@izonnet-web-solution/react-native-date-time-picker-kit 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -19
- package/lib/module/components/CalendarPicker.js +12 -7
- package/lib/module/components/CalendarPicker.js.map +1 -1
- package/lib/module/components/DatePicker.js +21 -14
- package/lib/module/components/DatePicker.js.map +1 -1
- package/lib/module/components/DateRangePicker.js +10 -6
- package/lib/module/components/DateRangePicker.js.map +1 -1
- package/lib/module/components/DateTimePicker.js +115 -39
- package/lib/module/components/DateTimePicker.js.map +1 -1
- package/lib/module/components/TimePicker.js +7 -5
- package/lib/module/components/TimePicker.js.map +1 -1
- package/lib/module/components/WheelPicker.js +62 -41
- package/lib/module/components/WheelPicker.js.map +1 -1
- package/lib/module/components/common/ModalWrapper.js +8 -2
- package/lib/module/components/common/ModalWrapper.js.map +1 -1
- package/lib/module/localization/useLocale.js +54 -4
- package/lib/module/localization/useLocale.js.map +1 -1
- package/lib/module/theme/useTheme.js +23 -1
- package/lib/module/theme/useTheme.js.map +1 -1
- package/lib/module/utils/dateConversion.js +109 -0
- package/lib/module/utils/dateConversion.js.map +1 -1
- package/lib/typescript/src/components/CalendarPicker.d.ts +16 -0
- package/lib/typescript/src/components/CalendarPicker.d.ts.map +1 -1
- package/lib/typescript/src/components/DatePicker.d.ts +13 -1
- package/lib/typescript/src/components/DatePicker.d.ts.map +1 -1
- package/lib/typescript/src/components/DateRangePicker.d.ts +16 -1
- package/lib/typescript/src/components/DateRangePicker.d.ts.map +1 -1
- package/lib/typescript/src/components/DateTimePicker.d.ts.map +1 -1
- package/lib/typescript/src/components/TimePicker.d.ts +7 -1
- package/lib/typescript/src/components/TimePicker.d.ts.map +1 -1
- package/lib/typescript/src/components/WheelPicker.d.ts.map +1 -1
- package/lib/typescript/src/components/common/ModalWrapper.d.ts +1 -0
- package/lib/typescript/src/components/common/ModalWrapper.d.ts.map +1 -1
- package/lib/typescript/src/localization/useLocale.d.ts +1 -1
- package/lib/typescript/src/localization/useLocale.d.ts.map +1 -1
- package/lib/typescript/src/theme/types.d.ts +11 -0
- package/lib/typescript/src/theme/types.d.ts.map +1 -1
- package/lib/typescript/src/theme/useTheme.d.ts.map +1 -1
- package/lib/typescript/src/types/presentation.d.ts +7 -0
- package/lib/typescript/src/types/presentation.d.ts.map +1 -1
- package/lib/typescript/src/types/props.d.ts +154 -1
- package/lib/typescript/src/types/props.d.ts.map +1 -1
- package/lib/typescript/src/utils/dateConversion.d.ts +19 -0
- package/lib/typescript/src/utils/dateConversion.d.ts.map +1 -1
- package/package.json +16 -8
- package/src/components/CalendarPicker.tsx +38 -8
- package/src/components/DatePicker.tsx +45 -15
- package/src/components/DateRangePicker.tsx +31 -6
- package/src/components/DateTimePicker.tsx +217 -51
- package/src/components/TimePicker.tsx +18 -5
- package/src/components/WheelPicker.tsx +86 -56
- package/src/components/common/ModalWrapper.tsx +9 -1
- package/src/localization/useLocale.ts +64 -4
- package/src/theme/types.ts +12 -0
- package/src/theme/useTheme.ts +24 -1
- package/src/types/presentation.ts +7 -0
- package/src/types/props.ts +198 -11
- package/src/utils/dateConversion.ts +146 -0
|
@@ -125,3 +125,149 @@ export function addDays(date: Date, days: number): Date {
|
|
|
125
125
|
export function cloneDate(date: Date): Date {
|
|
126
126
|
return new Date(date.getTime());
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Clamps a day of month to the valid range [1, daysInMonth] for a given year and month.
|
|
131
|
+
* Fixes edge cases when switching months (e.g. Jan 31 -> Feb 28 or 29 in leap years).
|
|
132
|
+
*/
|
|
133
|
+
export function clampMonthDay(
|
|
134
|
+
year: number,
|
|
135
|
+
month: number,
|
|
136
|
+
day: number
|
|
137
|
+
): number {
|
|
138
|
+
const maxDays = getDaysInMonth(year, month);
|
|
139
|
+
return Math.max(1, Math.min(day, maxDays));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Clamps a date strictly within an optional [minimumDate, maximumDate] range.
|
|
144
|
+
*/
|
|
145
|
+
export function clampDate(
|
|
146
|
+
date: unknown,
|
|
147
|
+
minDate?: unknown,
|
|
148
|
+
maxDate?: unknown
|
|
149
|
+
): Date | null {
|
|
150
|
+
const d = parseDate(date);
|
|
151
|
+
if (!d) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (minDate !== undefined && minDate !== null) {
|
|
155
|
+
const min = parseDate(minDate);
|
|
156
|
+
if (min && d.getTime() < min.getTime()) {
|
|
157
|
+
return new Date(min.getTime());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (maxDate !== undefined && maxDate !== null) {
|
|
161
|
+
const max = parseDate(maxDate);
|
|
162
|
+
if (max && d.getTime() > max.getTime()) {
|
|
163
|
+
return new Date(max.getTime());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return new Date(d.getTime());
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Dynamically clamps a date's time components (hour, minute) if date falls on the
|
|
171
|
+
* same calendar day as minimumDate or maximumDate.
|
|
172
|
+
*/
|
|
173
|
+
export function clampTime(
|
|
174
|
+
date: Date,
|
|
175
|
+
minDate?: unknown,
|
|
176
|
+
maxDate?: unknown
|
|
177
|
+
): Date {
|
|
178
|
+
const result = new Date(date.getTime());
|
|
179
|
+
const dateStr = serializeDateOnly(result);
|
|
180
|
+
|
|
181
|
+
if (minDate !== undefined && minDate !== null) {
|
|
182
|
+
const min = parseDate(minDate);
|
|
183
|
+
if (min && serializeDateOnly(min) === dateStr) {
|
|
184
|
+
if (result.getHours() < min.getHours()) {
|
|
185
|
+
result.setHours(min.getHours(), min.getMinutes(), min.getSeconds());
|
|
186
|
+
} else if (
|
|
187
|
+
result.getHours() === min.getHours() &&
|
|
188
|
+
result.getMinutes() < min.getMinutes()
|
|
189
|
+
) {
|
|
190
|
+
result.setMinutes(min.getMinutes(), min.getSeconds());
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (maxDate !== undefined && maxDate !== null) {
|
|
196
|
+
const max = parseDate(maxDate);
|
|
197
|
+
if (max && serializeDateOnly(max) === dateStr) {
|
|
198
|
+
if (result.getHours() > max.getHours()) {
|
|
199
|
+
result.setHours(max.getHours(), max.getMinutes(), max.getSeconds());
|
|
200
|
+
} else if (
|
|
201
|
+
result.getHours() === max.getHours() &&
|
|
202
|
+
result.getMinutes() > max.getMinutes()
|
|
203
|
+
) {
|
|
204
|
+
result.setMinutes(max.getMinutes(), max.getSeconds());
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Normalizes a date using a target IANA timezone (e.g. "America/New_York", "Asia/Kolkata")
|
|
214
|
+
* or a UTC offset in minutes, returning a Date object reflecting the local components in that zone.
|
|
215
|
+
*/
|
|
216
|
+
export function normalizeDateWithTimezone(
|
|
217
|
+
date: Date,
|
|
218
|
+
timeZone?: string,
|
|
219
|
+
utcOffsetMinutes?: number
|
|
220
|
+
): Date {
|
|
221
|
+
if (isNaN(date.getTime())) {
|
|
222
|
+
return date;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (timeZone && typeof Intl !== 'undefined' && Intl.DateTimeFormat) {
|
|
226
|
+
try {
|
|
227
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
228
|
+
timeZone,
|
|
229
|
+
year: 'numeric',
|
|
230
|
+
month: 'numeric',
|
|
231
|
+
day: 'numeric',
|
|
232
|
+
hour: 'numeric',
|
|
233
|
+
minute: 'numeric',
|
|
234
|
+
second: 'numeric',
|
|
235
|
+
hour12: false,
|
|
236
|
+
});
|
|
237
|
+
const parts = formatter.formatToParts(date);
|
|
238
|
+
let year = date.getFullYear();
|
|
239
|
+
let month = date.getMonth();
|
|
240
|
+
let day = date.getDate();
|
|
241
|
+
let hour = date.getHours();
|
|
242
|
+
let minute = date.getMinutes();
|
|
243
|
+
let second = date.getSeconds();
|
|
244
|
+
|
|
245
|
+
for (const part of parts) {
|
|
246
|
+
if (part.type === 'year') year = parseInt(part.value, 10);
|
|
247
|
+
else if (part.type === 'month') month = parseInt(part.value, 10) - 1;
|
|
248
|
+
else if (part.type === 'day') day = parseInt(part.value, 10);
|
|
249
|
+
else if (part.type === 'hour') {
|
|
250
|
+
const h = parseInt(part.value, 10);
|
|
251
|
+
hour = h === 24 ? 0 : h;
|
|
252
|
+
} else if (part.type === 'minute') minute = parseInt(part.value, 10);
|
|
253
|
+
else if (part.type === 'second') second = parseInt(part.value, 10);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return new Date(year, month, day, hour, minute, second);
|
|
257
|
+
} catch {
|
|
258
|
+
// Fallback
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (typeof utcOffsetMinutes === 'number') {
|
|
263
|
+
const offsetMin =
|
|
264
|
+
Math.abs(utcOffsetMinutes) <= 14 && !Number.isInteger(utcOffsetMinutes)
|
|
265
|
+
? utcOffsetMinutes * 60
|
|
266
|
+
: utcOffsetMinutes;
|
|
267
|
+
const currentOffsetMin = -date.getTimezoneOffset();
|
|
268
|
+
const diffMin = offsetMin - currentOffsetMin;
|
|
269
|
+
return new Date(date.getTime() + diffMin * 60 * 1000);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return new Date(date.getTime());
|
|
273
|
+
}
|