ts-time-utils 4.0.1 → 4.4.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.
- package/README.md +175 -30
- package/dist/{age.js → age.cjs} +14 -6
- package/dist/{calculate.js → calculate.cjs} +30 -18
- package/dist/{calendar.js → calendar.cjs} +80 -39
- package/dist/{calendars.js → calendars.cjs} +48 -23
- package/dist/{chain.js → chain.cjs} +41 -40
- package/dist/{compare.js → compare.cjs} +58 -28
- package/dist/constants.cjs +19 -0
- package/dist/{countdown.js → countdown.cjs} +16 -7
- package/dist/{cron.js → cron.cjs} +20 -9
- package/dist/{dateRange.js → dateRange.cjs} +42 -26
- package/dist/{duration.js → duration.cjs} +56 -44
- package/dist/esm/chain.js +0 -5
- package/dist/esm/finance.d.ts +236 -0
- package/dist/esm/finance.d.ts.map +1 -0
- package/dist/esm/finance.js +495 -0
- package/dist/esm/healthcare.d.ts +260 -0
- package/dist/esm/healthcare.d.ts.map +1 -0
- package/dist/esm/healthcare.js +447 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/naturalLanguage.d.ts +1 -3
- package/dist/esm/naturalLanguage.d.ts.map +1 -1
- package/dist/esm/naturalLanguage.js +9 -2
- package/dist/esm/plugins.d.ts +0 -6
- package/dist/esm/plugins.d.ts.map +1 -1
- package/dist/esm/plugins.js +36 -42
- package/dist/esm/recurrence.d.ts.map +1 -1
- package/dist/esm/recurrence.js +3 -5
- package/dist/esm/scheduling.d.ts +206 -0
- package/dist/esm/scheduling.d.ts.map +1 -0
- package/dist/esm/scheduling.js +329 -0
- package/dist/esm/timezone.d.ts +6 -1
- package/dist/esm/timezone.d.ts.map +1 -1
- package/dist/esm/timezone.js +106 -66
- package/dist/esm/types.d.ts +0 -4
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/finance.cjs +512 -0
- package/dist/finance.d.ts +236 -0
- package/dist/finance.d.ts.map +1 -0
- package/dist/{fiscal.js → fiscal.cjs} +36 -17
- package/dist/{format.js → format.cjs} +83 -70
- package/dist/healthcare.cjs +462 -0
- package/dist/healthcare.d.ts +260 -0
- package/dist/healthcare.d.ts.map +1 -0
- package/dist/{holidays.js → holidays.cjs} +52 -25
- package/dist/index.cjs +595 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/{interval.js → interval.cjs} +24 -11
- package/dist/{iterate.js → iterate.cjs} +84 -41
- package/dist/{locale.js → locale.cjs} +54 -26
- package/dist/{naturalLanguage.js → naturalLanguage.cjs} +36 -23
- package/dist/naturalLanguage.d.ts +1 -3
- package/dist/naturalLanguage.d.ts.map +1 -1
- package/dist/{parse.js → parse.cjs} +24 -11
- package/dist/{performance.js → performance.cjs} +23 -10
- package/dist/{plugins.js → plugins.cjs} +48 -47
- package/dist/plugins.d.ts +0 -6
- package/dist/plugins.d.ts.map +1 -1
- package/dist/{precision.js → precision.cjs} +74 -37
- package/dist/{rangePresets.js → rangePresets.cjs} +40 -19
- package/dist/{recurrence.js → recurrence.cjs} +27 -21
- package/dist/recurrence.d.ts.map +1 -1
- package/dist/scheduling.cjs +344 -0
- package/dist/scheduling.d.ts +206 -0
- package/dist/scheduling.d.ts.map +1 -0
- package/dist/{serialize.js → serialize.cjs} +36 -17
- package/dist/{temporal.js → temporal.cjs} +28 -13
- package/dist/{timezone.js → timezone.cjs} +140 -82
- package/dist/timezone.d.ts +6 -1
- package/dist/timezone.d.ts.map +1 -1
- package/dist/{types.js → types.cjs} +9 -3
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/{validate.js → validate.cjs} +54 -26
- package/dist/{workingHours.js → workingHours.cjs} +36 -17
- package/package.json +52 -34
- package/dist/constants.js +0 -16
- package/dist/index.js +0 -66
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Healthcare utilities for medical scheduling and compliance timing
|
|
3
|
+
* Provides medication schedules, shift patterns, on-call rotations, and compliance windows
|
|
4
|
+
*/
|
|
5
|
+
import type { DateInput, DateRange } from './types.js';
|
|
6
|
+
import { Duration } from './duration.js';
|
|
7
|
+
/**
|
|
8
|
+
* Standard medical abbreviations for medication frequency
|
|
9
|
+
*/
|
|
10
|
+
export type MedicationFrequency = 'QD' | 'BID' | 'TID' | 'QID' | 'q4h' | 'q6h' | 'q8h' | 'q12h' | 'PRN';
|
|
11
|
+
/**
|
|
12
|
+
* Shift duration patterns
|
|
13
|
+
*/
|
|
14
|
+
export type ShiftPattern = '8hr' | '12hr' | '24hr';
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for shift scheduling
|
|
17
|
+
*/
|
|
18
|
+
export interface ShiftConfig {
|
|
19
|
+
pattern: ShiftPattern;
|
|
20
|
+
startTime: {
|
|
21
|
+
hour: number;
|
|
22
|
+
minute: number;
|
|
23
|
+
};
|
|
24
|
+
rotation?: 'fixed' | 'rotating';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for medication timing
|
|
28
|
+
*/
|
|
29
|
+
export interface MedicationConfig {
|
|
30
|
+
wakeTime?: string;
|
|
31
|
+
sleepTime?: string;
|
|
32
|
+
withMeals?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* On-call slot assignment
|
|
36
|
+
*/
|
|
37
|
+
export interface OnCallSlot {
|
|
38
|
+
staff: string;
|
|
39
|
+
start: Date;
|
|
40
|
+
end: Date;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Number of doses per day for each frequency
|
|
44
|
+
*/
|
|
45
|
+
export declare const MEDICATION_FREQUENCIES: Record<MedicationFrequency, number | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Hours per shift pattern
|
|
48
|
+
*/
|
|
49
|
+
export declare const SHIFT_DURATIONS: Record<ShiftPattern, number>;
|
|
50
|
+
/**
|
|
51
|
+
* Default medication timing config
|
|
52
|
+
*/
|
|
53
|
+
export declare const DEFAULT_MEDICATION_CONFIG: Required<MedicationConfig>;
|
|
54
|
+
/**
|
|
55
|
+
* Get medication administration times for a given date and frequency
|
|
56
|
+
*
|
|
57
|
+
* @param date - The date to get medication times for
|
|
58
|
+
* @param frequency - Medical frequency abbreviation (QD, BID, TID, etc.)
|
|
59
|
+
* @param config - Optional configuration for wake/sleep times
|
|
60
|
+
* @returns Array of Date objects for each dose, empty array for PRN
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const times = getMedicationTimes(new Date('2024-01-15'), 'BID');
|
|
65
|
+
* // Returns [7:00 AM, 7:00 PM] (twice daily)
|
|
66
|
+
*
|
|
67
|
+
* const customTimes = getMedicationTimes(new Date('2024-01-15'), 'TID', {
|
|
68
|
+
* wakeTime: '06:00',
|
|
69
|
+
* sleepTime: '21:00'
|
|
70
|
+
* });
|
|
71
|
+
* // Returns [6:00 AM, 1:30 PM, 9:00 PM] (three times daily)
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function getMedicationTimes(date: DateInput, frequency: MedicationFrequency, config?: MedicationConfig): Date[];
|
|
75
|
+
/**
|
|
76
|
+
* Get the next medication time after a given date/time
|
|
77
|
+
*
|
|
78
|
+
* @param after - The date/time to find the next medication time after
|
|
79
|
+
* @param frequency - Medical frequency abbreviation
|
|
80
|
+
* @param config - Optional configuration
|
|
81
|
+
* @returns Next medication Date, or null for PRN
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const next = getNextMedicationTime(new Date('2024-01-15T10:00:00'), 'BID');
|
|
86
|
+
* // Returns 7:00 PM on same day (next BID dose after 10 AM)
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function getNextMedicationTime(after: DateInput, frequency: MedicationFrequency, config?: MedicationConfig): Date | null;
|
|
90
|
+
/**
|
|
91
|
+
* Parse a medication frequency string to MedicationFrequency type
|
|
92
|
+
*
|
|
93
|
+
* @param freq - String to parse (case-insensitive)
|
|
94
|
+
* @returns MedicationFrequency or null if invalid
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* parseMedicationFrequency('bid'); // 'BID'
|
|
99
|
+
* parseMedicationFrequency('q8h'); // 'q8h'
|
|
100
|
+
* parseMedicationFrequency('invalid'); // null
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function parseMedicationFrequency(freq: string): MedicationFrequency | null;
|
|
104
|
+
/**
|
|
105
|
+
* Generate shift schedule for a date range
|
|
106
|
+
*
|
|
107
|
+
* @param start - Start of range
|
|
108
|
+
* @param end - End of range
|
|
109
|
+
* @param config - Shift configuration
|
|
110
|
+
* @returns Array of DateRange objects representing shifts
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const shifts = generateShiftSchedule(
|
|
115
|
+
* new Date('2024-01-15'),
|
|
116
|
+
* new Date('2024-01-17'),
|
|
117
|
+
* { pattern: '12hr', startTime: { hour: 7, minute: 0 } }
|
|
118
|
+
* );
|
|
119
|
+
* // Returns 4 shifts: day/night on 15th, day/night on 16th
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function generateShiftSchedule(start: DateInput, end: DateInput, config: ShiftConfig): DateRange[];
|
|
123
|
+
/**
|
|
124
|
+
* Get the shift containing a specific time
|
|
125
|
+
*
|
|
126
|
+
* @param date - The date/time to check
|
|
127
|
+
* @param config - Shift configuration
|
|
128
|
+
* @returns DateRange of the shift containing the time
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const shift = getShiftForTime(
|
|
133
|
+
* new Date('2024-01-15T14:00:00'),
|
|
134
|
+
* { pattern: '8hr', startTime: { hour: 7, minute: 0 } }
|
|
135
|
+
* );
|
|
136
|
+
* // Returns { start: 7:00 AM, end: 3:00 PM } (day shift)
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function getShiftForTime(date: DateInput, config: ShiftConfig): DateRange;
|
|
140
|
+
/**
|
|
141
|
+
* Check if a date/time is during a specific shift
|
|
142
|
+
*
|
|
143
|
+
* @param date - The date/time to check
|
|
144
|
+
* @param shiftStart - When the shift started
|
|
145
|
+
* @param config - Shift configuration
|
|
146
|
+
* @returns true if the time is during the shift
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* isOnShift(
|
|
151
|
+
* new Date('2024-01-15T10:00:00'),
|
|
152
|
+
* new Date('2024-01-15T07:00:00'),
|
|
153
|
+
* { pattern: '8hr', startTime: { hour: 7, minute: 0 } }
|
|
154
|
+
* ); // true (10 AM is during 7 AM - 3 PM shift)
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function isOnShift(date: DateInput, shiftStart: DateInput, config: ShiftConfig): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Create an on-call rotation schedule
|
|
160
|
+
*
|
|
161
|
+
* @param start - Start of rotation period
|
|
162
|
+
* @param end - End of rotation period
|
|
163
|
+
* @param staff - Array of staff names to rotate through
|
|
164
|
+
* @param hoursPerShift - Hours per on-call shift (default 24)
|
|
165
|
+
* @returns Array of OnCallSlot assignments
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const rotation = createOnCallRotation(
|
|
170
|
+
* new Date('2024-01-15'),
|
|
171
|
+
* new Date('2024-01-18'),
|
|
172
|
+
* ['Dr. Smith', 'Dr. Jones', 'Dr. Brown'],
|
|
173
|
+
* 24
|
|
174
|
+
* );
|
|
175
|
+
* // Returns 3 slots, one per doctor per day
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function createOnCallRotation(start: DateInput, end: DateInput, staff: string[], hoursPerShift?: number): OnCallSlot[];
|
|
179
|
+
/**
|
|
180
|
+
* Get the staff member on call at a specific time
|
|
181
|
+
*
|
|
182
|
+
* @param date - The date/time to check
|
|
183
|
+
* @param rotation - The on-call rotation schedule
|
|
184
|
+
* @returns Staff name or null if no one is on call
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* const onCall = getOnCallStaff(new Date('2024-01-16T03:00:00'), rotation);
|
|
189
|
+
* // Returns 'Dr. Jones' (whoever is on call at 3 AM on the 16th)
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function getOnCallStaff(date: DateInput, rotation: OnCallSlot[]): string | null;
|
|
193
|
+
/**
|
|
194
|
+
* Check if an event occurred within its compliance window
|
|
195
|
+
*
|
|
196
|
+
* @param event - When the event occurred
|
|
197
|
+
* @param deadline - The compliance deadline
|
|
198
|
+
* @returns true if event is before or at deadline
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* isWithinComplianceWindow(
|
|
203
|
+
* new Date('2024-01-15T10:00:00'),
|
|
204
|
+
* new Date('2024-01-15T12:00:00')
|
|
205
|
+
* ); // true (event occurred before deadline)
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare function isWithinComplianceWindow(event: DateInput, deadline: DateInput): boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Calculate the compliance deadline from an event
|
|
211
|
+
*
|
|
212
|
+
* @param event - The triggering event
|
|
213
|
+
* @param windowHours - Hours until deadline
|
|
214
|
+
* @returns Deadline Date
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* const deadline = getComplianceDeadline(
|
|
219
|
+
* new Date('2024-01-15T08:00:00'),
|
|
220
|
+
* 72
|
|
221
|
+
* );
|
|
222
|
+
* // Returns 2024-01-18T08:00:00 (72 hours later)
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export declare function getComplianceDeadline(event: DateInput, windowHours: number): Date;
|
|
226
|
+
/**
|
|
227
|
+
* Calculate time remaining until a compliance deadline
|
|
228
|
+
*
|
|
229
|
+
* @param event - Current time or event time
|
|
230
|
+
* @param deadline - The compliance deadline
|
|
231
|
+
* @returns Duration until deadline, or null if already past
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const remaining = timeUntilDeadline(
|
|
236
|
+
* new Date('2024-01-15T10:00:00'),
|
|
237
|
+
* new Date('2024-01-16T10:00:00')
|
|
238
|
+
* );
|
|
239
|
+
* // Returns Duration of 24 hours
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export declare function timeUntilDeadline(event: DateInput, deadline: DateInput): Duration | null;
|
|
243
|
+
/**
|
|
244
|
+
* Calculate rest hours between two shifts
|
|
245
|
+
*
|
|
246
|
+
* @param shift1End - End of first shift
|
|
247
|
+
* @param shift2Start - Start of second shift
|
|
248
|
+
* @returns Hours of rest between shifts
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* const rest = calculateRestBetweenShifts(
|
|
253
|
+
* new Date('2024-01-15T19:00:00'),
|
|
254
|
+
* new Date('2024-01-16T07:00:00')
|
|
255
|
+
* );
|
|
256
|
+
* // Returns 12 (hours of rest)
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export declare function calculateRestBetweenShifts(shift1End: DateInput, shift2Start: DateInput): number;
|
|
260
|
+
//# sourceMappingURL=healthcare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"healthcare.d.ts","sourceRoot":"","sources":["../src/healthcare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAMzC;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,IAAI,GACJ,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,M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,WAAW,EAAE,SAAS,GAAG,MAAM,CAM/F"}
|
|
@@ -1,7 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview International holiday utilities
|
|
3
4
|
* Calculate holidays for multiple countries including fixed, movable, and lunar-based holidays
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getUKHolidays = getUKHolidays;
|
|
8
|
+
exports.getNetherlandsHolidays = getNetherlandsHolidays;
|
|
9
|
+
exports.getGermanyHolidays = getGermanyHolidays;
|
|
10
|
+
exports.getCanadaHolidays = getCanadaHolidays;
|
|
11
|
+
exports.getAustraliaHolidays = getAustraliaHolidays;
|
|
12
|
+
exports.getItalyHolidays = getItalyHolidays;
|
|
13
|
+
exports.getSpainHolidays = getSpainHolidays;
|
|
14
|
+
exports.getChinaHolidays = getChinaHolidays;
|
|
15
|
+
exports.getIndiaHolidays = getIndiaHolidays;
|
|
16
|
+
exports.getJapanHolidays = getJapanHolidays;
|
|
17
|
+
exports.getFranceHolidays = getFranceHolidays;
|
|
18
|
+
exports.getBrazilHolidays = getBrazilHolidays;
|
|
19
|
+
exports.getMexicoHolidays = getMexicoHolidays;
|
|
20
|
+
exports.getSouthKoreaHolidays = getSouthKoreaHolidays;
|
|
21
|
+
exports.getSingaporeHolidays = getSingaporeHolidays;
|
|
22
|
+
exports.getPolandHolidays = getPolandHolidays;
|
|
23
|
+
exports.getSwedenHolidays = getSwedenHolidays;
|
|
24
|
+
exports.getBelgiumHolidays = getBelgiumHolidays;
|
|
25
|
+
exports.getSwitzerlandHolidays = getSwitzerlandHolidays;
|
|
26
|
+
exports.getHolidays = getHolidays;
|
|
27
|
+
exports.isHoliday = isHoliday;
|
|
28
|
+
exports.getHolidayName = getHolidayName;
|
|
29
|
+
exports.getNextHoliday = getNextHoliday;
|
|
30
|
+
exports.getUpcomingHolidays = getUpcomingHolidays;
|
|
31
|
+
exports.getSupportedCountries = getSupportedCountries;
|
|
5
32
|
/**
|
|
6
33
|
* Calculate Easter Sunday using the Anonymous Gregorian algorithm
|
|
7
34
|
* @param year - The year
|
|
@@ -64,7 +91,7 @@ function adjustForWeekend(date) {
|
|
|
64
91
|
// ============================================================================
|
|
65
92
|
// UK HOLIDAYS
|
|
66
93
|
// ============================================================================
|
|
67
|
-
|
|
94
|
+
function getUKHolidays(year) {
|
|
68
95
|
const holidays = [];
|
|
69
96
|
// New Year's Day (or substitute)
|
|
70
97
|
holidays.push({
|
|
@@ -139,7 +166,7 @@ export function getUKHolidays(year) {
|
|
|
139
166
|
// ============================================================================
|
|
140
167
|
// NETHERLANDS HOLIDAYS
|
|
141
168
|
// ============================================================================
|
|
142
|
-
|
|
169
|
+
function getNetherlandsHolidays(year) {
|
|
143
170
|
const holidays = [];
|
|
144
171
|
const easter = getEasterSunday(year);
|
|
145
172
|
// New Year's Day
|
|
@@ -235,7 +262,7 @@ export function getNetherlandsHolidays(year) {
|
|
|
235
262
|
// ============================================================================
|
|
236
263
|
// GERMANY HOLIDAYS
|
|
237
264
|
// ============================================================================
|
|
238
|
-
|
|
265
|
+
function getGermanyHolidays(year) {
|
|
239
266
|
const holidays = [];
|
|
240
267
|
const easter = getEasterSunday(year);
|
|
241
268
|
// New Year's Day
|
|
@@ -306,7 +333,7 @@ export function getGermanyHolidays(year) {
|
|
|
306
333
|
// ============================================================================
|
|
307
334
|
// CANADA HOLIDAYS
|
|
308
335
|
// ============================================================================
|
|
309
|
-
|
|
336
|
+
function getCanadaHolidays(year) {
|
|
310
337
|
const holidays = [];
|
|
311
338
|
const easter = getEasterSunday(year);
|
|
312
339
|
// New Year's Day
|
|
@@ -379,7 +406,7 @@ export function getCanadaHolidays(year) {
|
|
|
379
406
|
// ============================================================================
|
|
380
407
|
// AUSTRALIA HOLIDAYS
|
|
381
408
|
// ============================================================================
|
|
382
|
-
|
|
409
|
+
function getAustraliaHolidays(year) {
|
|
383
410
|
const holidays = [];
|
|
384
411
|
const easter = getEasterSunday(year);
|
|
385
412
|
// New Year's Day
|
|
@@ -450,7 +477,7 @@ export function getAustraliaHolidays(year) {
|
|
|
450
477
|
// ============================================================================
|
|
451
478
|
// ITALY HOLIDAYS
|
|
452
479
|
// ============================================================================
|
|
453
|
-
|
|
480
|
+
function getItalyHolidays(year) {
|
|
454
481
|
const holidays = [];
|
|
455
482
|
const easter = getEasterSunday(year);
|
|
456
483
|
// New Year's Day
|
|
@@ -535,7 +562,7 @@ export function getItalyHolidays(year) {
|
|
|
535
562
|
// ============================================================================
|
|
536
563
|
// SPAIN HOLIDAYS
|
|
537
564
|
// ============================================================================
|
|
538
|
-
|
|
565
|
+
function getSpainHolidays(year) {
|
|
539
566
|
const holidays = [];
|
|
540
567
|
const easter = getEasterSunday(year);
|
|
541
568
|
// New Year's Day
|
|
@@ -613,7 +640,7 @@ export function getSpainHolidays(year) {
|
|
|
613
640
|
// ============================================================================
|
|
614
641
|
// CHINA HOLIDAYS (Simplified - some are lunar calendar based)
|
|
615
642
|
// ============================================================================
|
|
616
|
-
|
|
643
|
+
function getChinaHolidays(year) {
|
|
617
644
|
const holidays = [];
|
|
618
645
|
// New Year's Day
|
|
619
646
|
holidays.push({
|
|
@@ -655,7 +682,7 @@ export function getChinaHolidays(year) {
|
|
|
655
682
|
// ============================================================================
|
|
656
683
|
// INDIA HOLIDAYS (Simplified - many are lunar calendar based)
|
|
657
684
|
// ============================================================================
|
|
658
|
-
|
|
685
|
+
function getIndiaHolidays(year) {
|
|
659
686
|
const holidays = [];
|
|
660
687
|
// Republic Day
|
|
661
688
|
holidays.push({
|
|
@@ -685,7 +712,7 @@ export function getIndiaHolidays(year) {
|
|
|
685
712
|
// ============================================================================
|
|
686
713
|
// JAPAN HOLIDAYS
|
|
687
714
|
// ============================================================================
|
|
688
|
-
|
|
715
|
+
function getJapanHolidays(year) {
|
|
689
716
|
const holidays = [];
|
|
690
717
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'JP', type: 'public' });
|
|
691
718
|
holidays.push({ name: 'Coming of Age Day', date: getNthWeekdayOfMonth(year, 0, 1, 2), countryCode: 'JP', type: 'public' });
|
|
@@ -708,7 +735,7 @@ export function getJapanHolidays(year) {
|
|
|
708
735
|
// ============================================================================
|
|
709
736
|
// FRANCE HOLIDAYS
|
|
710
737
|
// ============================================================================
|
|
711
|
-
|
|
738
|
+
function getFranceHolidays(year) {
|
|
712
739
|
const holidays = [];
|
|
713
740
|
const easter = getEasterSunday(year);
|
|
714
741
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'FR', type: 'public' });
|
|
@@ -727,7 +754,7 @@ export function getFranceHolidays(year) {
|
|
|
727
754
|
// ============================================================================
|
|
728
755
|
// BRAZIL HOLIDAYS
|
|
729
756
|
// ============================================================================
|
|
730
|
-
|
|
757
|
+
function getBrazilHolidays(year) {
|
|
731
758
|
const holidays = [];
|
|
732
759
|
const easter = getEasterSunday(year);
|
|
733
760
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'BR', type: 'public' });
|
|
@@ -746,7 +773,7 @@ export function getBrazilHolidays(year) {
|
|
|
746
773
|
// ============================================================================
|
|
747
774
|
// MEXICO HOLIDAYS
|
|
748
775
|
// ============================================================================
|
|
749
|
-
|
|
776
|
+
function getMexicoHolidays(year) {
|
|
750
777
|
const holidays = [];
|
|
751
778
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'MX', type: 'public' });
|
|
752
779
|
holidays.push({ name: 'Constitution Day', date: getNthWeekdayOfMonth(year, 1, 1, 1), countryCode: 'MX', type: 'public' });
|
|
@@ -760,7 +787,7 @@ export function getMexicoHolidays(year) {
|
|
|
760
787
|
// ============================================================================
|
|
761
788
|
// SOUTH KOREA HOLIDAYS
|
|
762
789
|
// ============================================================================
|
|
763
|
-
|
|
790
|
+
function getSouthKoreaHolidays(year) {
|
|
764
791
|
const holidays = [];
|
|
765
792
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'KR', type: 'public' });
|
|
766
793
|
holidays.push({ name: 'Independence Movement Day', date: new Date(year, 2, 1), countryCode: 'KR', type: 'public' });
|
|
@@ -776,7 +803,7 @@ export function getSouthKoreaHolidays(year) {
|
|
|
776
803
|
// ============================================================================
|
|
777
804
|
// SINGAPORE HOLIDAYS
|
|
778
805
|
// ============================================================================
|
|
779
|
-
|
|
806
|
+
function getSingaporeHolidays(year) {
|
|
780
807
|
const holidays = [];
|
|
781
808
|
const easter = getEasterSunday(year);
|
|
782
809
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'SG', type: 'public' });
|
|
@@ -790,7 +817,7 @@ export function getSingaporeHolidays(year) {
|
|
|
790
817
|
// ============================================================================
|
|
791
818
|
// POLAND HOLIDAYS
|
|
792
819
|
// ============================================================================
|
|
793
|
-
|
|
820
|
+
function getPolandHolidays(year) {
|
|
794
821
|
const holidays = [];
|
|
795
822
|
const easter = getEasterSunday(year);
|
|
796
823
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'PL', type: 'public' });
|
|
@@ -811,7 +838,7 @@ export function getPolandHolidays(year) {
|
|
|
811
838
|
// ============================================================================
|
|
812
839
|
// SWEDEN HOLIDAYS
|
|
813
840
|
// ============================================================================
|
|
814
|
-
|
|
841
|
+
function getSwedenHolidays(year) {
|
|
815
842
|
const holidays = [];
|
|
816
843
|
const easter = getEasterSunday(year);
|
|
817
844
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'SE', type: 'public' });
|
|
@@ -851,7 +878,7 @@ function getSaturdayBetween(year, startMonth, startDay, endMonth, endDay) {
|
|
|
851
878
|
// ============================================================================
|
|
852
879
|
// BELGIUM HOLIDAYS
|
|
853
880
|
// ============================================================================
|
|
854
|
-
|
|
881
|
+
function getBelgiumHolidays(year) {
|
|
855
882
|
const holidays = [];
|
|
856
883
|
const easter = getEasterSunday(year);
|
|
857
884
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'BE', type: 'public' });
|
|
@@ -869,7 +896,7 @@ export function getBelgiumHolidays(year) {
|
|
|
869
896
|
// ============================================================================
|
|
870
897
|
// SWITZERLAND HOLIDAYS (Federal only - cantons have additional)
|
|
871
898
|
// ============================================================================
|
|
872
|
-
|
|
899
|
+
function getSwitzerlandHolidays(year) {
|
|
873
900
|
const holidays = [];
|
|
874
901
|
const easter = getEasterSunday(year);
|
|
875
902
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'CH', type: 'public' });
|
|
@@ -890,7 +917,7 @@ export function getSwitzerlandHolidays(year) {
|
|
|
890
917
|
* @param countryCode - ISO country code
|
|
891
918
|
* @returns Array of holidays
|
|
892
919
|
*/
|
|
893
|
-
|
|
920
|
+
function getHolidays(year, countryCode) {
|
|
894
921
|
switch (countryCode) {
|
|
895
922
|
case 'UK':
|
|
896
923
|
return getUKHolidays(year);
|
|
@@ -943,7 +970,7 @@ export function getHolidays(year, countryCode) {
|
|
|
943
970
|
* @param countryCode - ISO country code
|
|
944
971
|
* @returns True if date is a holiday
|
|
945
972
|
*/
|
|
946
|
-
|
|
973
|
+
function isHoliday(date, countryCode) {
|
|
947
974
|
const holidays = getHolidays(date.getFullYear(), countryCode);
|
|
948
975
|
// Normalize to local date components for comparison
|
|
949
976
|
const targetYear = date.getFullYear();
|
|
@@ -959,7 +986,7 @@ export function isHoliday(date, countryCode) {
|
|
|
959
986
|
* @param countryCode - ISO country code
|
|
960
987
|
* @returns Holiday name or null if not a holiday
|
|
961
988
|
*/
|
|
962
|
-
|
|
989
|
+
function getHolidayName(date, countryCode) {
|
|
963
990
|
const holidays = getHolidays(date.getFullYear(), countryCode);
|
|
964
991
|
// Normalize to local date components for comparison
|
|
965
992
|
const targetYear = date.getFullYear();
|
|
@@ -976,7 +1003,7 @@ export function getHolidayName(date, countryCode) {
|
|
|
976
1003
|
* @param countryCode - ISO country code
|
|
977
1004
|
* @returns Next holiday or null
|
|
978
1005
|
*/
|
|
979
|
-
|
|
1006
|
+
function getNextHoliday(date, countryCode) {
|
|
980
1007
|
const year = date.getFullYear();
|
|
981
1008
|
let holidays = getHolidays(year, countryCode);
|
|
982
1009
|
// Also get next year's holidays
|
|
@@ -993,7 +1020,7 @@ export function getNextHoliday(date, countryCode) {
|
|
|
993
1020
|
* @param countryCode - ISO country code
|
|
994
1021
|
* @returns Array of upcoming holidays
|
|
995
1022
|
*/
|
|
996
|
-
|
|
1023
|
+
function getUpcomingHolidays(date, days, countryCode) {
|
|
997
1024
|
const year = date.getFullYear();
|
|
998
1025
|
let holidays = getHolidays(year, countryCode);
|
|
999
1026
|
// Also get next year's holidays
|
|
@@ -1007,6 +1034,6 @@ export function getUpcomingHolidays(date, days, countryCode) {
|
|
|
1007
1034
|
* Get all supported country codes
|
|
1008
1035
|
* @returns Array of country codes
|
|
1009
1036
|
*/
|
|
1010
|
-
|
|
1037
|
+
function getSupportedCountries() {
|
|
1011
1038
|
return ['UK', 'NL', 'DE', 'CA', 'AU', 'IT', 'ES', 'CN', 'IN', 'US', 'JP', 'FR', 'BR', 'MX', 'KR', 'SG', 'PL', 'SE', 'BE', 'CH'];
|
|
1012
1039
|
}
|