@izonnet-web-solution/react-native-date-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 (271) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +5 -0
  3. package/README.md +942 -2
  4. package/assets/screenshots/calendar-picker-blue.jpg +0 -0
  5. package/assets/screenshots/calendar-picker.jpg +0 -0
  6. package/assets/screenshots/datetime-picker-date.jpg +0 -0
  7. package/assets/screenshots/datetime-picker-time-blue.jpg +0 -0
  8. package/assets/screenshots/input-modal-picker.jpg +0 -0
  9. package/assets/screenshots/manual-entry-single.jpg +0 -0
  10. package/assets/screenshots/manual-entry-split.jpg +0 -0
  11. package/assets/screenshots/month-year-selector-modal.jpg +0 -0
  12. package/assets/screenshots/range-picker.jpg +0 -0
  13. package/assets/screenshots/time-12h-wheel.jpg +0 -0
  14. package/assets/screenshots/time-24h-military-blue.jpg +0 -0
  15. package/assets/screenshots/wheel-date-picker.jpg +0 -0
  16. package/lib/components/Calendar/Calendar.d.ts +35 -0
  17. package/lib/components/Calendar/Calendar.d.ts.map +1 -0
  18. package/lib/components/Calendar/Calendar.js +126 -0
  19. package/lib/components/Calendar/Calendar.js.map +1 -0
  20. package/lib/components/Calendar/CalendarGrid.d.ts +11 -0
  21. package/lib/components/Calendar/CalendarGrid.d.ts.map +1 -0
  22. package/lib/components/Calendar/CalendarGrid.js +22 -0
  23. package/lib/components/Calendar/CalendarGrid.js.map +1 -0
  24. package/lib/components/Calendar/CalendarHeader.d.ts +23 -0
  25. package/lib/components/Calendar/CalendarHeader.d.ts.map +1 -0
  26. package/lib/components/Calendar/CalendarHeader.js +62 -0
  27. package/lib/components/Calendar/CalendarHeader.js.map +1 -0
  28. package/lib/components/Calendar/DateCell.d.ts +11 -0
  29. package/lib/components/Calendar/DateCell.d.ts.map +1 -0
  30. package/lib/components/Calendar/DateCell.js +71 -0
  31. package/lib/components/Calendar/DateCell.js.map +1 -0
  32. package/lib/components/Calendar/MonthYearSelectorModal.d.ts +17 -0
  33. package/lib/components/Calendar/MonthYearSelectorModal.d.ts.map +1 -0
  34. package/lib/components/Calendar/MonthYearSelectorModal.js +253 -0
  35. package/lib/components/Calendar/MonthYearSelectorModal.js.map +1 -0
  36. package/lib/components/Calendar/WeekDays.d.ts +13 -0
  37. package/lib/components/Calendar/WeekDays.d.ts.map +1 -0
  38. package/lib/components/Calendar/WeekDays.js +34 -0
  39. package/lib/components/Calendar/WeekDays.js.map +1 -0
  40. package/lib/components/Calendar/index.d.ts +7 -0
  41. package/lib/components/Calendar/index.d.ts.map +1 -0
  42. package/lib/components/Calendar/index.js +23 -0
  43. package/lib/components/Calendar/index.js.map +1 -0
  44. package/lib/components/DatePicker.d.ts +4 -0
  45. package/lib/components/DatePicker.d.ts.map +1 -0
  46. package/lib/components/DatePicker.js +498 -0
  47. package/lib/components/DatePicker.js.map +1 -0
  48. package/lib/components/Input/CalendarPopup.d.ts +26 -0
  49. package/lib/components/Input/CalendarPopup.d.ts.map +1 -0
  50. package/lib/components/Input/CalendarPopup.js +60 -0
  51. package/lib/components/Input/CalendarPopup.js.map +1 -0
  52. package/lib/components/Input/DateInput.d.ts +29 -0
  53. package/lib/components/Input/DateInput.d.ts.map +1 -0
  54. package/lib/components/Input/DateInput.js +110 -0
  55. package/lib/components/Input/DateInput.js.map +1 -0
  56. package/lib/components/Input/index.d.ts +3 -0
  57. package/lib/components/Input/index.d.ts.map +1 -0
  58. package/lib/components/Input/index.js +19 -0
  59. package/lib/components/Input/index.js.map +1 -0
  60. package/lib/components/ManualDateInput/DateInputField.d.ts +19 -0
  61. package/lib/components/ManualDateInput/DateInputField.d.ts.map +1 -0
  62. package/lib/components/ManualDateInput/DateInputField.js +345 -0
  63. package/lib/components/ManualDateInput/DateInputField.js.map +1 -0
  64. package/lib/components/ManualDateInput/DateValidationMessage.d.ts +8 -0
  65. package/lib/components/ManualDateInput/DateValidationMessage.d.ts.map +1 -0
  66. package/lib/components/ManualDateInput/DateValidationMessage.js +45 -0
  67. package/lib/components/ManualDateInput/DateValidationMessage.js.map +1 -0
  68. package/lib/components/ManualDateInput/ManualDateInput.d.ts +19 -0
  69. package/lib/components/ManualDateInput/ManualDateInput.d.ts.map +1 -0
  70. package/lib/components/ManualDateInput/ManualDateInput.js +18 -0
  71. package/lib/components/ManualDateInput/ManualDateInput.js.map +1 -0
  72. package/lib/components/ManualDateInput/index.d.ts +4 -0
  73. package/lib/components/ManualDateInput/index.d.ts.map +1 -0
  74. package/lib/components/ManualDateInput/index.js +20 -0
  75. package/lib/components/ManualDateInput/index.js.map +1 -0
  76. package/lib/components/Range/RangeDateCell.d.ts +11 -0
  77. package/lib/components/Range/RangeDateCell.d.ts.map +1 -0
  78. package/lib/components/Range/RangeDateCell.js +107 -0
  79. package/lib/components/Range/RangeDateCell.js.map +1 -0
  80. package/lib/components/Range/RangePicker.d.ts +29 -0
  81. package/lib/components/Range/RangePicker.d.ts.map +1 -0
  82. package/lib/components/Range/RangePicker.js +261 -0
  83. package/lib/components/Range/RangePicker.js.map +1 -0
  84. package/lib/components/Range/index.d.ts +3 -0
  85. package/lib/components/Range/index.d.ts.map +1 -0
  86. package/lib/components/Range/index.js +19 -0
  87. package/lib/components/Range/index.js.map +1 -0
  88. package/lib/components/Time/ClockDial.d.ts +15 -0
  89. package/lib/components/Time/ClockDial.d.ts.map +1 -0
  90. package/lib/components/Time/ClockDial.js +347 -0
  91. package/lib/components/Time/ClockDial.js.map +1 -0
  92. package/lib/components/Time/DateTimePicker.d.ts +31 -0
  93. package/lib/components/Time/DateTimePicker.d.ts.map +1 -0
  94. package/lib/components/Time/DateTimePicker.js +197 -0
  95. package/lib/components/Time/DateTimePicker.js.map +1 -0
  96. package/lib/components/Time/TimePicker.d.ts +31 -0
  97. package/lib/components/Time/TimePicker.d.ts.map +1 -0
  98. package/lib/components/Time/TimePicker.js +550 -0
  99. package/lib/components/Time/TimePicker.js.map +1 -0
  100. package/lib/components/Time/WheelTimePicker.d.ts +27 -0
  101. package/lib/components/Time/WheelTimePicker.d.ts.map +1 -0
  102. package/lib/components/Time/WheelTimePicker.js +203 -0
  103. package/lib/components/Time/WheelTimePicker.js.map +1 -0
  104. package/lib/components/Time/index.d.ts +5 -0
  105. package/lib/components/Time/index.d.ts.map +1 -0
  106. package/lib/components/Time/index.js +21 -0
  107. package/lib/components/Time/index.js.map +1 -0
  108. package/lib/components/Wheel/WheelColumn.d.ts +17 -0
  109. package/lib/components/Wheel/WheelColumn.d.ts.map +1 -0
  110. package/lib/components/Wheel/WheelColumn.js +192 -0
  111. package/lib/components/Wheel/WheelColumn.js.map +1 -0
  112. package/lib/components/Wheel/WheelPicker.d.ts +26 -0
  113. package/lib/components/Wheel/WheelPicker.d.ts.map +1 -0
  114. package/lib/components/Wheel/WheelPicker.js +123 -0
  115. package/lib/components/Wheel/WheelPicker.js.map +1 -0
  116. package/lib/components/Wheel/index.d.ts +3 -0
  117. package/lib/components/Wheel/index.d.ts.map +1 -0
  118. package/lib/components/Wheel/index.js +19 -0
  119. package/lib/components/Wheel/index.js.map +1 -0
  120. package/lib/components/common/Button.d.ts +17 -0
  121. package/lib/components/common/Button.d.ts.map +1 -0
  122. package/lib/components/common/Button.js +77 -0
  123. package/lib/components/common/Button.js.map +1 -0
  124. package/lib/components/common/IconButton.d.ts +14 -0
  125. package/lib/components/common/IconButton.d.ts.map +1 -0
  126. package/lib/components/common/IconButton.js +150 -0
  127. package/lib/components/common/IconButton.js.map +1 -0
  128. package/lib/components/common/Modal.d.ts +13 -0
  129. package/lib/components/common/Modal.d.ts.map +1 -0
  130. package/lib/components/common/Modal.js +65 -0
  131. package/lib/components/common/Modal.js.map +1 -0
  132. package/lib/components/common/index.d.ts +4 -0
  133. package/lib/components/common/index.d.ts.map +1 -0
  134. package/lib/components/common/index.js +20 -0
  135. package/lib/components/common/index.js.map +1 -0
  136. package/lib/components/index.d.ts +9 -0
  137. package/lib/components/index.d.ts.map +1 -0
  138. package/lib/components/index.js +25 -0
  139. package/lib/components/index.js.map +1 -0
  140. package/lib/hooks/index.d.ts +4 -0
  141. package/lib/hooks/index.d.ts.map +1 -0
  142. package/lib/hooks/index.js +20 -0
  143. package/lib/hooks/index.js.map +1 -0
  144. package/lib/hooks/useCalendar.d.ts +34 -0
  145. package/lib/hooks/useCalendar.d.ts.map +1 -0
  146. package/lib/hooks/useCalendar.js +93 -0
  147. package/lib/hooks/useCalendar.js.map +1 -0
  148. package/lib/hooks/useDatePicker.d.ts +28 -0
  149. package/lib/hooks/useDatePicker.d.ts.map +1 -0
  150. package/lib/hooks/useDatePicker.js +150 -0
  151. package/lib/hooks/useDatePicker.js.map +1 -0
  152. package/lib/hooks/useDateRange.d.ts +23 -0
  153. package/lib/hooks/useDateRange.d.ts.map +1 -0
  154. package/lib/hooks/useDateRange.js +82 -0
  155. package/lib/hooks/useDateRange.js.map +1 -0
  156. package/lib/index.d.ts +7 -0
  157. package/lib/index.d.ts.map +1 -0
  158. package/lib/index.js +29 -0
  159. package/lib/index.js.map +1 -0
  160. package/lib/localization/en.d.ts +3 -0
  161. package/lib/localization/en.d.ts.map +1 -0
  162. package/lib/localization/en.js +80 -0
  163. package/lib/localization/en.js.map +1 -0
  164. package/lib/localization/gu.d.ts +3 -0
  165. package/lib/localization/gu.d.ts.map +1 -0
  166. package/lib/localization/gu.js +80 -0
  167. package/lib/localization/gu.js.map +1 -0
  168. package/lib/localization/hi.d.ts +3 -0
  169. package/lib/localization/hi.d.ts.map +1 -0
  170. package/lib/localization/hi.js +80 -0
  171. package/lib/localization/hi.js.map +1 -0
  172. package/lib/localization/index.d.ts +8 -0
  173. package/lib/localization/index.d.ts.map +1 -0
  174. package/lib/localization/index.js +32 -0
  175. package/lib/localization/index.js.map +1 -0
  176. package/lib/themes/dark.d.ts +3 -0
  177. package/lib/themes/dark.d.ts.map +1 -0
  178. package/lib/themes/dark.js +30 -0
  179. package/lib/themes/dark.js.map +1 -0
  180. package/lib/themes/index.d.ts +16 -0
  181. package/lib/themes/index.d.ts.map +1 -0
  182. package/lib/themes/index.js +56 -0
  183. package/lib/themes/index.js.map +1 -0
  184. package/lib/themes/light.d.ts +3 -0
  185. package/lib/themes/light.d.ts.map +1 -0
  186. package/lib/themes/light.js +30 -0
  187. package/lib/themes/light.js.map +1 -0
  188. package/lib/types/index.d.ts +344 -0
  189. package/lib/types/index.d.ts.map +1 -0
  190. package/lib/types/index.js +3 -0
  191. package/lib/types/index.js.map +1 -0
  192. package/lib/utils/calendarUtils.d.ts +27 -0
  193. package/lib/utils/calendarUtils.d.ts.map +1 -0
  194. package/lib/utils/calendarUtils.js +108 -0
  195. package/lib/utils/calendarUtils.js.map +1 -0
  196. package/lib/utils/dateFormatting.d.ts +29 -0
  197. package/lib/utils/dateFormatting.d.ts.map +1 -0
  198. package/lib/utils/dateFormatting.js +114 -0
  199. package/lib/utils/dateFormatting.js.map +1 -0
  200. package/lib/utils/dateParsing.d.ts +23 -0
  201. package/lib/utils/dateParsing.d.ts.map +1 -0
  202. package/lib/utils/dateParsing.js +289 -0
  203. package/lib/utils/dateParsing.js.map +1 -0
  204. package/lib/utils/dateUtils.d.ts +20 -0
  205. package/lib/utils/dateUtils.d.ts.map +1 -0
  206. package/lib/utils/dateUtils.js +115 -0
  207. package/lib/utils/dateUtils.js.map +1 -0
  208. package/lib/utils/dateValidation.d.ts +36 -0
  209. package/lib/utils/dateValidation.d.ts.map +1 -0
  210. package/lib/utils/dateValidation.js +196 -0
  211. package/lib/utils/dateValidation.js.map +1 -0
  212. package/lib/utils/index.d.ts +7 -0
  213. package/lib/utils/index.d.ts.map +1 -0
  214. package/lib/utils/index.js +23 -0
  215. package/lib/utils/index.js.map +1 -0
  216. package/lib/utils/timeUtils.d.ts +78 -0
  217. package/lib/utils/timeUtils.d.ts.map +1 -0
  218. package/lib/utils/timeUtils.js +335 -0
  219. package/lib/utils/timeUtils.js.map +1 -0
  220. package/package.json +92 -3
  221. package/src/components/Calendar/Calendar.tsx +314 -0
  222. package/src/components/Calendar/CalendarGrid.tsx +47 -0
  223. package/src/components/Calendar/CalendarHeader.tsx +176 -0
  224. package/src/components/Calendar/DateCell.tsx +118 -0
  225. package/src/components/Calendar/MonthYearSelectorModal.tsx +407 -0
  226. package/src/components/Calendar/WeekDays.tsx +49 -0
  227. package/src/components/Calendar/index.ts +6 -0
  228. package/src/components/DatePicker.tsx +834 -0
  229. package/src/components/Input/CalendarPopup.tsx +168 -0
  230. package/src/components/Input/DateInput.tsx +259 -0
  231. package/src/components/Input/index.ts +2 -0
  232. package/src/components/ManualDateInput/DateInputField.tsx +493 -0
  233. package/src/components/ManualDateInput/DateValidationMessage.tsx +65 -0
  234. package/src/components/ManualDateInput/ManualDateInput.tsx +66 -0
  235. package/src/components/ManualDateInput/index.ts +3 -0
  236. package/src/components/Range/RangeDateCell.tsx +174 -0
  237. package/src/components/Range/RangePicker.tsx +484 -0
  238. package/src/components/Range/index.ts +2 -0
  239. package/src/components/Time/ClockDial.tsx +450 -0
  240. package/src/components/Time/DateTimePicker.tsx +395 -0
  241. package/src/components/Time/TimePicker.tsx +899 -0
  242. package/src/components/Time/WheelTimePicker.tsx +356 -0
  243. package/src/components/Time/index.ts +4 -0
  244. package/src/components/Wheel/WheelColumn.tsx +300 -0
  245. package/src/components/Wheel/WheelPicker.tsx +265 -0
  246. package/src/components/Wheel/index.ts +2 -0
  247. package/src/components/common/Button.tsx +125 -0
  248. package/src/components/common/IconButton.tsx +237 -0
  249. package/src/components/common/Modal.tsx +137 -0
  250. package/src/components/common/index.ts +3 -0
  251. package/src/components/index.ts +8 -0
  252. package/src/hooks/index.ts +3 -0
  253. package/src/hooks/useCalendar.ts +153 -0
  254. package/src/hooks/useDatePicker.ts +216 -0
  255. package/src/hooks/useDateRange.ts +135 -0
  256. package/src/index.ts +17 -0
  257. package/src/localization/en.ts +78 -0
  258. package/src/localization/gu.ts +78 -0
  259. package/src/localization/hi.ts +78 -0
  260. package/src/localization/index.ts +31 -0
  261. package/src/themes/dark.ts +28 -0
  262. package/src/themes/index.ts +73 -0
  263. package/src/themes/light.ts +28 -0
  264. package/src/types/index.ts +452 -0
  265. package/src/utils/calendarUtils.ts +152 -0
  266. package/src/utils/dateFormatting.ts +125 -0
  267. package/src/utils/dateParsing.ts +335 -0
  268. package/src/utils/dateUtils.ts +117 -0
  269. package/src/utils/dateValidation.ts +276 -0
  270. package/src/utils/index.ts +6 -0
  271. package/src/utils/timeUtils.ts +416 -0
