@izonnet-web-solution/react-native-date-time-picker-kit 0.0.0-stage → 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.
Files changed (216) hide show
  1. package/DateTimePickerKit.podspec +22 -0
  2. package/LICENSE +20 -0
  3. package/README.md +652 -2
  4. package/android/build.gradle +36 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/datetimepickerkit/DatePickerHelper.kt +185 -0
  7. package/android/src/main/java/com/datetimepickerkit/DateTimePickerHelper.kt +214 -0
  8. package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitModule.kt +258 -0
  9. package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitPackage.kt +30 -0
  10. package/android/src/main/java/com/datetimepickerkit/TimePickerHelper.kt +208 -0
  11. package/ios/DateTimePickerKit.h +11 -0
  12. package/ios/DateTimePickerKit.mm +84 -0
  13. package/ios/DateTimePickerModule.swift +474 -0
  14. package/lib/module/NativeDateTimePickerKit.js +5 -0
  15. package/lib/module/NativeDateTimePickerKit.js.map +1 -0
  16. package/lib/module/components/CalendarPicker.js +419 -0
  17. package/lib/module/components/CalendarPicker.js.map +1 -0
  18. package/lib/module/components/ClockPicker.js +273 -0
  19. package/lib/module/components/ClockPicker.js.map +1 -0
  20. package/lib/module/components/DatePicker.js +181 -0
  21. package/lib/module/components/DatePicker.js.map +1 -0
  22. package/lib/module/components/DateRangePicker.js +158 -0
  23. package/lib/module/components/DateRangePicker.js.map +1 -0
  24. package/lib/module/components/DateTimePicker.js +674 -0
  25. package/lib/module/components/DateTimePicker.js.map +1 -0
  26. package/lib/module/components/MonthPicker.js +145 -0
  27. package/lib/module/components/MonthPicker.js.map +1 -0
  28. package/lib/module/components/TimePicker.js +142 -0
  29. package/lib/module/components/TimePicker.js.map +1 -0
  30. package/lib/module/components/TimeSlotPicker.js +118 -0
  31. package/lib/module/components/TimeSlotPicker.js.map +1 -0
  32. package/lib/module/components/WheelPicker.js +159 -0
  33. package/lib/module/components/WheelPicker.js.map +1 -0
  34. package/lib/module/components/YearPicker.js +151 -0
  35. package/lib/module/components/YearPicker.js.map +1 -0
  36. package/lib/module/components/common/ModalWrapper.js +136 -0
  37. package/lib/module/components/common/ModalWrapper.js.map +1 -0
  38. package/lib/module/components/common/PickerHeader.js +82 -0
  39. package/lib/module/components/common/PickerHeader.js.map +1 -0
  40. package/lib/module/components/common/PresetsBar.js +66 -0
  41. package/lib/module/components/common/PresetsBar.js.map +1 -0
  42. package/lib/module/errors/DateTimePickerError.js +12 -0
  43. package/lib/module/errors/DateTimePickerError.js.map +1 -0
  44. package/lib/module/hooks/useDateTimePicker.js +73 -0
  45. package/lib/module/hooks/useDateTimePicker.js.map +1 -0
  46. package/lib/module/index.js +40 -0
  47. package/lib/module/index.js.map +1 -0
  48. package/lib/module/localization/index.js +6 -0
  49. package/lib/module/localization/index.js.map +1 -0
  50. package/lib/module/localization/locales.js +186 -0
  51. package/lib/module/localization/locales.js.map +1 -0
  52. package/lib/module/localization/types.js +2 -0
  53. package/lib/module/localization/types.js.map +1 -0
  54. package/lib/module/localization/useLocale.js +176 -0
  55. package/lib/module/localization/useLocale.js.map +1 -0
  56. package/lib/module/native/NativeDateTimePicker.js +110 -0
  57. package/lib/module/native/NativeDateTimePicker.js.map +1 -0
  58. package/lib/module/package.json +1 -0
  59. package/lib/module/presets/datePresets.js +75 -0
  60. package/lib/module/presets/datePresets.js.map +1 -0
  61. package/lib/module/presets/index.js +4 -0
  62. package/lib/module/presets/index.js.map +1 -0
  63. package/lib/module/slots/index.js +4 -0
  64. package/lib/module/slots/index.js.map +1 -0
  65. package/lib/module/slots/timeSlots.js +59 -0
  66. package/lib/module/slots/timeSlots.js.map +1 -0
  67. package/lib/module/theme/defaultTheme.js +91 -0
  68. package/lib/module/theme/defaultTheme.js.map +1 -0
  69. package/lib/module/theme/index.js +6 -0
  70. package/lib/module/theme/index.js.map +1 -0
  71. package/lib/module/theme/types.js +2 -0
  72. package/lib/module/theme/types.js.map +1 -0
  73. package/lib/module/theme/useTheme.js +81 -0
  74. package/lib/module/theme/useTheme.js.map +1 -0
  75. package/lib/module/types/events.js +4 -0
  76. package/lib/module/types/events.js.map +1 -0
  77. package/lib/module/types/index.js +7 -0
  78. package/lib/module/types/index.js.map +1 -0
  79. package/lib/module/types/native.js +2 -0
  80. package/lib/module/types/native.js.map +1 -0
  81. package/lib/module/types/presentation.js +2 -0
  82. package/lib/module/types/presentation.js.map +1 -0
  83. package/lib/module/types/props.js +4 -0
  84. package/lib/module/types/props.js.map +1 -0
  85. package/lib/module/utils/constants.js +14 -0
  86. package/lib/module/utils/constants.js.map +1 -0
  87. package/lib/module/utils/dateConversion.js +224 -0
  88. package/lib/module/utils/dateConversion.js.map +1 -0
  89. package/lib/module/utils/dateFormatting.js +102 -0
  90. package/lib/module/utils/dateFormatting.js.map +1 -0
  91. package/lib/module/utils/dateValidation.js +161 -0
  92. package/lib/module/utils/dateValidation.js.map +1 -0
  93. package/lib/module/utils/index.js +7 -0
  94. package/lib/module/utils/index.js.map +1 -0
  95. package/lib/typescript/package.json +1 -0
  96. package/lib/typescript/src/NativeDateTimePickerKit.d.ts +17 -0
  97. package/lib/typescript/src/NativeDateTimePickerKit.d.ts.map +1 -0
  98. package/lib/typescript/src/components/CalendarPicker.d.ts +51 -0
  99. package/lib/typescript/src/components/CalendarPicker.d.ts.map +1 -0
  100. package/lib/typescript/src/components/ClockPicker.d.ts +22 -0
  101. package/lib/typescript/src/components/ClockPicker.d.ts.map +1 -0
  102. package/lib/typescript/src/components/DatePicker.d.ts +44 -0
  103. package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
  104. package/lib/typescript/src/components/DateRangePicker.d.ts +56 -0
  105. package/lib/typescript/src/components/DateRangePicker.d.ts.map +1 -0
  106. package/lib/typescript/src/components/DateTimePicker.d.ts +7 -0
  107. package/lib/typescript/src/components/DateTimePicker.d.ts.map +1 -0
  108. package/lib/typescript/src/components/MonthPicker.d.ts +21 -0
  109. package/lib/typescript/src/components/MonthPicker.d.ts.map +1 -0
  110. package/lib/typescript/src/components/TimePicker.d.ts +31 -0
  111. package/lib/typescript/src/components/TimePicker.d.ts.map +1 -0
  112. package/lib/typescript/src/components/TimeSlotPicker.d.ts +18 -0
  113. package/lib/typescript/src/components/TimeSlotPicker.d.ts.map +1 -0
  114. package/lib/typescript/src/components/WheelPicker.d.ts +17 -0
  115. package/lib/typescript/src/components/WheelPicker.d.ts.map +1 -0
  116. package/lib/typescript/src/components/YearPicker.d.ts +14 -0
  117. package/lib/typescript/src/components/YearPicker.d.ts.map +1 -0
  118. package/lib/typescript/src/components/common/ModalWrapper.d.ts +11 -0
  119. package/lib/typescript/src/components/common/ModalWrapper.d.ts.map +1 -0
  120. package/lib/typescript/src/components/common/PickerHeader.d.ts +13 -0
  121. package/lib/typescript/src/components/common/PickerHeader.d.ts.map +1 -0
  122. package/lib/typescript/src/components/common/PresetsBar.d.ts +12 -0
  123. package/lib/typescript/src/components/common/PresetsBar.d.ts.map +1 -0
  124. package/lib/typescript/src/errors/DateTimePickerError.d.ts +7 -0
  125. package/lib/typescript/src/errors/DateTimePickerError.d.ts.map +1 -0
  126. package/lib/typescript/src/hooks/useDateTimePicker.d.ts +17 -0
  127. package/lib/typescript/src/hooks/useDateTimePicker.d.ts.map +1 -0
  128. package/lib/typescript/src/index.d.ts +23 -0
  129. package/lib/typescript/src/index.d.ts.map +1 -0
  130. package/lib/typescript/src/localization/index.d.ts +4 -0
  131. package/lib/typescript/src/localization/index.d.ts.map +1 -0
  132. package/lib/typescript/src/localization/locales.d.ts +12 -0
  133. package/lib/typescript/src/localization/locales.d.ts.map +1 -0
  134. package/lib/typescript/src/localization/types.d.ts +23 -0
  135. package/lib/typescript/src/localization/types.d.ts.map +1 -0
  136. package/lib/typescript/src/localization/useLocale.d.ts +31 -0
  137. package/lib/typescript/src/localization/useLocale.d.ts.map +1 -0
  138. package/lib/typescript/src/native/NativeDateTimePicker.d.ts +14 -0
  139. package/lib/typescript/src/native/NativeDateTimePicker.d.ts.map +1 -0
  140. package/lib/typescript/src/presets/datePresets.d.ts +8 -0
  141. package/lib/typescript/src/presets/datePresets.d.ts.map +1 -0
  142. package/lib/typescript/src/presets/index.d.ts +2 -0
  143. package/lib/typescript/src/presets/index.d.ts.map +1 -0
  144. package/lib/typescript/src/slots/index.d.ts +2 -0
  145. package/lib/typescript/src/slots/index.d.ts.map +1 -0
  146. package/lib/typescript/src/slots/timeSlots.d.ts +18 -0
  147. package/lib/typescript/src/slots/timeSlots.d.ts.map +1 -0
  148. package/lib/typescript/src/theme/defaultTheme.d.ts +9 -0
  149. package/lib/typescript/src/theme/defaultTheme.d.ts.map +1 -0
  150. package/lib/typescript/src/theme/index.d.ts +4 -0
  151. package/lib/typescript/src/theme/index.d.ts.map +1 -0
  152. package/lib/typescript/src/theme/types.d.ts +76 -0
  153. package/lib/typescript/src/theme/types.d.ts.map +1 -0
  154. package/lib/typescript/src/theme/useTheme.d.ts +4 -0
  155. package/lib/typescript/src/theme/useTheme.d.ts.map +1 -0
  156. package/lib/typescript/src/types/events.d.ts +8 -0
  157. package/lib/typescript/src/types/events.d.ts.map +1 -0
  158. package/lib/typescript/src/types/index.d.ts +5 -0
  159. package/lib/typescript/src/types/index.d.ts.map +1 -0
  160. package/lib/typescript/src/types/native.d.ts +26 -0
  161. package/lib/typescript/src/types/native.d.ts.map +1 -0
  162. package/lib/typescript/src/types/presentation.d.ts +26 -0
  163. package/lib/typescript/src/types/presentation.d.ts.map +1 -0
  164. package/lib/typescript/src/types/props.d.ts +221 -0
  165. package/lib/typescript/src/types/props.d.ts.map +1 -0
  166. package/lib/typescript/src/utils/constants.d.ts +12 -0
  167. package/lib/typescript/src/utils/constants.d.ts.map +1 -0
  168. package/lib/typescript/src/utils/dateConversion.d.ts +46 -0
  169. package/lib/typescript/src/utils/dateConversion.d.ts.map +1 -0
  170. package/lib/typescript/src/utils/dateFormatting.d.ts +8 -0
  171. package/lib/typescript/src/utils/dateFormatting.d.ts.map +1 -0
  172. package/lib/typescript/src/utils/dateValidation.d.ts +46 -0
  173. package/lib/typescript/src/utils/dateValidation.d.ts.map +1 -0
  174. package/lib/typescript/src/utils/index.d.ts +5 -0
  175. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  176. package/package.json +191 -4
  177. package/src/NativeDateTimePickerKit.ts +19 -0
  178. package/src/components/CalendarPicker.tsx +623 -0
  179. package/src/components/ClockPicker.tsx +403 -0
  180. package/src/components/DatePicker.tsx +276 -0
  181. package/src/components/DateRangePicker.tsx +251 -0
  182. package/src/components/DateTimePicker.tsx +1028 -0
  183. package/src/components/MonthPicker.tsx +216 -0
  184. package/src/components/TimePicker.tsx +203 -0
  185. package/src/components/TimeSlotPicker.tsx +163 -0
  186. package/src/components/WheelPicker.tsx +229 -0
  187. package/src/components/YearPicker.tsx +228 -0
  188. package/src/components/common/ModalWrapper.tsx +192 -0
  189. package/src/components/common/PickerHeader.tsx +121 -0
  190. package/src/components/common/PresetsBar.tsx +104 -0
  191. package/src/errors/DateTimePickerError.ts +29 -0
  192. package/src/hooks/useDateTimePicker.ts +100 -0
  193. package/src/index.tsx +92 -0
  194. package/src/localization/index.ts +3 -0
  195. package/src/localization/locales.ts +499 -0
  196. package/src/localization/types.ts +21 -0
  197. package/src/localization/useLocale.ts +197 -0
  198. package/src/native/NativeDateTimePicker.ts +154 -0
  199. package/src/presets/datePresets.ts +97 -0
  200. package/src/presets/index.ts +1 -0
  201. package/src/slots/index.ts +1 -0
  202. package/src/slots/timeSlots.ts +89 -0
  203. package/src/theme/defaultTheme.ts +102 -0
  204. package/src/theme/index.ts +3 -0
  205. package/src/theme/types.ts +82 -0
  206. package/src/theme/useTheme.ts +98 -0
  207. package/src/types/events.ts +8 -0
  208. package/src/types/index.ts +4 -0
  209. package/src/types/native.ts +28 -0
  210. package/src/types/presentation.ts +28 -0
  211. package/src/types/props.ts +291 -0
  212. package/src/utils/constants.ts +15 -0
  213. package/src/utils/dateConversion.ts +273 -0
  214. package/src/utils/dateFormatting.ts +166 -0
  215. package/src/utils/dateValidation.ts +178 -0
  216. package/src/utils/index.ts +4 -0
