@izonnet-web-solution/react-native-date-time-picker-kit 0.0.0-stage → 1.0.0

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 +532 -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 +414 -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 +174 -0
  21. package/lib/module/components/DatePicker.js.map +1 -0
  22. package/lib/module/components/DateRangePicker.js +154 -0
  23. package/lib/module/components/DateRangePicker.js.map +1 -0
  24. package/lib/module/components/DateTimePicker.js +598 -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 +140 -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 +138 -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 +130 -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 +126 -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 +59 -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 +115 -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 +35 -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 +32 -0
  103. package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
  104. package/lib/typescript/src/components/DateRangePicker.d.ts +41 -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 +25 -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 +10 -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 +65 -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 +19 -0
  163. package/lib/typescript/src/types/presentation.d.ts.map +1 -0
  164. package/lib/typescript/src/types/props.d.ts +68 -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 +27 -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 +183 -4
  177. package/src/NativeDateTimePickerKit.ts +19 -0
  178. package/src/components/CalendarPicker.tsx +593 -0
  179. package/src/components/ClockPicker.tsx +403 -0
  180. package/src/components/DatePicker.tsx +246 -0
  181. package/src/components/DateRangePicker.tsx +226 -0
  182. package/src/components/DateTimePicker.tsx +862 -0
  183. package/src/components/MonthPicker.tsx +216 -0
  184. package/src/components/TimePicker.tsx +190 -0
  185. package/src/components/TimeSlotPicker.tsx +163 -0
  186. package/src/components/WheelPicker.tsx +199 -0
  187. package/src/components/YearPicker.tsx +228 -0
  188. package/src/components/common/ModalWrapper.tsx +184 -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 +137 -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 +70 -0
  206. package/src/theme/useTheme.ts +75 -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 +21 -0
  211. package/src/types/props.ts +104 -0
  212. package/src/utils/constants.ts +15 -0
  213. package/src/utils/dateConversion.ts +127 -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,104 @@
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 { ThemeConfig, ThemeMode } from '../theme/types';
16
+ import type { PartialLocaleData } from '../localization/types';
17
+ import type { BaseModalProps, PresentationMode } from './presentation';
18
+ import type { MarkedDatesMap } from '../components/CalendarPicker';
19
+ import type { DatePreset } from '../presets';
20
+
21
+ export type MinuteInterval = 1 | 2 | 3 | 4 | 5 | 6 | 10 | 12 | 15 | 20 | 30;
22
+
23
+ export interface TimeObject {
24
+ hour: number;
25
+ minute: number;
26
+ second?: number;
27
+ }
28
+
29
+ export interface DateTimePickerProps extends Omit<
30
+ BaseModalProps,
31
+ 'onConfirm' | 'onCancel'
32
+ > {
33
+ // Selection
34
+ mode?: NativePickerMode;
35
+ value?: Date | number | string | null;
36
+ defaultValue?: Date | number | string | null;
37
+ display?: NativePickerDisplay;
38
+ disabled?: boolean;
39
+ presentation?: PresentationMode; // 'native' | 'inline' | 'modal' | 'bottom-sheet' | 'fullscreen'
40
+
41
+ // Restrictions
42
+ minimumDate?: Date | number | string;
43
+ maximumDate?: Date | number | string;
44
+ minimumTime?: string | TimeObject;
45
+ maximumTime?: string | TimeObject;
46
+ minuteInterval?: MinuteInterval;
47
+ disabledDates?: (Date | string)[];
48
+ disabledWeekdays?: number[]; // 0 = Sunday, 1 = Monday, ..., 6 = Saturday
49
+ markedDates?: MarkedDatesMap;
50
+
51
+ // Localization
52
+ locale?: string | PartialLocaleData;
53
+ timeZoneName?: string;
54
+ timeZoneOffsetInMinutes?: number;
55
+ is24Hour?: boolean;
56
+ firstDayOfWeek?: number; // 0 = Sunday, 1 = Monday, ..., 6 = Saturday
57
+
58
+ // Appearance
59
+ theme?: NativePickerTheme | ThemeMode | ThemeConfig;
60
+ title?: string;
61
+ confirmText?: string;
62
+ cancelText?: string;
63
+ accentColor?: string;
64
+ textColor?: string;
65
+ backgroundColor?: string;
66
+ showPresets?: boolean;
67
+ customPresets?: DatePreset[];
68
+
69
+ // Callbacks
70
+ onChange?: DateTimePickerChangeEvent;
71
+ onConfirm?: DateTimePickerConfirmEvent;
72
+ onCancel?: DateTimePickerCancelEvent;
73
+ onDismiss?: DateTimePickerDismissEvent;
74
+ onOpen?: DateTimePickerOpenEvent;
75
+ onError?: DateTimePickerErrorEvent;
76
+
77
+ // Testing
78
+ testID?: string;
79
+
80
+ // Declarative open control (optional)
81
+ open?: boolean;
82
+ }
83
+
84
+ export interface DateTimePickerRef {
85
+ open: () => Promise<Date | null>;
86
+ close: () => Promise<boolean>;
87
+ confirm: () => Promise<Date | null>;
88
+ cancel: () => Promise<boolean>;
89
+ reset: () => void;
90
+ getValue: () => Date | null;
91
+ setValue: (date: Date | number | string) => void;
92
+ }
93
+
94
+ export interface OpenPickerOptions extends Omit<
95
+ DateTimePickerProps,
96
+ 'open' | 'testID'
97
+ > {
98
+ value?: Date | number | string;
99
+ }
100
+
101
+ export interface PickerResultEvent {
102
+ action: NativePickerAction;
103
+ date: Date | null;
104
+ }
@@ -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,127 @@
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
+ }
@@ -0,0 +1,166 @@
1
+ import { padZero } from './dateConversion';
2
+
3
+ const MONTH_NAMES_EN = [
4
+ 'January',
5
+ 'February',
6
+ 'March',
7
+ 'April',
8
+ 'May',
9
+ 'June',
10
+ 'July',
11
+ 'August',
12
+ 'September',
13
+ 'October',
14
+ 'November',
15
+ 'December',
16
+ ];
17
+
18
+ const MONTH_NAMES_SHORT_EN = [
19
+ 'Jan',
20
+ 'Feb',
21
+ 'Mar',
22
+ 'Apr',
23
+ 'May',
24
+ 'Jun',
25
+ 'Jul',
26
+ 'Aug',
27
+ 'Sep',
28
+ 'Oct',
29
+ 'Nov',
30
+ 'Dec',
31
+ ];
32
+
33
+ const DAY_NAMES_EN = [
34
+ 'Sunday',
35
+ 'Monday',
36
+ 'Tuesday',
37
+ 'Wednesday',
38
+ 'Thursday',
39
+ 'Friday',
40
+ 'Saturday',
41
+ ];
42
+
43
+ const DAY_NAMES_SHORT_EN = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
44
+
45
+ function getLocaleMonthName(
46
+ date: Date,
47
+ style: 'long' | 'short',
48
+ locale?: string
49
+ ): string {
50
+ try {
51
+ return new Intl.DateTimeFormat(locale || 'en-US', {
52
+ month: style,
53
+ }).format(date);
54
+ } catch {
55
+ const month = date.getMonth();
56
+ return style === 'long'
57
+ ? (MONTH_NAMES_EN[month] as string)
58
+ : (MONTH_NAMES_SHORT_EN[month] as string);
59
+ }
60
+ }
61
+
62
+ function getLocaleWeekdayName(
63
+ date: Date,
64
+ style: 'long' | 'short',
65
+ locale?: string
66
+ ): string {
67
+ try {
68
+ return new Intl.DateTimeFormat(locale || 'en-US', {
69
+ weekday: style,
70
+ }).format(date);
71
+ } catch {
72
+ const day = date.getDay();
73
+ return style === 'long'
74
+ ? (DAY_NAMES_EN[day] as string)
75
+ : (DAY_NAMES_SHORT_EN[day] as string);
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Formats a Date object according to a format string pattern.
81
+ * Tokens supported:
82
+ * YYYY, YY, MMMM, MMM, MM, M, DD, D, dddd, ddd, HH, H, hh, h, mm, m, ss, s, A, a
83
+ */
84
+ export function formatDate(
85
+ date: Date,
86
+ formatStr: string,
87
+ locale?: string
88
+ ): string {
89
+ if (!date || isNaN(date.getTime())) {
90
+ return '';
91
+ }
92
+
93
+ const year = date.getFullYear();
94
+ const month = date.getMonth();
95
+ const dayOfMonth = date.getDate();
96
+ const hours24 = date.getHours();
97
+ const hours12 = hours24 % 12 || 12;
98
+ const minutes = date.getMinutes();
99
+ const seconds = date.getSeconds();
100
+ const isPM = hours24 >= 12;
101
+
102
+ return formatStr.replace(
103
+ /(\[[^\]]*\]|YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|A|a)/g,
104
+ (match) => {
105
+ // Escaped text in brackets [text]
106
+ if (match.startsWith('[') && match.endsWith(']')) {
107
+ return match.slice(1, -1);
108
+ }
109
+
110
+ switch (match) {
111
+ case 'YYYY':
112
+ return year.toString();
113
+ case 'YY':
114
+ return year.toString().slice(-2);
115
+ case 'MMMM':
116
+ return getLocaleMonthName(date, 'long', locale);
117
+ case 'MMM':
118
+ return getLocaleMonthName(date, 'short', locale);
119
+ case 'MM':
120
+ return padZero(month + 1);
121
+ case 'M':
122
+ return (month + 1).toString();
123
+ case 'DD':
124
+ return padZero(dayOfMonth);
125
+ case 'D':
126
+ return dayOfMonth.toString();
127
+ case 'dddd':
128
+ return getLocaleWeekdayName(date, 'long', locale);
129
+ case 'ddd':
130
+ return getLocaleWeekdayName(date, 'short', locale);
131
+ case 'HH':
132
+ return padZero(hours24);
133
+ case 'H':
134
+ return hours24.toString();
135
+ case 'hh':
136
+ return padZero(hours12);
137
+ case 'h':
138
+ return hours12.toString();
139
+ case 'mm':
140
+ return padZero(minutes);
141
+ case 'm':
142
+ return minutes.toString();
143
+ case 'ss':
144
+ return padZero(seconds);
145
+ case 's':
146
+ return seconds.toString();
147
+ case 'A':
148
+ return isPM ? 'PM' : 'AM';
149
+ case 'a':
150
+ return isPM ? 'pm' : 'am';
151
+ default:
152
+ return match;
153
+ }
154
+ }
155
+ );
156
+ }
157
+
158
+ export function formatTime(
159
+ hour: number,
160
+ minute: number,
161
+ is24Hour = false
162
+ ): string {
163
+ const d = new Date();
164
+ d.setHours(hour, minute, 0, 0);
165
+ return formatDate(d, is24Hour ? 'HH:mm' : 'hh:mm A');
166
+ }
@@ -0,0 +1,178 @@
1
+ import { VALID_MINUTE_INTERVALS } from './constants';
2
+ import { parseDate, serializeDateOnly } from './dateConversion';
3
+
4
+ /**
5
+ * Validates that an input resolves to a valid, non-NaN Date.
6
+ */
7
+ export function validateDate(date: unknown): boolean {
8
+ const parsed = parseDate(date);
9
+ return parsed !== null;
10
+ }
11
+
12
+ /**
13
+ * Validates 24-hour time components.
14
+ */
15
+ export function validateTime(hour: number, minute: number): boolean {
16
+ if (typeof hour !== 'number' || typeof minute !== 'number') {
17
+ return false;
18
+ }
19
+ if (!Number.isInteger(hour) || !Number.isInteger(minute)) {
20
+ return false;
21
+ }
22
+ return hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59;
23
+ }
24
+
25
+ /**
26
+ * Validates that a date range is valid: both dates are valid and start <= end.
27
+ */
28
+ export function validateDateRange(
29
+ startDate: unknown,
30
+ endDate: unknown
31
+ ): boolean {
32
+ const start = parseDate(startDate);
33
+ const end = parseDate(endDate);
34
+ if (!start || !end) {
35
+ return false;
36
+ }
37
+ return start.getTime() <= end.getTime();
38
+ }
39
+
40
+ /**
41
+ * Checks if a date is strictly before another date.
42
+ */
43
+ export function isDateBefore(date: unknown, compareDate: unknown): boolean {
44
+ const d1 = parseDate(date);
45
+ const d2 = parseDate(compareDate);
46
+ if (!d1 || !d2) {
47
+ return false;
48
+ }
49
+ return d1.getTime() < d2.getTime();
50
+ }
51
+
52
+ /**
53
+ * Checks if a date is strictly after another date.
54
+ */
55
+ export function isDateAfter(date: unknown, compareDate: unknown): boolean {
56
+ const d1 = parseDate(date);
57
+ const d2 = parseDate(compareDate);
58
+ if (!d1 || !d2) {
59
+ return false;
60
+ }
61
+ return d1.getTime() > d2.getTime();
62
+ }
63
+
64
+ /**
65
+ * Checks if a date falls within an optional [minimumDate, maximumDate] range.
66
+ */
67
+ export function isDateWithinRange(
68
+ date: unknown,
69
+ minDate?: unknown,
70
+ maxDate?: unknown
71
+ ): boolean {
72
+ const d = parseDate(date);
73
+ if (!d) {
74
+ return false;
75
+ }
76
+
77
+ if (minDate !== undefined && minDate !== null) {
78
+ const min = parseDate(minDate);
79
+ if (!min || d.getTime() < min.getTime()) {
80
+ return false;
81
+ }
82
+ }
83
+
84
+ if (maxDate !== undefined && maxDate !== null) {
85
+ const max = parseDate(maxDate);
86
+ if (!max || d.getTime() > max.getTime()) {
87
+ return false;
88
+ }
89
+ }
90
+
91
+ return true;
92
+ }
93
+
94
+ /**
95
+ * Checks if the weekday of a date is disabled.
96
+ * 0 = Sunday, 1 = Monday, ..., 6 = Saturday
97
+ */
98
+ export function isWeekdayDisabled(
99
+ date: unknown,
100
+ disabledWeekdays?: number[]
101
+ ): boolean {
102
+ if (!disabledWeekdays || disabledWeekdays.length === 0) {
103
+ return false;
104
+ }
105
+ const d = parseDate(date);
106
+ if (!d) {
107
+ return false;
108
+ }
109
+ const day = d.getDay();
110
+ return disabledWeekdays.includes(day);
111
+ }
112
+
113
+ /**
114
+ * Checks if a date is disabled either specifically in disabledDates or by weekday.
115
+ */
116
+ export function isDateDisabled(
117
+ date: unknown,
118
+ disabledDates?: unknown[],
119
+ disabledWeekdays?: number[]
120
+ ): boolean {
121
+ const d = parseDate(date);
122
+ if (!d) {
123
+ return true;
124
+ }
125
+
126
+ if (isWeekdayDisabled(d, disabledWeekdays)) {
127
+ return true;
128
+ }
129
+
130
+ if (disabledDates && disabledDates.length > 0) {
131
+ const targetDateStr = serializeDateOnly(d);
132
+ for (const disabledItem of disabledDates) {
133
+ const parsedItem = parseDate(disabledItem);
134
+ if (parsedItem && serializeDateOnly(parsedItem) === targetDateStr) {
135
+ return true;
136
+ }
137
+ }
138
+ }
139
+
140
+ return false;
141
+ }
142
+
143
+ /**
144
+ * Validates that date is >= minDate.
145
+ */
146
+ export function validateMinimumDate(date: unknown, minDate: unknown): boolean {
147
+ const d = parseDate(date);
148
+ const min = parseDate(minDate);
149
+ if (!d || !min) {
150
+ return false;
151
+ }
152
+ return d.getTime() >= min.getTime();
153
+ }
154
+
155
+ /**
156
+ * Validates that date is <= maxDate.
157
+ */
158
+ export function validateMaximumDate(date: unknown, maxDate: unknown): boolean {
159
+ const d = parseDate(date);
160
+ const max = parseDate(maxDate);
161
+ if (!d || !max) {
162
+ return false;
163
+ }
164
+ return d.getTime() <= max.getTime();
165
+ }
166
+
167
+ /**
168
+ * Validates that the minute interval is a valid divisor of 60.
169
+ */
170
+ export function validateMinuteInterval(interval?: number): boolean {
171
+ if (interval === undefined || interval === null) {
172
+ return true;
173
+ }
174
+ if (!Number.isInteger(interval)) {
175
+ return false;
176
+ }
177
+ return (VALID_MINUTE_INTERVALS as readonly number[]).includes(interval);
178
+ }
@@ -0,0 +1,4 @@
1
+ export * from './constants';
2
+ export * from './dateConversion';
3
+ export * from './dateValidation';
4
+ export * from './dateFormatting';