@@ -0,0 +1,276 @@
1
+ import type {
2
+ DatePickerLocale,
3
+ ValidationResult,
4
+ DisabledDateCheck,
5
+ } from '../types';
6
+ import {
7
+ isLeapYear,
8
+ getDaysInMonth,
9
+ isBeforeDay,
10
+ isAfterDay,
11
+ isSameDay,
12
+ getDaysDifference,
13
+ } from './dateUtils';
14
+ import { validateTime, getTimeFromDate } from './timeUtils';
15
+
16
+ export interface DateValidationOptions {
17
+ minimumDate?: Date;
18
+ maximumDate?: Date;
19
+ disabledDates?: (Date | string)[] | DisabledDateCheck;
20
+ disabledWeekdays?: number[];
21
+ minimumTime?: string | Date;
22
+ maximumTime?: string | Date;
23
+ is24Hour?: boolean;
24
+ validateTimeComponent?: boolean;
25
+ locale?: DatePickerLocale;
26
+ }
27
+
28
+ export interface RangeValidationOptions extends DateValidationOptions {
29
+ maxRangeDays?: number;
30
+ }
31
+
32
+ /**
33
+ * Validates individual numeric components of a date strictly.
34
+ */
35
+ export const validateDateComponents = (
36
+ year: number,
37
+ month1Indexed: number,
38
+ day: number,
39
+ locale?: DatePickerLocale
40
+ ): ValidationResult => {
41
+ if (!Number.isInteger(year) || year < 1000 || year > 9999) {
42
+ return {
43
+ isValid: false,
44
+ errorCode: 'INVALID_YEAR',
45
+ error: locale?.errors.invalidDate || 'Invalid year. Must be a 4-digit year.',
46
+ };
47
+ }
48
+
49
+ if (!Number.isInteger(month1Indexed) || month1Indexed < 1 || month1Indexed > 12) {
50
+ return {
51
+ isValid: false,
52
+ errorCode: 'INVALID_MONTH',
53
+ error: locale?.errors.invalidDate || 'Invalid month. Must be between 1 and 12.',
54
+ };
55
+ }
56
+
57
+ const monthIndex = month1Indexed - 1;
58
+ const maxDays = getDaysInMonth(year, monthIndex);
59
+
60
+ if (month1Indexed === 2 && day === 29 && !isLeapYear(year)) {
61
+ return {
62
+ isValid: false,
63
+ errorCode: 'LEAP_YEAR',
64
+ error: locale?.errors.invalidDate || `${year} is not a leap year. February has 28 days.`,
65
+ };
66
+ }
67
+
68
+ if (!Number.isInteger(day) || day < 1 || day > maxDays) {
69
+ return {
70
+ isValid: false,
71
+ errorCode: 'INVALID_DAY',
72
+ error:
73
+ locale?.errors.invalidDate ||
74
+ `Invalid day for the selected month. Day must be between 1 and ${maxDays}.`,
75
+ };
76
+ }
77
+
78
+ return { isValid: true };
79
+ };
80
+
81
+ /**
82
+ * Checks if a specific date is disabled by disabledDates array or function
83
+ */
84
+ export const isDateDisabled = (
85
+ date: Date,
86
+ disabledDates?: (Date | string)[] | DisabledDateCheck
87
+ ): boolean => {
88
+ if (!disabledDates) {
89
+ return false;
90
+ }
91
+
92
+ if (typeof disabledDates === 'function') {
93
+ return disabledDates(date);
94
+ }
95
+
96
+ if (Array.isArray(disabledDates)) {
97
+ return disabledDates.some((disabled) => {
98
+ if (disabled instanceof Date) {
99
+ return isSameDay(disabled, date);
100
+ }
101
+ if (typeof disabled === 'string') {
102
+ const [y, m, d] = disabled.split('-').map(Number);
103
+ if (y && m && d) {
104
+ return (
105
+ date.getFullYear() === y &&
106
+ date.getMonth() === m - 1 &&
107
+ date.getDate() === d
108
+ );
109
+ }
110
+ }
111
+ return false;
112
+ });
113
+ }
114
+
115
+ return false;
116
+ };
117
+
118
+ /**
119
+ * Checks if day of the week is disabled (0 = Sunday, 6 = Saturday)
120
+ */
121
+ export const isWeekdayDisabled = (
122
+ date: Date,
123
+ disabledWeekdays?: number[]
124
+ ): boolean => {
125
+ if (!disabledWeekdays || !Array.isArray(disabledWeekdays)) {
126
+ return false;
127
+ }
128
+ return disabledWeekdays.includes(date.getDay());
129
+ };
130
+
131
+ /**
132
+ * Validates a Date object against all date and time constraints
133
+ */
134
+ export const validateDate = (
135
+ date: Date | null | undefined,
136
+ options?: DateValidationOptions
137
+ ): ValidationResult => {
138
+ if (!date || !(date instanceof Date) || isNaN(date.getTime())) {
139
+ return {
140
+ isValid: false,
141
+ errorCode: 'INVALID_FORMAT',
142
+ error: options?.locale?.errors.invalidDate || 'Invalid date value.',
143
+ };
144
+ }
145
+
146
+ const {
147
+ minimumDate,
148
+ maximumDate,
149
+ disabledDates,
150
+ disabledWeekdays,
151
+ minimumTime,
152
+ maximumTime,
153
+ is24Hour = false,
154
+ validateTimeComponent = false,
155
+ locale,
156
+ } = options || {};
157
+
158
+ // 1. Day-level minimum date check
159
+ if (minimumDate && isBeforeDay(date, minimumDate)) {
160
+ const minFormatted = `${minimumDate.getDate()}/${minimumDate.getMonth() + 1}/${minimumDate.getFullYear()}`;
161
+ const errorMsg =
162
+ locale?.errors.minDate.replace('{min}', minFormatted) ||
163
+ `Date cannot be earlier than ${minFormatted}.`;
164
+ return {
165
+ isValid: false,
166
+ errorCode: 'MIN_DATE',
167
+ error: errorMsg,
168
+ };
169
+ }
170
+
171
+ // 2. Day-level maximum date check
172
+ if (maximumDate && isAfterDay(date, maximumDate)) {
173
+ const maxFormatted = `${maximumDate.getDate()}/${maximumDate.getMonth() + 1}/${maximumDate.getFullYear()}`;
174
+ const errorMsg =
175
+ locale?.errors.maxDate.replace('{max}', maxFormatted) ||
176
+ `Date cannot be later than ${maxFormatted}.`;
177
+ return {
178
+ isValid: false,
179
+ errorCode: 'MAX_DATE',
180
+ error: errorMsg,
181
+ };
182
+ }
183
+
184
+ // 3. Disabled specific dates
185
+ if (isDateDisabled(date, disabledDates)) {
186
+ return {
187
+ isValid: false,
188
+ errorCode: 'DISABLED_DATE',
189
+ error: locale?.errors.disabledDate || 'This date is unavailable.',
190
+ };
191
+ }
192
+
193
+ // 4. Disabled weekdays
194
+ if (isWeekdayDisabled(date, disabledWeekdays)) {
195
+ return {
196
+ isValid: false,
197
+ errorCode: 'DISABLED_WEEKDAY',
198
+ error: locale?.errors.disabledWeekday || 'This day of the week is disabled.',
199
+ };
200
+ }
201
+
202
+ // 5. Time validation (when validateTimeComponent is active or time boundaries are set)
203
+ if (validateTimeComponent || minimumTime || maximumTime) {
204
+ const timeObj = getTimeFromDate(date, is24Hour);
205
+ const timeVal = validateTime(timeObj, is24Hour, {
206
+ minimumTime,
207
+ maximumTime,
208
+ selectedDate: date,
209
+ minimumDate,
210
+ maximumDate,
211
+ locale,
212
+ });
213
+ if (!timeVal.isValid) {
214
+ return timeVal;
215
+ }
216
+ }
217
+
218
+ return { isValid: true };
219
+ };
220
+
221
+ /**
222
+ * Validates a Date Range against constraints
223
+ */
224
+ export const validateDateRange = (
225
+ startDate: Date | null | undefined,
226
+ endDate: Date | null | undefined,
227
+ options?: RangeValidationOptions
228
+ ): ValidationResult => {
229
+ const { maxRangeDays, locale } = options || {};
230
+
231
+ if (!startDate && !endDate) {
232
+ return { isValid: true };
233
+ }
234
+
235
+ if (startDate) {
236
+ const startVal = validateDate(startDate, options);
237
+ if (!startVal.isValid) {
238
+ return startVal;
239
+ }
240
+ }
241
+
242
+ if (endDate) {
243
+ const endVal = validateDate(endDate, options);
244
+ if (!endVal.isValid) {
245
+ return endVal;
246
+ }
247
+ }
248
+
249
+ if (startDate && endDate) {
250
+ if (isAfterDay(startDate, endDate)) {
251
+ return {
252
+ isValid: false,
253
+ errorCode: 'START_AFTER_END',
254
+ error:
255
+ locale?.errors.startDateAfterEndDate ||
256
+ 'Start date cannot be after end date.',
257
+ };
258
+ }
259
+
260
+ if (maxRangeDays && maxRangeDays > 0) {
261
+ const days = getDaysDifference(startDate, endDate);
262
+ if (days > maxRangeDays) {
263
+ const errorMsg =
264
+ locale?.errors.maxRangeExceeded.replace('{days}', String(maxRangeDays)) ||
265
+ `Selected range exceeds maximum allowed limit of ${maxRangeDays} days.`;
266
+ return {
267
+ isValid: false,
268
+ errorCode: 'RANGE_EXCEEDED',
269
+ error: errorMsg,
270
+ };
271
+ }
272
+ }
273
+ }
274
+
275
+ return { isValid: true };
276
+ };
@@ -0,0 +1,6 @@
1
+ export * from './dateUtils';
2
+ export * from './dateValidation';
3
+ export * from './dateFormatting';
4
+ export * from './dateParsing';
5
+ export * from './calendarUtils';
6
+ export * from './timeUtils';
@@ -0,0 +1,416 @@
1
+ import type {
2
+ DatePickerLocale,
3
+ SupportedLocale,
4
+ TimeObject,
5
+ TimePeriod,
6
+ ValidationResult,
7
+ } from '../types';
8
+ import { getLocale } from '../localization';
9
+ import { isSameDay } from './dateUtils';
10
+
11
+ export interface TimeValidationOptions {
12
+ minimumTime?: string | Date;
13
+ maximumTime?: string | Date;
14
+ selectedDate?: Date | null;
15
+ minimumDate?: Date;
16
+ maximumDate?: Date;
17
+ minuteInterval?: number;
18
+ locale?: SupportedLocale | DatePickerLocale;
19
+ }
20
+
21
+ export const padZero = (n: number, len = 2): string => {
22
+ return String(n).padStart(len, '0');
23
+ };
24
+
25
+ /**
26
+ * Detects if a format string specifies 24-hour mode.
27
+ * Returns true if format contains 24h tokens (HH, H) without 12h/AM/PM indicators.
28
+ */
29
+ export const is24HourFormat = (format?: string): boolean => {
30
+ if (!format) return false;
31
+ if (/hh|h\b|[Aa]/.test(format)) {
32
+ return false;
33
+ }
34
+ if (/HH|H\b/.test(format)) {
35
+ return true;
36
+ }
37
+ return false;
38
+ };
39
+
40
+ /**
41
+ * Converts a 24-hour number (0-23) to 12-hour format with AM/PM.
42
+ */
43
+ export const convert24To12 = (
44
+ hour24: number
45
+ ): { hour12: number; period: TimePeriod } => {
46
+ const clamped = Math.max(0, Math.min(23, Math.floor(hour24)));
47
+ if (clamped === 0) {
48
+ return { hour12: 12, period: 'AM' };
49
+ }
50
+ if (clamped === 12) {
51
+ return { hour12: 12, period: 'PM' };
52
+ }
53
+ if (clamped > 12) {
54
+ return { hour12: clamped - 12, period: 'PM' };
55
+ }
56
+ return { hour12: clamped, period: 'AM' };
57
+ };
58
+
59
+ /**
60
+ * Converts a 12-hour number (1-12) and AM/PM period to 24-hour (0-23).
61
+ */
62
+ export const convert12To24 = (hour12: number, period: TimePeriod): number => {
63
+ const clamped = Math.max(1, Math.min(12, Math.floor(hour12)));
64
+ if (period === 'AM') {
65
+ return clamped === 12 ? 0 : clamped;
66
+ } else {
67
+ return clamped === 12 ? 12 : clamped + 12;
68
+ }
69
+ };
70
+
71
+ /**
72
+ * Returns a new Date with updated time components while preserving year, month, date.
73
+ */
74
+ export const setTimeOnDate = (
75
+ date: Date,
76
+ hours: number,
77
+ minutes: number,
78
+ seconds = 0,
79
+ ms = 0
80
+ ): Date => {
81
+ const result = new Date(date);
82
+ result.setHours(hours, minutes, seconds, ms);
83
+ return result;
84
+ };
85
+
86
+ /**
87
+ * Extracts TimeObject from a Date.
88
+ */
89
+ export const getTimeFromDate = (
90
+ date: Date,
91
+ is24Hour = false
92
+ ): TimeObject => {
93
+ const h24 = date.getHours();
94
+ const minutes = date.getMinutes();
95
+ const seconds = date.getSeconds();
96
+
97
+ if (is24Hour) {
98
+ return {
99
+ hours: h24,
100
+ minutes,
101
+ seconds,
102
+ is24Hour: true,
103
+ period: h24 >= 12 ? 'PM' : 'AM',
104
+ };
105
+ }
106
+
107
+ const { hour12, period } = convert24To12(h24);
108
+ return {
109
+ hours: hour12,
110
+ minutes,
111
+ seconds,
112
+ period,
113
+ is24Hour: false,
114
+ };
115
+ };
116
+
117
+ /**
118
+ * Parses time string (e.g. "14:30", "02:30 PM", "9:45 AM", "23:59:59")
119
+ */
120
+ export const parseTimeString = (
121
+ text: string
122
+ ): {
123
+ hours24: number;
124
+ hours: number;
125
+ minutes: number;
126
+ seconds: number;
127
+ is24Hour: boolean;
128
+ period?: TimePeriod;
129
+ } | null => {
130
+ const trimmed = text.trim();
131
+ if (!trimmed) return null;
132
+
133
+ // Match 12h: "02:30 PM", "2:30:15 pm", "11:00 AM"
134
+ const match12 = trimmed.match(
135
+ /^(\d{1,2}):(\d{2})(?::(\d{2}))?\s*(AM|PM|am|pm)$/i
136
+ );
137
+ if (match12) {
138
+ const rawH = parseInt(match12[1], 10);
139
+ const m = parseInt(match12[2], 10);
140
+ const s = match12[3] ? parseInt(match12[3], 10) : 0;
141
+ const period = match12[4].toUpperCase() as TimePeriod;
142
+
143
+ if (rawH < 1 || rawH > 12 || m < 0 || m > 59 || s < 0 || s > 59) {
144
+ return null;
145
+ }
146
+
147
+ const hours24 = convert12To24(rawH, period);
148
+ return {
149
+ hours24,
150
+ hours: rawH,
151
+ minutes: m,
152
+ seconds: s,
153
+ is24Hour: false,
154
+ period,
155
+ };
156
+ }
157
+
158
+ // Match 24h: "14:30", "09:15:30", "00:00"
159
+ const match24 = trimmed.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/);
160
+ if (match24) {
161
+ const rawH = parseInt(match24[1], 10);
162
+ const m = parseInt(match24[2], 10);
163
+ const s = match24[3] ? parseInt(match24[3], 10) : 0;
164
+
165
+ if (rawH < 0 || rawH > 23 || m < 0 || m > 59 || s < 0 || s > 59) {
166
+ return null;
167
+ }
168
+
169
+ return {
170
+ hours24: rawH,
171
+ hours: rawH,
172
+ minutes: m,
173
+ seconds: s,
174
+ is24Hour: true,
175
+ period: rawH >= 12 ? 'PM' : 'AM',
176
+ };
177
+ }
178
+
179
+ return null;
180
+ };
181
+
182
+ /**
183
+ * Converts a time representation (string, Date, or TimeObject) to total minutes from midnight (0..1439).
184
+ */
185
+ export const getMinutesFromMidnight = (
186
+ time: string | Date | { hours: number; minutes: number; period?: TimePeriod; is24Hour?: boolean }
187
+ ): number | null => {
188
+ if (time instanceof Date) {
189
+ return time.getHours() * 60 + time.getMinutes();
190
+ }
191
+
192
+ if (typeof time === 'string') {
193
+ const parsed = parseTimeString(time);
194
+ if (!parsed) return null;
195
+ return parsed.hours24 * 60 + parsed.minutes;
196
+ }
197
+
198
+ if (typeof time === 'object' && time !== null) {
199
+ let h24 = time.hours;
200
+ if (!time.is24Hour && time.period) {
201
+ h24 = convert12To24(time.hours, time.period);
202
+ }
203
+ return h24 * 60 + time.minutes;
204
+ }
205
+
206
+ return null;
207
+ };
208
+
209
+ /**
210
+ * Formats minutes from midnight into a display string.
211
+ */
212
+ export const formatMinutesFromMidnight = (
213
+ totalMinutes: number,
214
+ is24Hour = false
215
+ ): string => {
216
+ const h24 = Math.floor(totalMinutes / 60) % 24;
217
+ const m = totalMinutes % 60;
218
+
219
+ if (is24Hour) {
220
+ return `${padZero(h24)}:${padZero(m)}`;
221
+ }
222
+
223
+ const { hour12, period } = convert24To12(h24);
224
+ return `${padZero(hour12)}:${padZero(m)} ${period}`;
225
+ };
226
+
227
+ /**
228
+ * Validates time strictly against ranges, boundaries, and interval rules.
229
+ */
230
+ export const validateTime = (
231
+ time: {
232
+ hours: number;
233
+ minutes: number;
234
+ seconds?: number;
235
+ period?: TimePeriod;
236
+ is24Hour?: boolean;
237
+ },
238
+ is24Hour: boolean,
239
+ options?: TimeValidationOptions
240
+ ): ValidationResult => {
241
+ const { hours, minutes, seconds = 0, period } = time;
242
+ const locale = getLocale(options?.locale);
243
+
244
+ // 1. Basic hour boundaries
245
+ if (is24Hour) {
246
+ if (!Number.isInteger(hours) || hours < 0 || hours > 23) {
247
+ return {
248
+ isValid: false,
249
+ errorCode: 'INVALID_HOUR',
250
+ error: locale.errors.invalidTime || 'Hour must be between 00 and 23.',
251
+ };
252
+ }
253
+ } else {
254
+ if (!Number.isInteger(hours) || hours < 1 || hours > 12) {
255
+ return {
256
+ isValid: false,
257
+ errorCode: 'INVALID_HOUR',
258
+ error: locale.errors.invalidTime || 'Hour must be between 01 and 12.',
259
+ };
260
+ }
261
+ if (!period || (period !== 'AM' && period !== 'PM')) {
262
+ return {
263
+ isValid: false,
264
+ errorCode: 'INVALID_TIME',
265
+ error: locale.errors.invalidTime || 'Period must be AM or PM.',
266
+ };
267
+ }
268
+ }
269
+
270
+ // 2. Minute boundaries
271
+ if (!Number.isInteger(minutes) || minutes < 0 || minutes > 59) {
272
+ return {
273
+ isValid: false,
274
+ errorCode: 'INVALID_MINUTE',
275
+ error: locale.errors.invalidTime || 'Minute must be between 00 and 59.',
276
+ };
277
+ }
278
+
279
+ // 3. Second boundaries
280
+ if (!Number.isInteger(seconds) || seconds < 0 || seconds > 59) {
281
+ return {
282
+ isValid: false,
283
+ errorCode: 'INVALID_SECOND',
284
+ error: locale.errors.invalidTime || 'Second must be between 00 and 59.',
285
+ };
286
+ }
287
+
288
+ const hour24 = is24Hour ? hours : convert12To24(hours, period as TimePeriod);
289
+ const currentTotalMinutes = hour24 * 60 + minutes;
290
+
291
+ // 4. Standalone minimumTime check
292
+ if (options?.minimumTime) {
293
+ const minMinutes = getMinutesFromMidnight(options.minimumTime);
294
+ if (minMinutes !== null && currentTotalMinutes < minMinutes) {
295
+ const formattedMin = formatMinutesFromMidnight(minMinutes, is24Hour);
296
+ return {
297
+ isValid: false,
298
+ errorCode: 'MIN_TIME',
299
+ error: locale.errors.minTime.replace('{min}', formattedMin),
300
+ };
301
+ }
302
+ }
303
+
304
+ // 5. Standalone maximumTime check
305
+ if (options?.maximumTime) {
306
+ const maxMinutes = getMinutesFromMidnight(options.maximumTime);
307
+ if (maxMinutes !== null && currentTotalMinutes > maxMinutes) {
308
+ const formattedMax = formatMinutesFromMidnight(maxMinutes, is24Hour);
309
+ return {
310
+ isValid: false,
311
+ errorCode: 'MAX_TIME',
312
+ error: locale.errors.maxTime.replace('{max}', formattedMax),
313
+ };
314
+ }
315
+ }
316
+
317
+ // 6. DateTime minimumDate constraint (if date is same day as minimumDate)
318
+ if (options?.selectedDate && options.minimumDate && isSameDay(options.selectedDate, options.minimumDate)) {
319
+ const minDateMinutes = options.minimumDate.getHours() * 60 + options.minimumDate.getMinutes();
320
+ if (currentTotalMinutes < minDateMinutes) {
321
+ const formattedMin = formatMinutesFromMidnight(minDateMinutes, is24Hour);
322
+ return {
323
+ isValid: false,
324
+ errorCode: 'MIN_TIME',
325
+ error: locale.errors.minTime.replace('{min}', formattedMin),
326
+ };
327
+ }
328
+ }
329
+
330
+ // 7. DateTime maximumDate constraint (if date is same day as maximumDate)
331
+ if (options?.selectedDate && options.maximumDate && isSameDay(options.selectedDate, options.maximumDate)) {
332
+ const maxDateMinutes = options.maximumDate.getHours() * 60 + options.maximumDate.getMinutes();
333
+ if (currentTotalMinutes > maxDateMinutes) {
334
+ const formattedMax = formatMinutesFromMidnight(maxDateMinutes, is24Hour);
335
+ return {
336
+ isValid: false,
337
+ errorCode: 'MAX_TIME',
338
+ error: locale.errors.maxTime.replace('{max}', formattedMax),
339
+ };
340
+ }
341
+ }
342
+
343
+ return { isValid: true };
344
+ };
345
+
346
+ /**
347
+ * Checks if a specific hour is disabled under constraints.
348
+ */
349
+ export const isHourDisabled = (
350
+ hour: number,
351
+ is24Hour: boolean,
352
+ period?: TimePeriod,
353
+ options?: TimeValidationOptions
354
+ ): boolean => {
355
+ const h24 = is24Hour ? hour : convert12To24(hour, period || 'AM');
356
+ const hourStartMinutes = h24 * 60;
357
+ const hourEndMinutes = h24 * 60 + 59;
358
+
359
+ if (options?.minimumTime) {
360
+ const min = getMinutesFromMidnight(options.minimumTime);
361
+ if (min !== null && hourEndMinutes < min) return true;
362
+ }
363
+
364
+ if (options?.maximumTime) {
365
+ const max = getMinutesFromMidnight(options.maximumTime);
366
+ if (max !== null && hourStartMinutes > max) return true;
367
+ }
368
+
369
+ if (options?.selectedDate && options.minimumDate && isSameDay(options.selectedDate, options.minimumDate)) {
370
+ const min = options.minimumDate.getHours() * 60 + options.minimumDate.getMinutes();
371
+ if (hourEndMinutes < min) return true;
372
+ }
373
+
374
+ if (options?.selectedDate && options.maximumDate && isSameDay(options.selectedDate, options.maximumDate)) {
375
+ const max = options.maximumDate.getHours() * 60 + options.maximumDate.getMinutes();
376
+ if (hourStartMinutes > max) return true;
377
+ }
378
+
379
+ return false;
380
+ };
381
+
382
+ /**
383
+ * Checks if a specific minute is disabled for a given hour under constraints.
384
+ */
385
+ export const isMinuteDisabled = (
386
+ minute: number,
387
+ hour: number,
388
+ is24Hour: boolean,
389
+ period?: TimePeriod,
390
+ options?: TimeValidationOptions
391
+ ): boolean => {
392
+ const h24 = is24Hour ? hour : convert12To24(hour, period || 'AM');
393
+ const totalMinutes = h24 * 60 + minute;
394
+
395
+ if (options?.minimumTime) {
396
+ const min = getMinutesFromMidnight(options.minimumTime);
397
+ if (min !== null && totalMinutes < min) return true;
398
+ }
399
+
400
+ if (options?.maximumTime) {
401
+ const max = getMinutesFromMidnight(options.maximumTime);
402
+ if (max !== null && totalMinutes > max) return true;
403
+ }
404
+
405
+ if (options?.selectedDate && options.minimumDate && isSameDay(options.selectedDate, options.minimumDate)) {
406
+ const min = options.minimumDate.getHours() * 60 + options.minimumDate.getMinutes();
407
+ if (totalMinutes < min) return true;
408
+ }
409
+
410
+ if (options?.selectedDate && options.maximumDate && isSameDay(options.selectedDate, options.maximumDate)) {
411
+ const max = options.maximumDate.getHours() * 60 + options.maximumDate.getMinutes();
412
+ if (totalMinutes > max) return true;
413
+ }
414
+
415
+ return false;
416
+ };