@@ -0,0 +1,291 @@
1
+ import type {
2
+ NativePickerAction,
3
+ NativePickerDisplay,
4
+ NativePickerMode,
5
+ NativePickerTheme,
6
+ } from './native';
7
+ import type {
8
+ DateTimePickerCancelEvent,
9
+ DateTimePickerChangeEvent,
10
+ DateTimePickerConfirmEvent,
11
+ DateTimePickerDismissEvent,
12
+ DateTimePickerErrorEvent,
13
+ DateTimePickerOpenEvent,
14
+ } from './events';
15
+ import type {
16
+ ThemeColorsOverride,
17
+ ThemeConfig,
18
+ ThemeMode,
19
+ } from '../theme/types';
20
+ import type { PartialLocaleData } from '../localization/types';
21
+ import type { BaseModalProps, PresentationMode } from './presentation';
22
+ import type { MarkedDatesMap } from '../components/CalendarPicker';
23
+ import type { DatePreset } from '../presets';
24
+
25
+ export type MinuteInterval = 1 | 2 | 3 | 4 | 5 | 6 | 10 | 12 | 15 | 20 | 30;
26
+
27
+ export type PickerMode = NativePickerMode;
28
+ export type PickerTheme = NativePickerTheme | ThemeMode;
29
+ export type PickerDisplay = NativePickerDisplay;
30
+ export type PickerPresentation = PresentationMode;
31
+
32
+ export interface TimeObject {
33
+ hour: number;
34
+ minute: number;
35
+ second?: number;
36
+ }
37
+
38
+ export interface DateTimePickerProps extends Omit<
39
+ BaseModalProps,
40
+ 'onConfirm' | 'onCancel'
41
+ > {
42
+ /**
43
+ * Selection mode for picker: 'date', 'time', 'datetime', or 'countdown'.
44
+ * @default 'date'
45
+ */
46
+ mode?: NativePickerMode;
47
+
48
+ /**
49
+ * Controlled Date value. Accepts Date object, numeric epoch timestamp, or ISO string.
50
+ */
51
+ value?: Date | number | string | null;
52
+
53
+ /**
54
+ * Uncontrolled initial Date value.
55
+ */
56
+ defaultValue?: Date | number | string | null;
57
+
58
+ /**
59
+ * Native display presentation style on iOS/Android (e.g. 'compact', 'inline', 'spinner', 'clock').
60
+ * @default 'default'
61
+ */
62
+ display?: NativePickerDisplay;
63
+
64
+ /**
65
+ * Whether the picker interactions are disabled.
66
+ * @default false
67
+ */
68
+ disabled?: boolean;
69
+
70
+ /**
71
+ * Presentation mode: 'native' (OS dialog), 'inline', 'modal', 'bottom-sheet', or 'fullscreen'.
72
+ * @default 'native'
73
+ */
74
+ presentation?: PresentationMode;
75
+
76
+ /**
77
+ * Minimum selectable date/time boundary. Selection before this timestamp is prevented/clamped.
78
+ */
79
+ minimumDate?: Date | number | string;
80
+
81
+ /**
82
+ * Alias for `minimumDate`.
83
+ */
84
+ minDate?: Date | number | string;
85
+
86
+ /**
87
+ * Maximum selectable date/time boundary. Selection after this timestamp is prevented/clamped.
88
+ */
89
+ maximumDate?: Date | number | string;
90
+
91
+ /**
92
+ * Alias for `maximumDate`.
93
+ */
94
+ maxDate?: Date | number | string;
95
+
96
+ /**
97
+ * Minimum allowable time components (e.g. "09:00" or { hour: 9, minute: 0 }).
98
+ */
99
+ minimumTime?: string | TimeObject;
100
+
101
+ /**
102
+ * Maximum allowable time components (e.g. "17:00" or { hour: 17, minute: 0 }).
103
+ */
104
+ maximumTime?: string | TimeObject;
105
+
106
+ /**
107
+ * Minute snapping interval (1, 2, 3, 4, 5, 6, 10, 12, 15, 20, or 30).
108
+ * @default 1
109
+ */
110
+ minuteInterval?: MinuteInterval;
111
+
112
+ /**
113
+ * Specific dates to disable from selection.
114
+ */
115
+ disabledDates?: (Date | string)[];
116
+
117
+ /**
118
+ * Weekdays to disable from selection (0 = Sunday, 1 = Monday, ..., 6 = Saturday).
119
+ */
120
+ disabledWeekdays?: number[];
121
+
122
+ /**
123
+ * Map of marked dates with colored dots, badges, or custom highlights.
124
+ */
125
+ markedDates?: MarkedDatesMap;
126
+
127
+ /**
128
+ * Locale string identifier (e.g. 'en', 'hi', 'gu', 'ar', 'es') or custom LocaleData object.
129
+ * @default Device locale
130
+ */
131
+ locale?: string | PartialLocaleData;
132
+
133
+ /**
134
+ * Target IANA timezone identifier (e.g. 'America/New_York', 'Asia/Kolkata').
135
+ */
136
+ timeZone?: string;
137
+
138
+ /**
139
+ * Alias for `timeZone`.
140
+ */
141
+ timeZoneName?: string;
142
+
143
+ /**
144
+ * Explicit UTC offset in minutes (e.g. 330 for IST +05:30).
145
+ */
146
+ timeZoneOffsetInMinutes?: number;
147
+
148
+ /**
149
+ * UTC offset in hours or minutes (e.g. 5.5 or 330).
150
+ */
151
+ utcOffset?: number;
152
+
153
+ /**
154
+ * Explicit override for 24-hour time representation.
155
+ */
156
+ is24Hour?: boolean;
157
+
158
+ /**
159
+ * First day of the week (0 = Sunday, 1 = Monday, 6 = Saturday).
160
+ */
161
+ firstDayOfWeek?: number;
162
+
163
+ /**
164
+ * Visual theme mode ('light', 'dark', 'auto') or comprehensive ThemeConfig object.
165
+ * @default 'auto'
166
+ */
167
+ theme?: NativePickerTheme | ThemeMode | ThemeConfig;
168
+
169
+ /**
170
+ * Convenient color override palette for quick styling without breaking layouts.
171
+ */
172
+ themeColors?: ThemeColorsOverride;
173
+
174
+ /**
175
+ * Optional custom style overrides for modal header, button, or container.
176
+ */
177
+ styles?: {
178
+ headerStyle?: any;
179
+ confirmButtonStyle?: any;
180
+ cancelButtonStyle?: any;
181
+ containerStyle?: any;
182
+ };
183
+
184
+ /**
185
+ * Title text displayed in header or native dialog.
186
+ */
187
+ title?: string;
188
+
189
+ /**
190
+ * Confirm button action label.
191
+ */
192
+ confirmText?: string;
193
+
194
+ /**
195
+ * Cancel button action label.
196
+ */
197
+ cancelText?: string;
198
+
199
+ /**
200
+ * Accent color override.
201
+ */
202
+ accentColor?: string;
203
+
204
+ /**
205
+ * Text color override.
206
+ */
207
+ textColor?: string;
208
+
209
+ /**
210
+ * Background color override.
211
+ */
212
+ backgroundColor?: string;
213
+
214
+ /**
215
+ * Whether to show quick date presets bar (Today, Yesterday, Last 7 Days, This Month).
216
+ * @default false
217
+ */
218
+ showPresets?: boolean;
219
+
220
+ /**
221
+ * Custom date presets to display.
222
+ */
223
+ customPresets?: DatePreset[];
224
+
225
+ /**
226
+ * Callback fired on any intermediate date or time selection change.
227
+ */
228
+ onChange?: DateTimePickerChangeEvent;
229
+
230
+ /**
231
+ * Callback fired when selection is confirmed with the final Date object.
232
+ */
233
+ onConfirm?: DateTimePickerConfirmEvent;
234
+
235
+ /**
236
+ * Callback fired when picker is cancelled or closed without confirmation.
237
+ */
238
+ onCancel?: DateTimePickerCancelEvent;
239
+
240
+ /**
241
+ * Callback fired on native dialog dismissal.
242
+ */
243
+ onDismiss?: DateTimePickerDismissEvent;
244
+
245
+ /**
246
+ * Callback fired when picker modal opens.
247
+ */
248
+ onOpen?: DateTimePickerOpenEvent;
249
+
250
+ /**
251
+ * Callback fired when an error occurs during presentation or validation.
252
+ */
253
+ onError?: DateTimePickerErrorEvent;
254
+
255
+ /**
256
+ * Test identifier for automation testing.
257
+ */
258
+ testID?: string;
259
+
260
+ /**
261
+ * Declarative open control flag.
262
+ */
263
+ open?: boolean;
264
+
265
+ /**
266
+ * Alias for `open` or `visible`.
267
+ */
268
+ isVisible?: boolean;
269
+ }
270
+
271
+ export interface DateTimePickerRef {
272
+ open: () => Promise<Date | null>;
273
+ close: () => Promise<boolean>;
274
+ confirm: () => Promise<Date | null>;
275
+ cancel: () => Promise<boolean>;
276
+ reset: () => void;
277
+ getValue: () => Date | null;
278
+ setValue: (date: Date | number | string) => void;
279
+ }
280
+
281
+ export interface OpenPickerOptions extends Omit<
282
+ DateTimePickerProps,
283
+ 'open' | 'testID'
284
+ > {
285
+ value?: Date | number | string;
286
+ }
287
+
288
+ export interface PickerResultEvent {
289
+ action: NativePickerAction;
290
+ date: Date | null;
291
+ }
@@ -0,0 +1,15 @@
1
+ export const VALID_MINUTE_INTERVALS = [
2
+ 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30,
3
+ ] as const;
4
+
5
+ export const DEFAULT_CONFIRM_TEXT = 'Confirm';
6
+ export const DEFAULT_CANCEL_TEXT = 'Cancel';
7
+ export const DEFAULT_TITLE = '';
8
+ export const DEFAULT_MODE = 'date';
9
+ export const DEFAULT_DISPLAY = 'default';
10
+ export const DEFAULT_THEME = 'auto';
11
+
12
+ export const MILLISECONDS_IN_SECOND = 1000;
13
+ export const MILLISECONDS_IN_MINUTE = 60 * MILLISECONDS_IN_SECOND;
14
+ export const MILLISECONDS_IN_HOUR = 60 * MILLISECONDS_IN_MINUTE;
15
+ export const MILLISECONDS_IN_DAY = 24 * MILLISECONDS_IN_HOUR;
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Pure TypeScript Date Conversion Utilities
3
+ * Zero external dependencies.
4
+ */
5
+
6
+ export function parseDate(input: unknown): Date | null {
7
+ if (input === null || input === undefined) {
8
+ return null;
9
+ }
10
+
11
+ if (input instanceof Date) {
12
+ return isNaN(input.getTime()) ? null : new Date(input.getTime());
13
+ }
14
+
15
+ if (typeof input === 'number') {
16
+ if (isNaN(input) || !isFinite(input)) {
17
+ return null;
18
+ }
19
+ const d = new Date(input);
20
+ return isNaN(d.getTime()) ? null : d;
21
+ }
22
+
23
+ if (typeof input === 'string') {
24
+ const trimmed = input.trim();
25
+ if (!trimmed) {
26
+ return null;
27
+ }
28
+
29
+ // Try standard Date.parse
30
+ const timestamp = Date.parse(trimmed);
31
+ if (!isNaN(timestamp)) {
32
+ // Check for YYYY-MM-DD date-only strings: Date.parse treats them as UTC
33
+ // If matches YYYY-MM-DD format strictly, parse as local date components to avoid timezone shifting
34
+ const dateOnlyMatch = /^(\d{4})-(\d{2})-(\d{2})$/.exec(trimmed);
35
+ if (dateOnlyMatch) {
36
+ const year = parseInt(dateOnlyMatch[1] as string, 10);
37
+ const month = parseInt(dateOnlyMatch[2] as string, 10) - 1;
38
+ const day = parseInt(dateOnlyMatch[3] as string, 10);
39
+ const localDate = new Date(year, month, day);
40
+ return isNaN(localDate.getTime()) ? null : localDate;
41
+ }
42
+ return new Date(timestamp);
43
+ }
44
+ }
45
+
46
+ return null;
47
+ }
48
+
49
+ export function dateToTimestamp(input: unknown): number | null {
50
+ const parsed = parseDate(input);
51
+ return parsed ? parsed.getTime() : null;
52
+ }
53
+
54
+ export function timestampToDate(timestamp: number): Date {
55
+ return new Date(timestamp);
56
+ }
57
+
58
+ export function isLeapYear(year: number): boolean {
59
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
60
+ }
61
+
62
+ export function getDaysInMonth(year: number, month: number): number {
63
+ return new Date(year, month + 1, 0).getDate();
64
+ }
65
+
66
+ export function padZero(num: number, size = 2): string {
67
+ let s = num.toString();
68
+ while (s.length < size) {
69
+ s = '0' + s;
70
+ }
71
+ return s;
72
+ }
73
+
74
+ /**
75
+ * Serializes local date as YYYY-MM-DD
76
+ */
77
+ export function serializeDateOnly(date: Date): string {
78
+ const year = date.getFullYear();
79
+ const month = padZero(date.getMonth() + 1);
80
+ const day = padZero(date.getDate());
81
+ return `${year}-${month}-${day}`;
82
+ }
83
+
84
+ /**
85
+ * Serializes local time as HH:mm or hh:mm a
86
+ */
87
+ export function serializeTimeOnly(date: Date, is24Hour = true): string {
88
+ const hours = date.getHours();
89
+ const minutes = padZero(date.getMinutes());
90
+
91
+ if (is24Hour) {
92
+ return `${padZero(hours)}:${minutes}`;
93
+ }
94
+
95
+ const period = hours >= 12 ? 'PM' : 'AM';
96
+ const displayHours = hours % 12 || 12;
97
+ return `${padZero(displayHours)}:${minutes} ${period}`;
98
+ }
99
+
100
+ /**
101
+ * Serializes date & time to local ISO string: YYYY-MM-DDTHH:mm:ss
102
+ */
103
+ export function serializeDateTime(date: Date): string {
104
+ return `${serializeDateOnly(date)}T${serializeTimeOnly(date, true)}:${padZero(date.getSeconds())}`;
105
+ }
106
+
107
+ export function startOfDay(date: Date): Date {
108
+ const d = new Date(date.getTime());
109
+ d.setHours(0, 0, 0, 0);
110
+ return d;
111
+ }
112
+
113
+ export function endOfDay(date: Date): Date {
114
+ const d = new Date(date.getTime());
115
+ d.setHours(23, 59, 59, 999);
116
+ return d;
117
+ }
118
+
119
+ export function addDays(date: Date, days: number): Date {
120
+ const d = new Date(date.getTime());
121
+ d.setDate(d.getDate() + days);
122
+ return d;
123
+ }
124
+
125
+ export function cloneDate(date: Date): Date {
126
+ return new Date(date.getTime());
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
+ }