soff-date 1.0.9 β 1.1.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 +67 -12
- package/dist/ar-DOBc0AKI.d.ts +24 -0
- package/dist/ar-DZGRazxg.d.cts +24 -0
- package/dist/br-Bxl7-z70.d.cts +24 -0
- package/dist/br-DyXv2cHh.d.ts +24 -0
- package/dist/co-BPDNBIJT.d.ts +24 -0
- package/dist/co-pYFH0DtD.d.cts +24 -0
- package/dist/core/engine.cjs +1 -1
- package/dist/core/engine.cjs.map +1 -1
- package/dist/core/engine.js +1 -1
- package/dist/core/engine.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/locales/ar.cjs +1 -1
- package/dist/locales/ar.cjs.map +1 -1
- package/dist/locales/ar.d.cts +2 -13
- package/dist/locales/ar.d.ts +2 -13
- package/dist/locales/ar.js +1 -1
- package/dist/locales/ar.js.map +1 -1
- package/dist/locales/br.cjs +1 -1
- package/dist/locales/br.cjs.map +1 -1
- package/dist/locales/br.d.cts +2 -13
- package/dist/locales/br.d.ts +2 -13
- package/dist/locales/br.js +1 -1
- package/dist/locales/br.js.map +1 -1
- package/dist/locales/co.cjs +1 -1
- package/dist/locales/co.cjs.map +1 -1
- package/dist/locales/co.d.cts +2 -13
- package/dist/locales/co.d.ts +2 -13
- package/dist/locales/co.js +1 -1
- package/dist/locales/co.js.map +1 -1
- package/dist/locales/index.cjs +2 -0
- package/dist/locales/index.cjs.map +1 -0
- package/dist/locales/index.d.cts +6 -0
- package/dist/locales/index.d.ts +6 -0
- package/dist/locales/index.js +2 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/locales/mx.cjs +1 -1
- package/dist/locales/mx.cjs.map +1 -1
- package/dist/locales/mx.d.cts +2 -13
- package/dist/locales/mx.d.ts +2 -13
- package/dist/locales/mx.js +1 -1
- package/dist/locales/mx.js.map +1 -1
- package/dist/locales/us.cjs +1 -1
- package/dist/locales/us.cjs.map +1 -1
- package/dist/locales/us.d.cts +2 -13
- package/dist/locales/us.d.ts +2 -13
- package/dist/locales/us.js +1 -1
- package/dist/locales/us.js.map +1 -1
- package/dist/mx-AFleoZyO.d.ts +24 -0
- package/dist/mx-aI-ieOc4.d.cts +24 -0
- package/dist/us-8v1NFxuj.d.cts +24 -0
- package/dist/us-BMlmAp3v.d.ts +24 -0
- package/package.json +20 -10
package/README.md
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
- [Shift Rules Explained](#shift-rules-explained)
|
|
32
32
|
- [Emiliani (Colombia, Argentina)](#emiliani-colombia-argentina)
|
|
33
33
|
- [Observed US (USA, UK)](#observed-us-usa-uk)
|
|
34
|
+
- [Nearest Monday (Argentina)](#nearest-monday-argentina)
|
|
35
|
+
- [Mexico's Presidential Transition Holiday](#mexicos-presidential-transition-holiday)
|
|
34
36
|
- [Advanced: Create Your Own Locale](#advanced-create-your-own-locale)
|
|
35
37
|
- [Advanced: Use Algorithms Directly](#advanced-use-algorithms-directly)
|
|
36
38
|
- [Bundle Size](#bundle-size)
|
|
@@ -38,6 +40,7 @@
|
|
|
38
40
|
- [`getHolidays(year, options?)`](#getholidaysyear-options)
|
|
39
41
|
- [`isHoliday(date, options?)`](#isholidaydate-options)
|
|
40
42
|
- [`getNextHoliday(from?, options?)`](#getnextholidayfrom-options)
|
|
43
|
+
- [`formatRelativeTime(date, options?)`](#formatrelativetimedate-options)
|
|
41
44
|
- [Business Days Calculation](#business-days-calculation)
|
|
42
45
|
- [Types](#types)
|
|
43
46
|
- [Contributing](#contributing)
|
|
@@ -111,13 +114,23 @@ getHolidays(2025, { lang: { ...en, newYear: 'Happy New Year!' } });
|
|
|
111
114
|
|
|
112
115
|
## Available Locales
|
|
113
116
|
|
|
114
|
-
| Locale | Import | Holidays | Shift Rule
|
|
115
|
-
| ------------ | ---------------------- | -------- |
|
|
116
|
-
| π¨π΄ Colombia | `soff-date/locales/co` | 18 | Emiliani
|
|
117
|
-
| πΊπΈ USA | `soff-date/locales/us` | 10 | Observed
|
|
118
|
-
| π²π½ MΓ©xico | `soff-date/locales/mx` | 8 | NthWeekday |
|
|
119
|
-
| π¦π· Argentina | `soff-date/locales/ar` | 16 |
|
|
120
|
-
| π§π· Brasil | `soff-date/locales/br` | 13 | None
|
|
117
|
+
| Locale | Import | Holidays | Shift Rule |
|
|
118
|
+
| ------------ | ---------------------- | -------- | ------------------- |
|
|
119
|
+
| π¨π΄ Colombia | `soff-date/locales/co` | 18 | Emiliani |
|
|
120
|
+
| πΊπΈ USA | `soff-date/locales/us` | 10 | Observed |
|
|
121
|
+
| π²π½ MΓ©xico | `soff-date/locales/mx` | 8 | NthWeekday + Custom |
|
|
122
|
+
| π¦π· Argentina | `soff-date/locales/ar` | 16 | NearestMonday |
|
|
123
|
+
| π§π· Brasil | `soff-date/locales/br` | 13 | None |
|
|
124
|
+
|
|
125
|
+
If you need to select a locale dynamically, you can import all locale namespaces from the public barrel:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { co, mx, us } from 'soff-date/locales';
|
|
129
|
+
|
|
130
|
+
co.getHolidays(2025);
|
|
131
|
+
mx.isHoliday(new Date('2025-09-16'));
|
|
132
|
+
us.getNextHoliday(new Date('2025-07-01'));
|
|
133
|
+
```
|
|
121
134
|
|
|
122
135
|
## Available Languages
|
|
123
136
|
|
|
@@ -148,6 +161,27 @@ Holidays falling on weekends **move to Monday**.
|
|
|
148
161
|
{ date: '2026-07-03', key: 'independenceDayUS', isShifted: true }
|
|
149
162
|
```
|
|
150
163
|
|
|
164
|
+
### Nearest Monday (Argentina)
|
|
165
|
+
|
|
166
|
+
- Tuesday or Wednesday β previous Monday
|
|
167
|
+
- Thursday or Friday β next Monday
|
|
168
|
+
- Monday, Saturday and Sunday stay unchanged
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// June 17, 2025 = Tuesday β Monday June 16
|
|
172
|
+
{ date: '2025-06-16', key: 'guemesDay', isShifted: true }
|
|
173
|
+
|
|
174
|
+
// November 20, 2025 = Thursday β Monday November 24
|
|
175
|
+
{ date: '2025-11-24', key: 'sovereigntyDay', isShifted: true }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Mexico's Presidential Transition Holiday
|
|
179
|
+
|
|
180
|
+
Mexico includes a custom holiday for the transmission of executive power.
|
|
181
|
+
|
|
182
|
+
- From 2024 onward, it is observed on October 1 every 6 years: 2024, 2030, 2036, ...
|
|
183
|
+
- For historical years before 2024, the library preserves the previous December 1 cycle: 2018, 2012, ...
|
|
184
|
+
|
|
151
185
|
## Advanced: Create Your Own Locale
|
|
152
186
|
|
|
153
187
|
```typescript
|
|
@@ -194,9 +228,7 @@ export function getHolidays(year: number): Holiday[] {
|
|
|
194
228
|
## Advanced: Use Algorithms Directly
|
|
195
229
|
|
|
196
230
|
```typescript
|
|
197
|
-
import { getEasterSunday } from 'soff-date
|
|
198
|
-
import { getNthWeekday } from 'soff-date/core/algorithms/nth-weekday';
|
|
199
|
-
import { applyShift } from 'soff-date/core/algorithms/shifts';
|
|
231
|
+
import { getEasterSunday, getNthWeekday, applyShift } from 'soff-date';
|
|
200
232
|
|
|
201
233
|
// Easter Sunday 2025
|
|
202
234
|
getEasterSunday(2025); // β Date(2025, 3, 20)
|
|
@@ -250,6 +282,29 @@ Returns holiday info if the date is a holiday, `null` otherwise.
|
|
|
250
282
|
|
|
251
283
|
Returns the next holiday from a given date (defaults to today).
|
|
252
284
|
|
|
285
|
+
### `formatRelativeTime(date, options?)`
|
|
286
|
+
|
|
287
|
+
Formats a date relative to another date using `Intl.RelativeTimeFormat`.
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import { formatRelativeTime } from 'soff-date';
|
|
291
|
+
|
|
292
|
+
formatRelativeTime(new Date('2024-01-02T12:00:00Z'), {
|
|
293
|
+
baseDate: new Date('2024-01-01T12:00:00Z'),
|
|
294
|
+
locale: 'en',
|
|
295
|
+
});
|
|
296
|
+
// β in 1 day
|
|
297
|
+
|
|
298
|
+
formatRelativeTime(new Date('2024-01-01T12:00:00Z'), {
|
|
299
|
+
baseDate: new Date('2024-01-02T12:00:00Z'),
|
|
300
|
+
locale: 'en',
|
|
301
|
+
numeric: 'auto',
|
|
302
|
+
});
|
|
303
|
+
// β yesterday
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Returns an empty string for invalid dates instead of throwing.
|
|
307
|
+
|
|
253
308
|
## Business Days Calculation
|
|
254
309
|
|
|
255
310
|
In addition to holiday calculation, `soff-date` provides utilities to work with business days (skipping weekends and holidays).
|
|
@@ -274,13 +329,13 @@ diffBusinessDays(new Date('2025-01-06'), new Date('2025-01-10'));
|
|
|
274
329
|
## Types
|
|
275
330
|
|
|
276
331
|
```typescript
|
|
277
|
-
type ShiftRule = 'none' | 'emiliani' | 'observedUS' | 'nextMonday';
|
|
332
|
+
type ShiftRule = 'none' | 'emiliani' | 'observedUS' | 'nextMonday' | 'nearestMonday';
|
|
278
333
|
|
|
279
334
|
type HolidayRule =
|
|
280
335
|
| { type: 'fixed'; month: number; day: number }
|
|
281
336
|
| { type: 'nthWeekday'; month: number; weekday: number; n: number }
|
|
282
337
|
| { type: 'easterRelative'; offset: number }
|
|
283
|
-
| { type: 'custom'; calc: (year: number) => Date };
|
|
338
|
+
| { type: 'custom'; calc: (year: number) => Date | null };
|
|
284
339
|
|
|
285
340
|
interface HolidayDefinition {
|
|
286
341
|
key: string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HolidayNames, Holiday } from './core/types.js';
|
|
2
|
+
|
|
3
|
+
interface GetHolidaysOptions {
|
|
4
|
+
lang?: HolidayNames;
|
|
5
|
+
}
|
|
6
|
+
declare function getHolidays(year: number, options?: GetHolidaysOptions): Holiday[];
|
|
7
|
+
declare function isHoliday(date: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
8
|
+
declare function getNextHoliday(from?: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
9
|
+
declare function isBusinessDay(date: Date): boolean;
|
|
10
|
+
declare function businessDays(date: Date, amount: number): Date;
|
|
11
|
+
declare function diffBusinessDays(startDate: Date, endDate: Date): number;
|
|
12
|
+
|
|
13
|
+
type ar_GetHolidaysOptions = GetHolidaysOptions;
|
|
14
|
+
declare const ar_businessDays: typeof businessDays;
|
|
15
|
+
declare const ar_diffBusinessDays: typeof diffBusinessDays;
|
|
16
|
+
declare const ar_getHolidays: typeof getHolidays;
|
|
17
|
+
declare const ar_getNextHoliday: typeof getNextHoliday;
|
|
18
|
+
declare const ar_isBusinessDay: typeof isBusinessDay;
|
|
19
|
+
declare const ar_isHoliday: typeof isHoliday;
|
|
20
|
+
declare namespace ar {
|
|
21
|
+
export { type ar_GetHolidaysOptions as GetHolidaysOptions, ar_businessDays as businessDays, ar_diffBusinessDays as diffBusinessDays, ar_getHolidays as getHolidays, ar_getNextHoliday as getNextHoliday, ar_isBusinessDay as isBusinessDay, ar_isHoliday as isHoliday };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { type GetHolidaysOptions as G, ar as a, businessDays as b, getNextHoliday as c, diffBusinessDays as d, isHoliday as e, getHolidays as g, isBusinessDay as i };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HolidayNames, Holiday } from './core/types.cjs';
|
|
2
|
+
|
|
3
|
+
interface GetHolidaysOptions {
|
|
4
|
+
lang?: HolidayNames;
|
|
5
|
+
}
|
|
6
|
+
declare function getHolidays(year: number, options?: GetHolidaysOptions): Holiday[];
|
|
7
|
+
declare function isHoliday(date: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
8
|
+
declare function getNextHoliday(from?: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
9
|
+
declare function isBusinessDay(date: Date): boolean;
|
|
10
|
+
declare function businessDays(date: Date, amount: number): Date;
|
|
11
|
+
declare function diffBusinessDays(startDate: Date, endDate: Date): number;
|
|
12
|
+
|
|
13
|
+
type ar_GetHolidaysOptions = GetHolidaysOptions;
|
|
14
|
+
declare const ar_businessDays: typeof businessDays;
|
|
15
|
+
declare const ar_diffBusinessDays: typeof diffBusinessDays;
|
|
16
|
+
declare const ar_getHolidays: typeof getHolidays;
|
|
17
|
+
declare const ar_getNextHoliday: typeof getNextHoliday;
|
|
18
|
+
declare const ar_isBusinessDay: typeof isBusinessDay;
|
|
19
|
+
declare const ar_isHoliday: typeof isHoliday;
|
|
20
|
+
declare namespace ar {
|
|
21
|
+
export { type ar_GetHolidaysOptions as GetHolidaysOptions, ar_businessDays as businessDays, ar_diffBusinessDays as diffBusinessDays, ar_getHolidays as getHolidays, ar_getNextHoliday as getNextHoliday, ar_isBusinessDay as isBusinessDay, ar_isHoliday as isHoliday };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { type GetHolidaysOptions as G, ar as a, businessDays as b, getNextHoliday as c, diffBusinessDays as d, isHoliday as e, getHolidays as g, isBusinessDay as i };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HolidayNames, Holiday } from './core/types.cjs';
|
|
2
|
+
|
|
3
|
+
interface GetHolidaysOptions {
|
|
4
|
+
lang?: HolidayNames;
|
|
5
|
+
}
|
|
6
|
+
declare function getHolidays(year: number, options?: GetHolidaysOptions): Holiday[];
|
|
7
|
+
declare function isHoliday(date: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
8
|
+
declare function getNextHoliday(from?: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
9
|
+
declare function isBusinessDay(date: Date): boolean;
|
|
10
|
+
declare function businessDays(date: Date, amount: number): Date;
|
|
11
|
+
declare function diffBusinessDays(startDate: Date, endDate: Date): number;
|
|
12
|
+
|
|
13
|
+
type br_GetHolidaysOptions = GetHolidaysOptions;
|
|
14
|
+
declare const br_businessDays: typeof businessDays;
|
|
15
|
+
declare const br_diffBusinessDays: typeof diffBusinessDays;
|
|
16
|
+
declare const br_getHolidays: typeof getHolidays;
|
|
17
|
+
declare const br_getNextHoliday: typeof getNextHoliday;
|
|
18
|
+
declare const br_isBusinessDay: typeof isBusinessDay;
|
|
19
|
+
declare const br_isHoliday: typeof isHoliday;
|
|
20
|
+
declare namespace br {
|
|
21
|
+
export { type br_GetHolidaysOptions as GetHolidaysOptions, br_businessDays as businessDays, br_diffBusinessDays as diffBusinessDays, br_getHolidays as getHolidays, br_getNextHoliday as getNextHoliday, br_isBusinessDay as isBusinessDay, br_isHoliday as isHoliday };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { type GetHolidaysOptions as G, businessDays as a, br as b, getNextHoliday as c, diffBusinessDays as d, isHoliday as e, getHolidays as g, isBusinessDay as i };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HolidayNames, Holiday } from './core/types.js';
|
|
2
|
+
|
|
3
|
+
interface GetHolidaysOptions {
|
|
4
|
+
lang?: HolidayNames;
|
|
5
|
+
}
|
|
6
|
+
declare function getHolidays(year: number, options?: GetHolidaysOptions): Holiday[];
|
|
7
|
+
declare function isHoliday(date: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
8
|
+
declare function getNextHoliday(from?: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
9
|
+
declare function isBusinessDay(date: Date): boolean;
|
|
10
|
+
declare function businessDays(date: Date, amount: number): Date;
|
|
11
|
+
declare function diffBusinessDays(startDate: Date, endDate: Date): number;
|
|
12
|
+
|
|
13
|
+
type br_GetHolidaysOptions = GetHolidaysOptions;
|
|
14
|
+
declare const br_businessDays: typeof businessDays;
|
|
15
|
+
declare const br_diffBusinessDays: typeof diffBusinessDays;
|
|
16
|
+
declare const br_getHolidays: typeof getHolidays;
|
|
17
|
+
declare const br_getNextHoliday: typeof getNextHoliday;
|
|
18
|
+
declare const br_isBusinessDay: typeof isBusinessDay;
|
|
19
|
+
declare const br_isHoliday: typeof isHoliday;
|
|
20
|
+
declare namespace br {
|
|
21
|
+
export { type br_GetHolidaysOptions as GetHolidaysOptions, br_businessDays as businessDays, br_diffBusinessDays as diffBusinessDays, br_getHolidays as getHolidays, br_getNextHoliday as getNextHoliday, br_isBusinessDay as isBusinessDay, br_isHoliday as isHoliday };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { type GetHolidaysOptions as G, businessDays as a, br as b, getNextHoliday as c, diffBusinessDays as d, isHoliday as e, getHolidays as g, isBusinessDay as i };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HolidayNames, Holiday } from './core/types.js';
|
|
2
|
+
|
|
3
|
+
interface GetHolidaysOptions {
|
|
4
|
+
lang?: HolidayNames;
|
|
5
|
+
}
|
|
6
|
+
declare function getHolidays(year: number, options?: GetHolidaysOptions): Holiday[];
|
|
7
|
+
declare function isHoliday(date: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
8
|
+
declare function getNextHoliday(from?: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
9
|
+
declare function isBusinessDay(date: Date): boolean;
|
|
10
|
+
declare function businessDays(date: Date, amount: number): Date;
|
|
11
|
+
declare function diffBusinessDays(startDate: Date, endDate: Date): number;
|
|
12
|
+
|
|
13
|
+
type co_GetHolidaysOptions = GetHolidaysOptions;
|
|
14
|
+
declare const co_businessDays: typeof businessDays;
|
|
15
|
+
declare const co_diffBusinessDays: typeof diffBusinessDays;
|
|
16
|
+
declare const co_getHolidays: typeof getHolidays;
|
|
17
|
+
declare const co_getNextHoliday: typeof getNextHoliday;
|
|
18
|
+
declare const co_isBusinessDay: typeof isBusinessDay;
|
|
19
|
+
declare const co_isHoliday: typeof isHoliday;
|
|
20
|
+
declare namespace co {
|
|
21
|
+
export { type co_GetHolidaysOptions as GetHolidaysOptions, co_businessDays as businessDays, co_diffBusinessDays as diffBusinessDays, co_getHolidays as getHolidays, co_getNextHoliday as getNextHoliday, co_isBusinessDay as isBusinessDay, co_isHoliday as isHoliday };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { type GetHolidaysOptions as G, getNextHoliday as a, businessDays as b, co as c, diffBusinessDays as d, isHoliday as e, getHolidays as g, isBusinessDay as i };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HolidayNames, Holiday } from './core/types.cjs';
|
|
2
|
+
|
|
3
|
+
interface GetHolidaysOptions {
|
|
4
|
+
lang?: HolidayNames;
|
|
5
|
+
}
|
|
6
|
+
declare function getHolidays(year: number, options?: GetHolidaysOptions): Holiday[];
|
|
7
|
+
declare function isHoliday(date: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
8
|
+
declare function getNextHoliday(from?: Date, options?: GetHolidaysOptions): Holiday | null;
|
|
9
|
+
declare function isBusinessDay(date: Date): boolean;
|
|
10
|
+
declare function businessDays(date: Date, amount: number): Date;
|
|
11
|
+
declare function diffBusinessDays(startDate: Date, endDate: Date): number;
|
|
12
|
+
|
|
13
|
+
type co_GetHolidaysOptions = GetHolidaysOptions;
|
|
14
|
+
declare const co_businessDays: typeof businessDays;
|
|
15
|
+
declare const co_diffBusinessDays: typeof diffBusinessDays;
|
|
16
|
+
declare const co_getHolidays: typeof getHolidays;
|
|
17
|
+
declare const co_getNextHoliday: typeof getNextHoliday;
|
|
18
|
+
declare const co_isBusinessDay: typeof isBusinessDay;
|
|
19
|
+
declare const co_isHoliday: typeof isHoliday;
|
|
20
|
+
declare namespace co {
|
|
21
|
+
export { type co_GetHolidaysOptions as GetHolidaysOptions, co_businessDays as businessDays, co_diffBusinessDays as diffBusinessDays, co_getHolidays as getHolidays, co_getNextHoliday as getNextHoliday, co_isBusinessDay as isBusinessDay, co_isHoliday as isHoliday };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { type GetHolidaysOptions as G, getNextHoliday as a, businessDays as b, co as c, diffBusinessDays as d, isHoliday as e, getHolidays as g, isBusinessDay as i };
|
package/dist/core/engine.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';function
|
|
1
|
+
'use strict';function y(t){let n=t%19,o=Math.floor(t/100),e=t%100,a=Math.floor(o/4),s=o%4,i=Math.floor((o+8)/25),r=Math.floor((o-i+1)/3),l=(19*n+o-a-r+15)%30,C=Math.floor(e/4),U=e%4,c=(32+2*s+2*C-l-U)%7,d=Math.floor((n+11*l+22*c)/451),g=Math.floor((l+c-7*d+114)/31),m=(l+c-7*d+114)%31+1;return new Date(Date.UTC(t,g-1,m))}function h(t,n,o,e){if(e>0){let s=new Date(Date.UTC(t,n-1,1)).getUTCDay(),r=1+(o-s+7)%7+(e-1)*7;return new Date(Date.UTC(t,n-1,r))}else {let a=new Date(Date.UTC(t,n,0)),i=(a.getUTCDay()-o+7)%7,r=a.getUTCDate()-i+(e+1)*7;return new Date(Date.UTC(t,n-1,r))}}function T(t,n){let o=t.getUTCDay();if(n==="none")return {date:t,shifted:false};let e=new Date(t);switch(n){case "emiliani":case "nextMonday":{if(o===1)return {date:t,shifted:false};let a=(8-o)%7;e.setUTCDate(t.getUTCDate()+a);break}case "observedUS":if(o===0)e.setUTCDate(t.getUTCDate()+1);else if(o===6)e.setUTCDate(t.getUTCDate()-1);else return {date:t,shifted:false};break;case "nearestMonday":if(o===2)e.setUTCDate(t.getUTCDate()-1);else if(o===3)e.setUTCDate(t.getUTCDate()-2);else if(o===4)e.setUTCDate(t.getUTCDate()+4);else if(o===5)e.setUTCDate(t.getUTCDate()+3);else return {date:t,shifted:false};break;default:return {date:t,shifted:false}}return {date:e,shifted:true}}function p(t,n){switch(t.type){case "fixed":return new Date(Date.UTC(n,t.month-1,t.day));case "nthWeekday":return h(n,t.month,t.weekday,t.n);case "easterRelative":{let o=y(n),e=new Date(o);return e.setUTCDate(o.getUTCDate()+t.offset),e}case "custom":return t.calc(n)}}function D(t){try{return t.toISOString().split("T")[0]}catch{return ""}}function f(t){return t instanceof Date&&!Number.isNaN(t.getTime())}function u(t,n,o={}){return typeof n!="number"||Number.isNaN(n)?[]:t.map(e=>{let a=p(e.rule,n);if(!a||!f(a))return null;let{date:s,shifted:i}=T(a,e.shift??"none");return f(s)?{date:D(s),key:e.key,name:o[e.key]??e.key,...i&&{isShifted:true}}:null}).filter(e=>e!==null).sort((e,a)=>e.date.localeCompare(a.date))}function M(t,n,o){if(!f(n))return null;let e=n.getUTCFullYear(),a=D(n);return a?u(t,e,o).find(i=>i.date===a)??null:null}function N(t,n,o){if(!f(n))return null;let e=D(n);if(!e)return null;let a=n.getUTCFullYear(),s=u(t,a,o),i=s.find(r=>r.date>=e);return i||(s=u(t,a+1,o),i=s[0]),i??null}exports.checkIsHoliday=M;exports.findNextHoliday=N;exports.resolveHolidays=u;//# sourceMappingURL=engine.cjs.map
|
|
2
2
|
//# sourceMappingURL=engine.cjs.map
|
package/dist/core/engine.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/algorithms/easter.ts","../../src/core/algorithms/nth-weekday.ts","../../src/core/algorithms/shifts.ts","../../src/core/engine.ts"],"names":["getEasterSunday","year","a","b","c","d","e","f","g","h","i","k","l","m","month","day","getNthWeekday","weekday","n","firstWeekday","last","diff","applyShift","date","rule","result","daysToNextMonday","resolveRule","easter","toISODate","resolveHolidays","definitions","names","def","rawDate","shifted","checkIsHoliday","isoDate","findNextHoliday","from","isoFrom","holidays","next"],"mappings":"aAIO,SAASA,CAAAA,CAAgBC,CAAAA,CAAoB,CAClD,IAAMC,EAAID,CAAAA,CAAO,EAAA,CACXE,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAO,GAAG,CAAA,CACzBG,EAAIH,CAAAA,CAAO,GAAA,CACXI,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAI,CAAC,CAAA,CACpBG,EAAIH,CAAAA,CAAI,CAAA,CACRI,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAA,CAAOJ,CAAAA,CAAI,CAAA,EAAK,EAAE,EAC3BK,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAA,CAAOL,CAAAA,CAAII,CAAAA,CAAI,CAA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ACdL,CAAAA,CACAR,CAAAA,CACAS,CAAAA,CACgB,CAChB,IAAM/B,EAAOsB,CAAAA,CAAK,cAAA,EAAe,CAC3Bc,CAAAA,CAAUR,CAAAA,CAAUN,CAAI,CAAA,CAE9B,OADiBO,EAAgBC,CAAAA,CAAa9B,CAAAA,CAAM+B,CAAK,CAAA,CACzC,IAAA,CAAMvB,CAAAA,EAAMA,CAAAA,CAAE,IAAA,GAAS4B,CAAO,CAAA,EAAK,IACrD,CAGO,SAASC,CAAAA,CACdP,CAAAA,CACAQ,CAAAA,CACAP,CAAAA,CACgB,CAChB,IAAMQ,CAAAA,CAAUX,CAAAA,CAAUU,CAAI,CAAA,CACxBtC,CAAAA,CAAOsC,CAAAA,CAAK,cAAA,GAGdE,CAAAA,CAAWX,CAAAA,CAAgBC,CAAAA,CAAa9B,CAAAA,CAAM+B,CAAK,CAAA,CACnDU,CAAAA,CAAOD,CAAAA,CAAS,KAAMhC,CAAAA,EAAMA,CAAAA,CAAE,IAAA,EAAQ+B,CAAO,CAAA,CAGjD,OAAKE,CAAAA,GACHD,CAAAA,CAAWX,EAAgBC,CAAAA,CAAa9B,CAAAA,CAAO,CAAA,CAAG+B,CAAK,EACvDU,CAAAA,CAAOD,CAAAA,CAAS,CAAC,CAAA,CAAA,CAGZC,GAAQ,IACjB","file":"engine.cjs","sourcesContent":["/**\n * Calculates Easter Sunday (Meeus/Jones/Butcher algorithm)\n * Valid for Gregorian calendar (1583+)\n */\nexport function getEasterSunday(year: number): Date {\n const a = year % 19;\n const b = Math.floor(year / 100);\n const c = year % 100;\n const d = Math.floor(b / 4);\n const e = b % 4;\n const f = Math.floor((b + 8) / 25);\n const g = Math.floor((b - f + 1) / 3);\n const h = (19 * a + b - d - g + 15) % 30;\n const i = Math.floor(c / 4);\n const k = c % 4;\n const l = (32 + 2 * e + 2 * i - h - k) % 7;\n const m = Math.floor((a + 11 * h + 22 * l) / 451);\n const month = Math.floor((h + l - 7 * m + 114) / 31);\n const day = ((h + l - 7 * m + 114) % 31) + 1;\n\n return new Date(Date.UTC(year, month - 1, day));\n}\n","/**\n * Calculates the Nth weekday of a month\n * @param year - Year\n * @param month - Month (1-12)\n * @param weekday - Weekday (0=Sun, 1=Mon, ..., 6=Sat)\n * @param n - Occurrence (1=first, 2=second, -1=last)\n */\nexport function getNthWeekday(year: number, month: number, weekday: number, n: number): Date {\n if (n > 0) {\n // From start of month\n const first = new Date(Date.UTC(year, month - 1, 1));\n const firstWeekday = first.getUTCDay();\n const diff = (weekday - firstWeekday + 7) % 7;\n const day = 1 + diff + (n - 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n } else {\n // From end of month (n = -1 = last)\n // month is 1-12. Date.UTC(year, month, 0) gives the last day of month 'month'\n const last = new Date(Date.UTC(year, month, 0));\n const lastWeekday = last.getUTCDay();\n const diff = (lastWeekday - weekday + 7) % 7;\n const day = last.getUTCDate() - diff + (n + 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n }\n}\n","import type { ShiftRule } from '../types';\n\n/**\n * Applies a shift rule to a date\n * @returns { date: Date, shifted: boolean }\n */\nexport function applyShift(date: Date, rule: ShiftRule): { date: Date; shifted: boolean } {\n const day = date.getUTCDay(); // 0=Sun, 6=Sat\n\n if (rule === 'none') {\n return { date, shifted: false };\n }\n\n const result = new Date(date);\n\n switch (rule) {\n case 'emiliani':\n case 'nextMonday': {\n // If it's already Monday (1), do not move\n if (day === 1) {\n return { date, shifted: false };\n }\n // Move to next Monday\n // (8 - day) % 7 gives days until next Monday\n // Ex: Sun(0) -> (8-0)%7 = 1 (+1 day) -> Mon\n // Ex: Sat(6) -> (8-6)%7 = 2 (+2 days) -> Mon\n // Ex: Wed(3) -> (8-3)%7 = 5 (+5 days) -> Mon\n const daysToNextMonday = (8 - day) % 7;\n result.setUTCDate(date.getUTCDate() + daysToNextMonday);\n break;\n }\n\n case 'observedUS':\n // Only affects weekends\n if (day === 0) {\n // Sunday -> Monday (+1)\n result.setUTCDate(date.getUTCDate() + 1);\n } else if (day === 6) {\n // Saturday -> Friday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else {\n return { date, shifted: false };\n }\n break;\n\n case 'nearestMonday':\n // Argentina rule:\n // Tue/Wed -> Previous Monday\n // Thu/Fri -> Next Monday\n if (day === 2) {\n // Tuesday -> Monday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else if (day === 3) {\n // Wednesday -> Monday (-2)\n result.setUTCDate(date.getUTCDate() - 2);\n } else if (day === 4) {\n // Thursday -> Next Monday (+4)\n result.setUTCDate(date.getUTCDate() + 4);\n } else if (day === 5) {\n // Friday -> Next Monday (+3)\n result.setUTCDate(date.getUTCDate() + 3);\n } else {\n return { date, shifted: false };\n }\n break;\n\n default:\n return { date, shifted: false };\n }\n\n return { date: result, shifted: true };\n}\n","import type { HolidayDefinition, HolidayRule, Holiday } from './types';\nimport { getEasterSunday } from './algorithms/easter';\nimport { getNthWeekday } from './algorithms/nth-weekday';\nimport { applyShift } from './algorithms/shifts';\n\n/** Resolves a rule to a concrete date */\nfunction resolveRule(rule: HolidayRule, year: number): Date | null {\n switch (rule.type) {\n case 'fixed':\n return new Date(Date.UTC(year, rule.month - 1, rule.day));\n\n case 'nthWeekday':\n return getNthWeekday(year, rule.month, rule.weekday, rule.n);\n\n case 'easterRelative': {\n const easter = getEasterSunday(year);\n const result = new Date(easter);\n result.setUTCDate(easter.getUTCDate() + rule.offset);\n return result;\n }\n\n case 'custom':\n return rule.calc(year);\n }\n}\n\n/** Formats Date to ISO string (date only) */\nfunction toISODate(date: Date): string {\n return date.toISOString().split('T')[0];\n}\n\n/** Generates holidays for a year */\nexport function resolveHolidays(\n definitions: HolidayDefinition[],\n year: number,\n names: Record<string, string> = {},\n): Holiday[] {\n return definitions\n .map((def) => {\n const rawDate = resolveRule(def.rule, year);\n if (!rawDate) return null;\n\n const { date, shifted } = applyShift(rawDate, def.shift ?? 'none');\n\n return {\n date: toISODate(date),\n key: def.key,\n name: names[def.key] ?? def.key,\n ...(shifted && { isShifted: true }),\n };\n })\n .filter((h): h is Holiday => h !== null)\n .sort((a, b) => a.date.localeCompare(b.date));\n}\n\n/** Checks if a date is a holiday */\nexport function checkIsHoliday(\n definitions: HolidayDefinition[],\n date: Date,\n names?: Record<string, string>,\n): Holiday | null {\n const year = date.getUTCFullYear();\n const isoDate = toISODate(date);\n const holidays = resolveHolidays(definitions, year, names);\n return holidays.find((h) => h.date === isoDate) ?? null;\n}\n\n/** Gets the next holiday from a date */\nexport function findNextHoliday(\n definitions: HolidayDefinition[],\n from: Date,\n names?: Record<string, string>,\n): Holiday | null {\n const isoFrom = toISODate(from);\n const year = from.getUTCFullYear();\n\n // Search in current year\n let holidays = resolveHolidays(definitions, year, names);\n let next = holidays.find((h) => h.date >= isoFrom);\n\n // If none, search in next year\n if (!next) {\n holidays = resolveHolidays(definitions, year + 1, names);\n next = holidays[0];\n }\n\n return next ?? null;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/algorithms/easter.ts","../../src/core/algorithms/nth-weekday.ts","../../src/core/algorithms/shifts.ts","../../src/core/engine.ts"],"names":["getEasterSunday","year","a","b","c","d","e","f","g","h","i","k","l","m","month","day","getNthWeekday","weekday","n","firstWeekday","last","diff","applyShift","date","rule","result","daysToNextMonday","resolveRule","easter","toISODate","isValidDate","resolveHolidays","definitions","names","def","rawDate","shifted","checkIsHoliday","isoDate","findNextHoliday","from","isoFrom","holidays","next"],"mappings":"aAIO,SAASA,EAAgBC,CAAAA,CAAoB,CAClD,IAAMC,CAAAA,CAAID,EAAO,EAAA,CACXE,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,EAAO,GAAG,CAAA,CACzBG,CAAAA,CAAIH,CAAAA,CAAO,IACXI,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAI,CAAC,CAAA,CACpBG,CAAAA,CAAIH,CAAAA,CAAI,CAAA,CACRI,EAAI,IAAA,CAAK,KAAA,CAAA,CAAOJ,CAAAA,CAAI,CAA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/**\n * Calculates Easter Sunday (Meeus/Jones/Butcher algorithm)\n * Valid for Gregorian calendar (1583+)\n */\nexport function getEasterSunday(year: number): Date {\n const a = year % 19;\n const b = Math.floor(year / 100);\n const c = year % 100;\n const d = Math.floor(b / 4);\n const e = b % 4;\n const f = Math.floor((b + 8) / 25);\n const g = Math.floor((b - f + 1) / 3);\n const h = (19 * a + b - d - g + 15) % 30;\n const i = Math.floor(c / 4);\n const k = c % 4;\n const l = (32 + 2 * e + 2 * i - h - k) % 7;\n const m = Math.floor((a + 11 * h + 22 * l) / 451);\n const month = Math.floor((h + l - 7 * m + 114) / 31);\n const day = ((h + l - 7 * m + 114) % 31) + 1;\n\n return new Date(Date.UTC(year, month - 1, day));\n}\n","/**\n * Calculates the Nth weekday of a month\n * @param year - Year\n * @param month - Month (1-12)\n * @param weekday - Weekday (0=Sun, 1=Mon, ..., 6=Sat)\n * @param n - Occurrence (1=first, 2=second, -1=last)\n */\nexport function getNthWeekday(year: number, month: number, weekday: number, n: number): Date {\n if (n > 0) {\n // From start of month\n const first = new Date(Date.UTC(year, month - 1, 1));\n const firstWeekday = first.getUTCDay();\n const diff = (weekday - firstWeekday + 7) % 7;\n const day = 1 + diff + (n - 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n } else {\n // From end of month (n = -1 = last)\n // month is 1-12. Date.UTC(year, month, 0) gives the last day of month 'month'\n const last = new Date(Date.UTC(year, month, 0));\n const lastWeekday = last.getUTCDay();\n const diff = (lastWeekday - weekday + 7) % 7;\n const day = last.getUTCDate() - diff + (n + 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n }\n}\n","import type { ShiftRule } from '../types';\n\n/**\n * Applies a shift rule to a date\n * @returns { date: Date, shifted: boolean }\n */\nexport function applyShift(date: Date, rule: ShiftRule): { date: Date; shifted: boolean } {\n const day = date.getUTCDay(); // 0=Sun, 6=Sat\n\n if (rule === 'none') {\n return { date, shifted: false };\n }\n\n const result = new Date(date);\n\n switch (rule) {\n case 'emiliani':\n case 'nextMonday': {\n // If it's already Monday (1), do not move\n if (day === 1) {\n return { date, shifted: false };\n }\n // Move to next Monday\n // (8 - day) % 7 gives days until next Monday\n // Ex: Sun(0) -> (8-0)%7 = 1 (+1 day) -> Mon\n // Ex: Sat(6) -> (8-6)%7 = 2 (+2 days) -> Mon\n // Ex: Wed(3) -> (8-3)%7 = 5 (+5 days) -> Mon\n const daysToNextMonday = (8 - day) % 7;\n result.setUTCDate(date.getUTCDate() + daysToNextMonday);\n break;\n }\n\n case 'observedUS':\n // Only affects weekends\n if (day === 0) {\n // Sunday -> Monday (+1)\n result.setUTCDate(date.getUTCDate() + 1);\n } else if (day === 6) {\n // Saturday -> Friday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else {\n return { date, shifted: false };\n }\n break;\n\n case 'nearestMonday':\n // Argentina rule:\n // Tue/Wed -> Previous Monday\n // Thu/Fri -> Next Monday\n if (day === 2) {\n // Tuesday -> Monday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else if (day === 3) {\n // Wednesday -> Monday (-2)\n result.setUTCDate(date.getUTCDate() - 2);\n } else if (day === 4) {\n // Thursday -> Next Monday (+4)\n result.setUTCDate(date.getUTCDate() + 4);\n } else if (day === 5) {\n // Friday -> Next Monday (+3)\n result.setUTCDate(date.getUTCDate() + 3);\n } else {\n return { date, shifted: false };\n }\n break;\n\n default:\n return { date, shifted: false };\n }\n\n return { date: result, shifted: true };\n}\n","import type { HolidayDefinition, HolidayRule, Holiday } from './types';\nimport { getEasterSunday } from './algorithms/easter';\nimport { getNthWeekday } from './algorithms/nth-weekday';\nimport { applyShift } from './algorithms/shifts';\n\n/** Resolves a rule to a concrete date */\nfunction resolveRule(rule: HolidayRule, year: number): Date | null {\n switch (rule.type) {\n case 'fixed':\n return new Date(Date.UTC(year, rule.month - 1, rule.day));\n\n case 'nthWeekday':\n return getNthWeekday(year, rule.month, rule.weekday, rule.n);\n\n case 'easterRelative': {\n const easter = getEasterSunday(year);\n const result = new Date(easter);\n result.setUTCDate(easter.getUTCDate() + rule.offset);\n return result;\n }\n\n case 'custom':\n return rule.calc(year);\n }\n}\n\n/** Formats Date to ISO string (date only) */\nfunction toISODate(date: Date): string {\n try {\n return date.toISOString().split('T')[0];\n } catch {\n return '';\n }\n}\n\n/** Checks if a date is valid */\nfunction isValidDate(date: Date): boolean {\n return date instanceof Date && !Number.isNaN(date.getTime());\n}\n\n/** Generates holidays for a year */\nexport function resolveHolidays(\n definitions: HolidayDefinition[],\n year: number,\n names: Record<string, string> = {},\n): Holiday[] {\n if (typeof year !== 'number' || Number.isNaN(year)) {\n return [];\n }\n\n return definitions\n .map((def) => {\n const rawDate = resolveRule(def.rule, year);\n if (!rawDate || !isValidDate(rawDate)) return null;\n\n const { date, shifted } = applyShift(rawDate, def.shift ?? 'none');\n if (!isValidDate(date)) return null;\n\n return {\n date: toISODate(date),\n key: def.key,\n name: names[def.key] ?? def.key,\n ...(shifted && { isShifted: true }),\n };\n })\n .filter((h): h is Holiday => h !== null)\n .sort((a, b) => a.date.localeCompare(b.date));\n}\n\n/** Checks if a date is a holiday */\nexport function checkIsHoliday(\n definitions: HolidayDefinition[],\n date: Date,\n names?: Record<string, string>,\n): Holiday | null {\n if (!isValidDate(date)) return null;\n\n const year = date.getUTCFullYear();\n const isoDate = toISODate(date);\n if (!isoDate) return null;\n\n const holidays = resolveHolidays(definitions, year, names);\n return holidays.find((h) => h.date === isoDate) ?? null;\n}\n\n/** Gets the next holiday from a date */\nexport function findNextHoliday(\n definitions: HolidayDefinition[],\n from: Date,\n names?: Record<string, string>,\n): Holiday | null {\n if (!isValidDate(from)) return null;\n\n const isoFrom = toISODate(from);\n if (!isoFrom) return null;\n\n const year = from.getUTCFullYear();\n\n // Search in current year\n let holidays = resolveHolidays(definitions, year, names);\n let next = holidays.find((h) => h.date >= isoFrom);\n\n // If none, search in next year\n if (!next) {\n holidays = resolveHolidays(definitions, year + 1, names);\n next = holidays[0];\n }\n\n return next ?? null;\n}\n"]}
|
package/dist/core/engine.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function y(t){let n=t%19,o=Math.floor(t/100),e=t%100,a=Math.floor(o/4),s=o%4,i=Math.floor((o+8)/25),r=Math.floor((o-i+1)/3),l=(19*n+o-a-r+15)%30,C=Math.floor(e/4),U=e%4,c=(32+2*s+2*C-l-U)%7,d=Math.floor((n+11*l+22*c)/451),g=Math.floor((l+c-7*d+114)/31),m=(l+c-7*d+114)%31+1;return new Date(Date.UTC(t,g-1,m))}function h(t,n,o,e){if(e>0){let s=new Date(Date.UTC(t,n-1,1)).getUTCDay(),r=1+(o-s+7)%7+(e-1)*7;return new Date(Date.UTC(t,n-1,r))}else {let a=new Date(Date.UTC(t,n,0)),i=(a.getUTCDay()-o+7)%7,r=a.getUTCDate()-i+(e+1)*7;return new Date(Date.UTC(t,n-1,r))}}function T(t,n){let o=t.getUTCDay();if(n==="none")return {date:t,shifted:false};let e=new Date(t);switch(n){case "emiliani":case "nextMonday":{if(o===1)return {date:t,shifted:false};let a=(8-o)%7;e.setUTCDate(t.getUTCDate()+a);break}case "observedUS":if(o===0)e.setUTCDate(t.getUTCDate()+1);else if(o===6)e.setUTCDate(t.getUTCDate()-1);else return {date:t,shifted:false};break;case "nearestMonday":if(o===2)e.setUTCDate(t.getUTCDate()-1);else if(o===3)e.setUTCDate(t.getUTCDate()-2);else if(o===4)e.setUTCDate(t.getUTCDate()+4);else if(o===5)e.setUTCDate(t.getUTCDate()+3);else return {date:t,shifted:false};break;default:return {date:t,shifted:false}}return {date:e,shifted:true}}function p(t,n){switch(t.type){case "fixed":return new Date(Date.UTC(n,t.month-1,t.day));case "nthWeekday":return h(n,t.month,t.weekday,t.n);case "easterRelative":{let o=y(n),e=new Date(o);return e.setUTCDate(o.getUTCDate()+t.offset),e}case "custom":return t.calc(n)}}function D(t){try{return t.toISOString().split("T")[0]}catch{return ""}}function f(t){return t instanceof Date&&!Number.isNaN(t.getTime())}function u(t,n,o={}){return typeof n!="number"||Number.isNaN(n)?[]:t.map(e=>{let a=p(e.rule,n);if(!a||!f(a))return null;let{date:s,shifted:i}=T(a,e.shift??"none");return f(s)?{date:D(s),key:e.key,name:o[e.key]??e.key,...i&&{isShifted:true}}:null}).filter(e=>e!==null).sort((e,a)=>e.date.localeCompare(a.date))}function M(t,n,o){if(!f(n))return null;let e=n.getUTCFullYear(),a=D(n);return a?u(t,e,o).find(i=>i.date===a)??null:null}function N(t,n,o){if(!f(n))return null;let e=D(n);if(!e)return null;let a=n.getUTCFullYear(),s=u(t,a,o),i=s.find(r=>r.date>=e);return i||(s=u(t,a+1,o),i=s[0]),i??null}export{M as checkIsHoliday,N as findNextHoliday,u as resolveHolidays};//# sourceMappingURL=engine.js.map
|
|
2
2
|
//# sourceMappingURL=engine.js.map
|
package/dist/core/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/algorithms/easter.ts","../../src/core/algorithms/nth-weekday.ts","../../src/core/algorithms/shifts.ts","../../src/core/engine.ts"],"names":["getEasterSunday","year","a","b","c","d","e","f","g","h","i","k","l","m","month","day","getNthWeekday","weekday","n","firstWeekday","last","diff","applyShift","date","rule","result","daysToNextMonday","resolveRule","easter","toISODate","resolveHolidays","definitions","names","def","rawDate","shifted","checkIsHoliday","isoDate","findNextHoliday","from","isoFrom","holidays","next"],"mappings":"AAIO,SAASA,CAAAA,CAAgBC,CAAAA,CAAoB,CAClD,IAAMC,EAAID,CAAAA,CAAO,EAAA,CACXE,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAO,GAAG,CAAA,CACzBG,EAAIH,CAAAA,CAAO,GAAA,CACXI,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAI,CAAC,CAAA,CACpBG,EAAIH,CAAAA,CAAI,CAAA,CACRI,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAA,CAAOJ,CAAAA,CAAI,CAAA,EAAK,EAAE,EA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A,CAAE,KAAK,aAAA,CAAcC,CAAAA,CAAE,IAAI,CAAC,CAChD,CAGO,SAASiC,CAAAA,CACdL,CAAAA,CACAR,CAAAA,CACAS,CAAAA,CACgB,CAChB,IAAM/B,EAAOsB,CAAAA,CAAK,cAAA,EAAe,CAC3Bc,CAAAA,CAAUR,CAAAA,CAAUN,CAAI,CAAA,CAE9B,OADiBO,EAAgBC,CAAAA,CAAa9B,CAAAA,CAAM+B,CAAK,CAAA,CACzC,IAAA,CAAMvB,CAAAA,EAAMA,CAAAA,CAAE,IAAA,GAAS4B,CAAO,CAAA,EAAK,IACrD,CAGO,SAASC,CAAAA,CACdP,CAAAA,CACAQ,CAAAA,CACAP,CAAAA,CACgB,CAChB,IAAMQ,CAAAA,CAAUX,CAAAA,CAAUU,CAAI,CAAA,CACxBtC,CAAAA,CAAOsC,CAAAA,CAAK,cAAA,GAGdE,CAAAA,CAAWX,CAAAA,CAAgBC,CAAAA,CAAa9B,CAAAA,CAAM+B,CAAK,CAAA,CACnDU,CAAAA,CAAOD,CAAAA,CAAS,KAAMhC,CAAAA,EAAMA,CAAAA,CAAE,IAAA,EAAQ+B,CAAO,CAAA,CAGjD,OAAKE,CAAAA,GACHD,CAAAA,CAAWX,EAAgBC,CAAAA,CAAa9B,CAAAA,CAAO,CAAA,CAAG+B,CAAK,EACvDU,CAAAA,CAAOD,CAAAA,CAAS,CAAC,CAAA,CAAA,CAGZC,GAAQ,IACjB","file":"engine.js","sourcesContent":["/**\n * Calculates Easter Sunday (Meeus/Jones/Butcher algorithm)\n * Valid for Gregorian calendar (1583+)\n */\nexport function getEasterSunday(year: number): Date {\n const a = year % 19;\n const b = Math.floor(year / 100);\n const c = year % 100;\n const d = Math.floor(b / 4);\n const e = b % 4;\n const f = Math.floor((b + 8) / 25);\n const g = Math.floor((b - f + 1) / 3);\n const h = (19 * a + b - d - g + 15) % 30;\n const i = Math.floor(c / 4);\n const k = c % 4;\n const l = (32 + 2 * e + 2 * i - h - k) % 7;\n const m = Math.floor((a + 11 * h + 22 * l) / 451);\n const month = Math.floor((h + l - 7 * m + 114) / 31);\n const day = ((h + l - 7 * m + 114) % 31) + 1;\n\n return new Date(Date.UTC(year, month - 1, day));\n}\n","/**\n * Calculates the Nth weekday of a month\n * @param year - Year\n * @param month - Month (1-12)\n * @param weekday - Weekday (0=Sun, 1=Mon, ..., 6=Sat)\n * @param n - Occurrence (1=first, 2=second, -1=last)\n */\nexport function getNthWeekday(year: number, month: number, weekday: number, n: number): Date {\n if (n > 0) {\n // From start of month\n const first = new Date(Date.UTC(year, month - 1, 1));\n const firstWeekday = first.getUTCDay();\n const diff = (weekday - firstWeekday + 7) % 7;\n const day = 1 + diff + (n - 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n } else {\n // From end of month (n = -1 = last)\n // month is 1-12. Date.UTC(year, month, 0) gives the last day of month 'month'\n const last = new Date(Date.UTC(year, month, 0));\n const lastWeekday = last.getUTCDay();\n const diff = (lastWeekday - weekday + 7) % 7;\n const day = last.getUTCDate() - diff + (n + 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n }\n}\n","import type { ShiftRule } from '../types';\n\n/**\n * Applies a shift rule to a date\n * @returns { date: Date, shifted: boolean }\n */\nexport function applyShift(date: Date, rule: ShiftRule): { date: Date; shifted: boolean } {\n const day = date.getUTCDay(); // 0=Sun, 6=Sat\n\n if (rule === 'none') {\n return { date, shifted: false };\n }\n\n const result = new Date(date);\n\n switch (rule) {\n case 'emiliani':\n case 'nextMonday': {\n // If it's already Monday (1), do not move\n if (day === 1) {\n return { date, shifted: false };\n }\n // Move to next Monday\n // (8 - day) % 7 gives days until next Monday\n // Ex: Sun(0) -> (8-0)%7 = 1 (+1 day) -> Mon\n // Ex: Sat(6) -> (8-6)%7 = 2 (+2 days) -> Mon\n // Ex: Wed(3) -> (8-3)%7 = 5 (+5 days) -> Mon\n const daysToNextMonday = (8 - day) % 7;\n result.setUTCDate(date.getUTCDate() + daysToNextMonday);\n break;\n }\n\n case 'observedUS':\n // Only affects weekends\n if (day === 0) {\n // Sunday -> Monday (+1)\n result.setUTCDate(date.getUTCDate() + 1);\n } else if (day === 6) {\n // Saturday -> Friday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else {\n return { date, shifted: false };\n }\n break;\n\n case 'nearestMonday':\n // Argentina rule:\n // Tue/Wed -> Previous Monday\n // Thu/Fri -> Next Monday\n if (day === 2) {\n // Tuesday -> Monday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else if (day === 3) {\n // Wednesday -> Monday (-2)\n result.setUTCDate(date.getUTCDate() - 2);\n } else if (day === 4) {\n // Thursday -> Next Monday (+4)\n result.setUTCDate(date.getUTCDate() + 4);\n } else if (day === 5) {\n // Friday -> Next Monday (+3)\n result.setUTCDate(date.getUTCDate() + 3);\n } else {\n return { date, shifted: false };\n }\n break;\n\n default:\n return { date, shifted: false };\n }\n\n return { date: result, shifted: true };\n}\n","import type { HolidayDefinition, HolidayRule, Holiday } from './types';\nimport { getEasterSunday } from './algorithms/easter';\nimport { getNthWeekday } from './algorithms/nth-weekday';\nimport { applyShift } from './algorithms/shifts';\n\n/** Resolves a rule to a concrete date */\nfunction resolveRule(rule: HolidayRule, year: number): Date | null {\n switch (rule.type) {\n case 'fixed':\n return new Date(Date.UTC(year, rule.month - 1, rule.day));\n\n case 'nthWeekday':\n return getNthWeekday(year, rule.month, rule.weekday, rule.n);\n\n case 'easterRelative': {\n const easter = getEasterSunday(year);\n const result = new Date(easter);\n result.setUTCDate(easter.getUTCDate() + rule.offset);\n return result;\n }\n\n case 'custom':\n return rule.calc(year);\n }\n}\n\n/** Formats Date to ISO string (date only) */\nfunction toISODate(date: Date): string {\n return date.toISOString().split('T')[0];\n}\n\n/** Generates holidays for a year */\nexport function resolveHolidays(\n definitions: HolidayDefinition[],\n year: number,\n names: Record<string, string> = {},\n): Holiday[] {\n return definitions\n .map((def) => {\n const rawDate = resolveRule(def.rule, year);\n if (!rawDate) return null;\n\n const { date, shifted } = applyShift(rawDate, def.shift ?? 'none');\n\n return {\n date: toISODate(date),\n key: def.key,\n name: names[def.key] ?? def.key,\n ...(shifted && { isShifted: true }),\n };\n })\n .filter((h): h is Holiday => h !== null)\n .sort((a, b) => a.date.localeCompare(b.date));\n}\n\n/** Checks if a date is a holiday */\nexport function checkIsHoliday(\n definitions: HolidayDefinition[],\n date: Date,\n names?: Record<string, string>,\n): Holiday | null {\n const year = date.getUTCFullYear();\n const isoDate = toISODate(date);\n const holidays = resolveHolidays(definitions, year, names);\n return holidays.find((h) => h.date === isoDate) ?? null;\n}\n\n/** Gets the next holiday from a date */\nexport function findNextHoliday(\n definitions: HolidayDefinition[],\n from: Date,\n names?: Record<string, string>,\n): Holiday | null {\n const isoFrom = toISODate(from);\n const year = from.getUTCFullYear();\n\n // Search in current year\n let holidays = resolveHolidays(definitions, year, names);\n let next = holidays.find((h) => h.date >= isoFrom);\n\n // If none, search in next year\n if (!next) {\n holidays = resolveHolidays(definitions, year + 1, names);\n next = holidays[0];\n }\n\n return next ?? null;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/algorithms/easter.ts","../../src/core/algorithms/nth-weekday.ts","../../src/core/algorithms/shifts.ts","../../src/core/engine.ts"],"names":["getEasterSunday","year","a","b","c","d","e","f","g","h","i","k","l","m","month","day","getNthWeekday","weekday","n","firstWeekday","last","diff","applyShift","date","rule","result","daysToNextMonday","resolveRule","easter","toISODate","isValidDate","resolveHolidays","definitions","names","def","rawDate","shifted","checkIsHoliday","isoDate","findNextHoliday","from","isoFrom","holidays","next"],"mappings":"AAIO,SAASA,EAAgBC,CAAAA,CAAoB,CAClD,IAAMC,CAAAA,CAAID,EAAO,EAAA,CACXE,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,EAAO,GAAG,CAAA,CACzBG,CAAAA,CAAIH,CAAAA,CAAO,IACXI,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAI,CAAC,CAAA,CACpBG,CAAAA,CAAIH,CA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AAA,CAAOD,EAAS,CAAC,CAAA,CAAA,CAGZC,GAAQ,IACjB","file":"engine.js","sourcesContent":["/**\n * Calculates Easter Sunday (Meeus/Jones/Butcher algorithm)\n * Valid for Gregorian calendar (1583+)\n */\nexport function getEasterSunday(year: number): Date {\n const a = year % 19;\n const b = Math.floor(year / 100);\n const c = year % 100;\n const d = Math.floor(b / 4);\n const e = b % 4;\n const f = Math.floor((b + 8) / 25);\n const g = Math.floor((b - f + 1) / 3);\n const h = (19 * a + b - d - g + 15) % 30;\n const i = Math.floor(c / 4);\n const k = c % 4;\n const l = (32 + 2 * e + 2 * i - h - k) % 7;\n const m = Math.floor((a + 11 * h + 22 * l) / 451);\n const month = Math.floor((h + l - 7 * m + 114) / 31);\n const day = ((h + l - 7 * m + 114) % 31) + 1;\n\n return new Date(Date.UTC(year, month - 1, day));\n}\n","/**\n * Calculates the Nth weekday of a month\n * @param year - Year\n * @param month - Month (1-12)\n * @param weekday - Weekday (0=Sun, 1=Mon, ..., 6=Sat)\n * @param n - Occurrence (1=first, 2=second, -1=last)\n */\nexport function getNthWeekday(year: number, month: number, weekday: number, n: number): Date {\n if (n > 0) {\n // From start of month\n const first = new Date(Date.UTC(year, month - 1, 1));\n const firstWeekday = first.getUTCDay();\n const diff = (weekday - firstWeekday + 7) % 7;\n const day = 1 + diff + (n - 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n } else {\n // From end of month (n = -1 = last)\n // month is 1-12. Date.UTC(year, month, 0) gives the last day of month 'month'\n const last = new Date(Date.UTC(year, month, 0));\n const lastWeekday = last.getUTCDay();\n const diff = (lastWeekday - weekday + 7) % 7;\n const day = last.getUTCDate() - diff + (n + 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n }\n}\n","import type { ShiftRule } from '../types';\n\n/**\n * Applies a shift rule to a date\n * @returns { date: Date, shifted: boolean }\n */\nexport function applyShift(date: Date, rule: ShiftRule): { date: Date; shifted: boolean } {\n const day = date.getUTCDay(); // 0=Sun, 6=Sat\n\n if (rule === 'none') {\n return { date, shifted: false };\n }\n\n const result = new Date(date);\n\n switch (rule) {\n case 'emiliani':\n case 'nextMonday': {\n // If it's already Monday (1), do not move\n if (day === 1) {\n return { date, shifted: false };\n }\n // Move to next Monday\n // (8 - day) % 7 gives days until next Monday\n // Ex: Sun(0) -> (8-0)%7 = 1 (+1 day) -> Mon\n // Ex: Sat(6) -> (8-6)%7 = 2 (+2 days) -> Mon\n // Ex: Wed(3) -> (8-3)%7 = 5 (+5 days) -> Mon\n const daysToNextMonday = (8 - day) % 7;\n result.setUTCDate(date.getUTCDate() + daysToNextMonday);\n break;\n }\n\n case 'observedUS':\n // Only affects weekends\n if (day === 0) {\n // Sunday -> Monday (+1)\n result.setUTCDate(date.getUTCDate() + 1);\n } else if (day === 6) {\n // Saturday -> Friday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else {\n return { date, shifted: false };\n }\n break;\n\n case 'nearestMonday':\n // Argentina rule:\n // Tue/Wed -> Previous Monday\n // Thu/Fri -> Next Monday\n if (day === 2) {\n // Tuesday -> Monday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else if (day === 3) {\n // Wednesday -> Monday (-2)\n result.setUTCDate(date.getUTCDate() - 2);\n } else if (day === 4) {\n // Thursday -> Next Monday (+4)\n result.setUTCDate(date.getUTCDate() + 4);\n } else if (day === 5) {\n // Friday -> Next Monday (+3)\n result.setUTCDate(date.getUTCDate() + 3);\n } else {\n return { date, shifted: false };\n }\n break;\n\n default:\n return { date, shifted: false };\n }\n\n return { date: result, shifted: true };\n}\n","import type { HolidayDefinition, HolidayRule, Holiday } from './types';\nimport { getEasterSunday } from './algorithms/easter';\nimport { getNthWeekday } from './algorithms/nth-weekday';\nimport { applyShift } from './algorithms/shifts';\n\n/** Resolves a rule to a concrete date */\nfunction resolveRule(rule: HolidayRule, year: number): Date | null {\n switch (rule.type) {\n case 'fixed':\n return new Date(Date.UTC(year, rule.month - 1, rule.day));\n\n case 'nthWeekday':\n return getNthWeekday(year, rule.month, rule.weekday, rule.n);\n\n case 'easterRelative': {\n const easter = getEasterSunday(year);\n const result = new Date(easter);\n result.setUTCDate(easter.getUTCDate() + rule.offset);\n return result;\n }\n\n case 'custom':\n return rule.calc(year);\n }\n}\n\n/** Formats Date to ISO string (date only) */\nfunction toISODate(date: Date): string {\n try {\n return date.toISOString().split('T')[0];\n } catch {\n return '';\n }\n}\n\n/** Checks if a date is valid */\nfunction isValidDate(date: Date): boolean {\n return date instanceof Date && !Number.isNaN(date.getTime());\n}\n\n/** Generates holidays for a year */\nexport function resolveHolidays(\n definitions: HolidayDefinition[],\n year: number,\n names: Record<string, string> = {},\n): Holiday[] {\n if (typeof year !== 'number' || Number.isNaN(year)) {\n return [];\n }\n\n return definitions\n .map((def) => {\n const rawDate = resolveRule(def.rule, year);\n if (!rawDate || !isValidDate(rawDate)) return null;\n\n const { date, shifted } = applyShift(rawDate, def.shift ?? 'none');\n if (!isValidDate(date)) return null;\n\n return {\n date: toISODate(date),\n key: def.key,\n name: names[def.key] ?? def.key,\n ...(shifted && { isShifted: true }),\n };\n })\n .filter((h): h is Holiday => h !== null)\n .sort((a, b) => a.date.localeCompare(b.date));\n}\n\n/** Checks if a date is a holiday */\nexport function checkIsHoliday(\n definitions: HolidayDefinition[],\n date: Date,\n names?: Record<string, string>,\n): Holiday | null {\n if (!isValidDate(date)) return null;\n\n const year = date.getUTCFullYear();\n const isoDate = toISODate(date);\n if (!isoDate) return null;\n\n const holidays = resolveHolidays(definitions, year, names);\n return holidays.find((h) => h.date === isoDate) ?? null;\n}\n\n/** Gets the next holiday from a date */\nexport function findNextHoliday(\n definitions: HolidayDefinition[],\n from: Date,\n names?: Record<string, string>,\n): Holiday | null {\n if (!isValidDate(from)) return null;\n\n const isoFrom = toISODate(from);\n if (!isoFrom) return null;\n\n const year = from.getUTCFullYear();\n\n // Search in current year\n let holidays = resolveHolidays(definitions, year, names);\n let next = holidays.find((h) => h.date >= isoFrom);\n\n // If none, search in next year\n if (!next) {\n holidays = resolveHolidays(definitions, year + 1, names);\n next = holidays[0];\n }\n\n return next ?? null;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';function
|
|
1
|
+
'use strict';function m(e){let n=e%19,o=Math.floor(e/100),t=e%100,i=Math.floor(o/4),s=o%4,a=Math.floor((o+8)/25),r=Math.floor((o-a+1)/3),l=(19*n+o-i-r+15)%30,y=Math.floor(t/4),c=t%4,u=(32+2*s+2*y-l-c)%7,f=Math.floor((n+11*l+22*u)/451),H=Math.floor((l+u-7*f+114)/31),w=(l+u-7*f+114)%31+1;return new Date(Date.UTC(e,H-1,w))}function T(e,n,o,t){if(t>0){let s=new Date(Date.UTC(e,n-1,1)).getUTCDay(),r=1+(o-s+7)%7+(t-1)*7;return new Date(Date.UTC(e,n-1,r))}else {let i=new Date(Date.UTC(e,n,0)),a=(i.getUTCDay()-o+7)%7,r=i.getUTCDate()-a+(t+1)*7;return new Date(Date.UTC(e,n-1,r))}}function h(e,n){let o=e.getUTCDay();if(n==="none")return {date:e,shifted:false};let t=new Date(e);switch(n){case "emiliani":case "nextMonday":{if(o===1)return {date:e,shifted:false};let i=(8-o)%7;t.setUTCDate(e.getUTCDate()+i);break}case "observedUS":if(o===0)t.setUTCDate(e.getUTCDate()+1);else if(o===6)t.setUTCDate(e.getUTCDate()-1);else return {date:e,shifted:false};break;case "nearestMonday":if(o===2)t.setUTCDate(e.getUTCDate()-1);else if(o===3)t.setUTCDate(e.getUTCDate()-2);else if(o===4)t.setUTCDate(e.getUTCDate()+4);else if(o===5)t.setUTCDate(e.getUTCDate()+3);else return {date:e,shifted:false};break;default:return {date:e,shifted:false}}return {date:t,shifted:true}}function x(e,n){switch(e.type){case "fixed":return new Date(Date.UTC(n,e.month-1,e.day));case "nthWeekday":return T(n,e.month,e.weekday,e.n);case "easterRelative":{let o=m(n),t=new Date(o);return t.setUTCDate(o.getUTCDate()+e.offset),t}case "custom":return e.calc(n)}}function g(e){try{return e.toISOString().split("T")[0]}catch{return ""}}function D(e){return e instanceof Date&&!Number.isNaN(e.getTime())}function d(e,n,o={}){return typeof n!="number"||Number.isNaN(n)?[]:e.map(t=>{let i=x(t.rule,n);if(!i||!D(i))return null;let{date:s,shifted:a}=h(i,t.shift??"none");return D(s)?{date:g(s),key:t.key,name:o[t.key]??t.key,...a&&{isShifted:true}}:null}).filter(t=>t!==null).sort((t,i)=>t.date.localeCompare(i.date))}function p(e,n,o){if(!D(n))return null;let t=n.getUTCFullYear(),i=g(n);return i?d(e,t,o).find(a=>a.date===i)??null:null}function k(e,n,o){if(!D(n))return null;let t=g(n);if(!t)return null;let i=n.getUTCFullYear(),s=d(e,i,o),a=s.find(r=>r.date>=t);return a||(s=d(e,i+1,o),a=s[0]),a??null}function C(e){let n=e.getUTCDay();return n===0||n===6}function U(e,n){return C(n)?false:p(e,n)===null}function R(e,n,o){let t=new Date(n),i=Math.abs(o),s=o>=0?1:-1;for(;i>0;)t.setUTCDate(t.getUTCDate()+s),U(e,t)&&i--;return t}function M(e,n,o){let t=new Date(n),i=new Date(o);if(t.setUTCHours(0,0,0,0),i.setUTCHours(0,0,0,0),t.getTime()===i.getTime())return 0;let s=t<i?1:-1,a=0,r=new Date(t);for(;r.getTime()!==i.getTime();)r.setUTCDate(r.getUTCDate()+s),U(e,r)&&(a+=s);return a}function b(e){return e instanceof Date&&Number.isFinite(e.getTime())}function S(e,n={}){let{locale:o="en",baseDate:t=new Date,numeric:i="always",style:s="long"}=n;if(!b(e)||!b(t))return "";let a=e.getTime()-t.getTime(),r=Math.round(a/1e3),l=new Intl.RelativeTimeFormat(o,{numeric:i,style:s}),y=[{unit:"year",seconds:3600*24*365},{unit:"month",seconds:3600*24*30},{unit:"week",seconds:3600*24*7},{unit:"day",seconds:3600*24},{unit:"hour",seconds:3600},{unit:"minute",seconds:60},{unit:"second",seconds:1}];for(let{unit:c,seconds:u}of y)if(Math.abs(r)>=u||c==="second"){let f=Math.round(r/u);return l.format(f,c)}return ""}exports.addBusinessDays=R;exports.applyShift=h;exports.checkIsBusinessDay=U;exports.checkIsHoliday=p;exports.findNextHoliday=k;exports.formatRelativeTime=S;exports.getBusinessDaysBetween=M;exports.getEasterSunday=m;exports.getNthWeekday=T;exports.isWeekend=C;exports.resolveHolidays=d;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/algorithms/easter.ts","../src/core/algorithms/nth-weekday.ts","../src/core/algorithms/shifts.ts","../src/core/engine.ts","../src/core/business.ts"],"names":["getEasterSunday","year","a","b","c","d","e","f","g","h","i","k","l","m","month","day","getNthWeekday","weekday","n","firstWeekday","last","diff","applyShift","date","rule","result","daysToNextMonday","resolveRule","easter","toISODate","resolveHolidays","definitions","names","def","rawDate","shifted","checkIsHoliday","isoDate","findNextHoliday","from","isoFrom","holidays","next","isWeekend","checkIsBusinessDay","addBusinessDays","startDate","amount","remaining","direction","getBusinessDaysBetween","endDate","start","end","count","current"],"mappings":"aAIO,SAASA,EAAgBC,CAAAA,CAAoB,CAClD,IAAMC,CAAAA,CAAID,CAAAA,CAAO,GACXE,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAO,GAAG,CAAA,CACzBG,CAAAA,CAAIH,EAAO,GAAA,CACXI,CAAAA,CAAI,KAAK,KAAA,CAAMF,CAAAA,CAAI,CAAC,CAAA,CACpBG,EAAIH,CAAAA,CAAI,CAAA,CACRI,EAAI,IAAA,CAAK,KAAA,CAAA,CAAOJ,EAAI,CAAA,EAAK,EAAE,EAC3BK,CAAAA,CAAI,IAAA,CAAK,OAAOL,CAAAA,CAAII,CAAAA,CAAI,GAAK,CAAC,CAAA,CAC9BE,GAAK,EAAA,CAAKP,CAAAA,CAAIC,CAAAA,CAAIE,CAAAA,CAAIG,EAAI,EAAA,EAAM,EAAA,CAChCE,EAAI,IAAA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,EAAQ,CAAG,OAAO,CAAA,CAE9C,IAAMJ,EAAYG,CAAAA,CAAQC,CAAAA,CAAM,EAAI,EAAA,CAChCC,CAAAA,CAAQ,EACNC,CAAAA,CAAU,IAAI,KAAKH,CAAK,CAAA,CAK9B,KAAOG,CAAAA,CAAQ,SAAQ,GAAMF,CAAAA,CAAI,SAAQ,EACvCE,CAAAA,CAAQ,WAAWA,CAAAA,CAAQ,UAAA,GAAeN,CAAS,CAAA,CAC/CL,EAAmBb,CAAAA,CAAawB,CAAO,IACzCD,CAAAA,EAASL,CAAAA,CAAAA,CAIb,OAAOK,CACT","file":"index.cjs","sourcesContent":["/**\n * Calculates Easter Sunday (Meeus/Jones/Butcher algorithm)\n * Valid for Gregorian calendar (1583+)\n */\nexport function getEasterSunday(year: number): Date {\n const a = year % 19;\n const b = Math.floor(year / 100);\n const c = year % 100;\n const d = Math.floor(b / 4);\n const e = b % 4;\n const f = Math.floor((b + 8) / 25);\n const g = Math.floor((b - f + 1) / 3);\n const h = (19 * a + b - d - g + 15) % 30;\n const i = Math.floor(c / 4);\n const k = c % 4;\n const l = (32 + 2 * e + 2 * i - h - k) % 7;\n const m = Math.floor((a + 11 * h + 22 * l) / 451);\n const month = Math.floor((h + l - 7 * m + 114) / 31);\n const day = ((h + l - 7 * m + 114) % 31) + 1;\n\n return new Date(Date.UTC(year, month - 1, day));\n}\n","/**\n * Calculates the Nth weekday of a month\n * @param year - Year\n * @param month - Month (1-12)\n * @param weekday - Weekday (0=Sun, 1=Mon, ..., 6=Sat)\n * @param n - Occurrence (1=first, 2=second, -1=last)\n */\nexport function getNthWeekday(year: number, month: number, weekday: number, n: number): Date {\n if (n > 0) {\n // From start of month\n const first = new Date(Date.UTC(year, month - 1, 1));\n const firstWeekday = first.getUTCDay();\n const diff = (weekday - firstWeekday + 7) % 7;\n const day = 1 + diff + (n - 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n } else {\n // From end of month (n = -1 = last)\n // month is 1-12. Date.UTC(year, month, 0) gives the last day of month 'month'\n const last = new Date(Date.UTC(year, month, 0));\n const lastWeekday = last.getUTCDay();\n const diff = (lastWeekday - weekday + 7) % 7;\n const day = last.getUTCDate() - diff + (n + 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n }\n}\n","import type { ShiftRule } from '../types';\n\n/**\n * Applies a shift rule to a date\n * @returns { date: Date, shifted: boolean }\n */\nexport function applyShift(date: Date, rule: ShiftRule): { date: Date; shifted: boolean } {\n const day = date.getUTCDay(); // 0=Sun, 6=Sat\n\n if (rule === 'none') {\n return { date, shifted: false };\n }\n\n const result = new Date(date);\n\n switch (rule) {\n case 'emiliani':\n case 'nextMonday': {\n // If it's already Monday (1), do not move\n if (day === 1) {\n return { date, shifted: false };\n }\n // Move to next Monday\n // (8 - day) % 7 gives days until next Monday\n // Ex: Sun(0) -> (8-0)%7 = 1 (+1 day) -> Mon\n // Ex: Sat(6) -> (8-6)%7 = 2 (+2 days) -> Mon\n // Ex: Wed(3) -> (8-3)%7 = 5 (+5 days) -> Mon\n const daysToNextMonday = (8 - day) % 7;\n result.setUTCDate(date.getUTCDate() + daysToNextMonday);\n break;\n }\n\n case 'observedUS':\n // Only affects weekends\n if (day === 0) {\n // Sunday -> Monday (+1)\n result.setUTCDate(date.getUTCDate() + 1);\n } else if (day === 6) {\n // Saturday -> Friday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else {\n return { date, shifted: false };\n }\n break;\n\n case 'nearestMonday':\n // Argentina rule:\n // Tue/Wed -> Previous Monday\n // Thu/Fri -> Next Monday\n if (day === 2) {\n // Tuesday -> Monday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else if (day === 3) {\n // Wednesday -> Monday (-2)\n result.setUTCDate(date.getUTCDate() - 2);\n } else if (day === 4) {\n // Thursday -> Next Monday (+4)\n result.setUTCDate(date.getUTCDate() + 4);\n } else if (day === 5) {\n // Friday -> Next Monday (+3)\n result.setUTCDate(date.getUTCDate() + 3);\n } else {\n return { date, shifted: false };\n }\n break;\n\n default:\n return { date, shifted: false };\n }\n\n return { date: result, shifted: true };\n}\n","import type { HolidayDefinition, HolidayRule, Holiday } from './types';\nimport { getEasterSunday } from './algorithms/easter';\nimport { getNthWeekday } from './algorithms/nth-weekday';\nimport { applyShift } from './algorithms/shifts';\n\n/** Resolves a rule to a concrete date */\nfunction resolveRule(rule: HolidayRule, year: number): Date | null {\n switch (rule.type) {\n case 'fixed':\n return new Date(Date.UTC(year, rule.month - 1, rule.day));\n\n case 'nthWeekday':\n return getNthWeekday(year, rule.month, rule.weekday, rule.n);\n\n case 'easterRelative': {\n const easter = getEasterSunday(year);\n const result = new Date(easter);\n result.setUTCDate(easter.getUTCDate() + rule.offset);\n return result;\n }\n\n case 'custom':\n return rule.calc(year);\n }\n}\n\n/** Formats Date to ISO string (date only) */\nfunction toISODate(date: Date): string {\n return date.toISOString().split('T')[0];\n}\n\n/** Generates holidays for a year */\nexport function resolveHolidays(\n definitions: HolidayDefinition[],\n year: number,\n names: Record<string, string> = {},\n): Holiday[] {\n return definitions\n .map((def) => {\n const rawDate = resolveRule(def.rule, year);\n if (!rawDate) return null;\n\n const { date, shifted } = applyShift(rawDate, def.shift ?? 'none');\n\n return {\n date: toISODate(date),\n key: def.key,\n name: names[def.key] ?? def.key,\n ...(shifted && { isShifted: true }),\n };\n })\n .filter((h): h is Holiday => h !== null)\n .sort((a, b) => a.date.localeCompare(b.date));\n}\n\n/** Checks if a date is a holiday */\nexport function checkIsHoliday(\n definitions: HolidayDefinition[],\n date: Date,\n names?: Record<string, string>,\n): Holiday | null {\n const year = date.getUTCFullYear();\n const isoDate = toISODate(date);\n const holidays = resolveHolidays(definitions, year, names);\n return holidays.find((h) => h.date === isoDate) ?? null;\n}\n\n/** Gets the next holiday from a date */\nexport function findNextHoliday(\n definitions: HolidayDefinition[],\n from: Date,\n names?: Record<string, string>,\n): Holiday | null {\n const isoFrom = toISODate(from);\n const year = from.getUTCFullYear();\n\n // Search in current year\n let holidays = resolveHolidays(definitions, year, names);\n let next = holidays.find((h) => h.date >= isoFrom);\n\n // If none, search in next year\n if (!next) {\n holidays = resolveHolidays(definitions, year + 1, names);\n next = holidays[0];\n }\n\n return next ?? null;\n}\n","import type { HolidayDefinition } from './types';\nimport { checkIsHoliday } from './engine';\n\n/**\n * Checks if a date is a weekend (Saturday or Sunday)\n * Uses UTC date to avoid timezone issues\n */\nexport function isWeekend(date: Date): boolean {\n const day = date.getUTCDay();\n return day === 0 || day === 6; // 0 = Sunday, 6 = Saturday\n}\n\n/**\n * Checks if a date is a business day (not weekend AND not holiday)\n */\nexport function checkIsBusinessDay(definitions: HolidayDefinition[], date: Date): boolean {\n if (isWeekend(date)) return false;\n return checkIsHoliday(definitions, date) === null;\n}\n\n/**\n * Adds (or subtracts) business days to a date\n */\nexport function addBusinessDays(\n definitions: HolidayDefinition[],\n startDate: Date,\n amount: number,\n): Date {\n const result = new Date(startDate);\n let remaining = Math.abs(amount);\n const direction = amount >= 0 ? 1 : -1;\n\n while (remaining > 0) {\n result.setUTCDate(result.getUTCDate() + direction);\n if (checkIsBusinessDay(definitions, result)) {\n remaining--;\n }\n }\n\n return result;\n}\n\n/**\n * Calculates the number of business days between two dates\n * Returns the number of days to add to startDate to get endDate (can be negative)\n * If startDate and endDate are the same, returns 0\n */\nexport function getBusinessDaysBetween(\n definitions: HolidayDefinition[],\n startDate: Date,\n endDate: Date,\n): number {\n const start = new Date(startDate);\n const end = new Date(endDate);\n\n // Reset hours to avoid issues with daylight saving time or partial days\n start.setUTCHours(0, 0, 0, 0);\n end.setUTCHours(0, 0, 0, 0);\n\n if (start.getTime() === end.getTime()) return 0;\n\n const direction = start < end ? 1 : -1;\n let count = 0;\n const current = new Date(start);\n\n // If direction is positive, we count days starting from start+1 until end\n // If direction is negative, we count days starting from start-1 until end\n\n while (current.getTime() !== end.getTime()) {\n current.setUTCDate(current.getUTCDate() + direction);\n if (checkIsBusinessDay(definitions, current)) {\n count += direction;\n }\n }\n\n return count;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/algorithms/easter.ts","../src/core/algorithms/nth-weekday.ts","../src/core/algorithms/shifts.ts","../src/core/engine.ts","../src/core/business.ts","../src/core/relative-time.ts"],"names":["getEasterSunday","year","a","b","c","d","e","f","g","h","i","k","l","m","month","day","getNthWeekday","weekday","n","firstWeekday","last","diff","applyShift","date","rule","result","daysToNextMonday","resolveRule","easter","toISODate","isValidDate","resolveHolidays","definitions","names","def","rawDate","shifted","checkIsHoliday","isoDate","findNextHoliday","from","isoFrom","holidays","next","isWeekend","checkIsBusinessDay","addBusinessDays","startDate","amount","remaining","direction","getBusinessDaysBetween","endDate","start","end","count","current","isFiniteDate","formatRelativeTime","options","locale","baseDate","numeric","style","diffMs","diffSecs","formatter","units","unit","seconds","value"],"mappings":"aAIO,SAASA,CAAAA,CAAgBC,CAAAA,CAAoB,CAClD,IAAMC,CAAAA,CAAID,EAAO,EAAA,CACXE,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAO,GAAG,EACzBG,CAAAA,CAAIH,CAAAA,CAAO,GAAA,CACXI,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMF,CAAAA,CAAI,CAAC,CAAA,CACpBG,CAAAA,CAAIH,CAAAA,CAAI,CAAA,CACRI,CAAAA,CAAI,IAAA,CAAK,OAAOJ,CAAAA,CAAI,CAAA,EAAK,EAAE,CAAA,CAC3BK,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAA,CAAOL,CAAAA,CAAII,CAAAA,CAAI,CAAA,EAAK,CAAC,CAAA,CAC9BE,CAAAA,CAAAA,CAAK,EAAA,CAAKP,EAAIC,CAAAA,CAAIE,CAAAA,CAAIG,CAAAA,CAAI,EAAA,EAAM,EAAA,CAChCE,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMN,CAAAA,CAAI,CAAC,CAAA,CACpBO,CAAAA,CAAIP,CAAAA,CAAI,CAAA,CACRQ,GAAK,EAAA,CAAK,CAAA,CAAIN,CAAAA,CA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AAK,EAAG,CAAA,CAC5C,CAAE,IAAA,CAAM,MAAA,CAAQ,OAAA,CAAS,IAAA,CAAU,EAAA,CAAK,CAAE,CAAA,CAC1C,CAAE,IAAA,CAAM,KAAA,CAAO,OAAA,CAAS,IAAA,CAAU,EAAG,CAAA,CACrC,CAAE,IAAA,CAAM,MAAA,CAAQ,OAAA,CAAS,IAAQ,CAAA,CACjC,CAAE,IAAA,CAAM,SAAU,OAAA,CAAS,EAAG,CAAA,CAC9B,CAAE,IAAA,CAAM,QAAA,CAAU,OAAA,CAAS,CAAE,CAC/B,CAAA,CAEA,IAAA,GAAW,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAAC,CAAQ,CAAA,GAAKF,CAAAA,CAC9B,GAAI,IAAA,CAAK,GAAA,CAAIF,CAAQ,CAAA,EAAKI,CAAAA,EAAWD,CAAAA,GAAS,QAAA,CAAU,CACtD,IAAME,CAAAA,CAAQ,KAAK,KAAA,CAAML,CAAAA,CAAWI,CAAO,CAAA,CAC3C,OAAOH,CAAAA,CAAU,MAAA,CAAOI,CAAAA,CAAOF,CAAI,CACrC,CAGF,OAAO,EACT","file":"index.cjs","sourcesContent":["/**\n * Calculates Easter Sunday (Meeus/Jones/Butcher algorithm)\n * Valid for Gregorian calendar (1583+)\n */\nexport function getEasterSunday(year: number): Date {\n const a = year % 19;\n const b = Math.floor(year / 100);\n const c = year % 100;\n const d = Math.floor(b / 4);\n const e = b % 4;\n const f = Math.floor((b + 8) / 25);\n const g = Math.floor((b - f + 1) / 3);\n const h = (19 * a + b - d - g + 15) % 30;\n const i = Math.floor(c / 4);\n const k = c % 4;\n const l = (32 + 2 * e + 2 * i - h - k) % 7;\n const m = Math.floor((a + 11 * h + 22 * l) / 451);\n const month = Math.floor((h + l - 7 * m + 114) / 31);\n const day = ((h + l - 7 * m + 114) % 31) + 1;\n\n return new Date(Date.UTC(year, month - 1, day));\n}\n","/**\n * Calculates the Nth weekday of a month\n * @param year - Year\n * @param month - Month (1-12)\n * @param weekday - Weekday (0=Sun, 1=Mon, ..., 6=Sat)\n * @param n - Occurrence (1=first, 2=second, -1=last)\n */\nexport function getNthWeekday(year: number, month: number, weekday: number, n: number): Date {\n if (n > 0) {\n // From start of month\n const first = new Date(Date.UTC(year, month - 1, 1));\n const firstWeekday = first.getUTCDay();\n const diff = (weekday - firstWeekday + 7) % 7;\n const day = 1 + diff + (n - 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n } else {\n // From end of month (n = -1 = last)\n // month is 1-12. Date.UTC(year, month, 0) gives the last day of month 'month'\n const last = new Date(Date.UTC(year, month, 0));\n const lastWeekday = last.getUTCDay();\n const diff = (lastWeekday - weekday + 7) % 7;\n const day = last.getUTCDate() - diff + (n + 1) * 7;\n return new Date(Date.UTC(year, month - 1, day));\n }\n}\n","import type { ShiftRule } from '../types';\n\n/**\n * Applies a shift rule to a date\n * @returns { date: Date, shifted: boolean }\n */\nexport function applyShift(date: Date, rule: ShiftRule): { date: Date; shifted: boolean } {\n const day = date.getUTCDay(); // 0=Sun, 6=Sat\n\n if (rule === 'none') {\n return { date, shifted: false };\n }\n\n const result = new Date(date);\n\n switch (rule) {\n case 'emiliani':\n case 'nextMonday': {\n // If it's already Monday (1), do not move\n if (day === 1) {\n return { date, shifted: false };\n }\n // Move to next Monday\n // (8 - day) % 7 gives days until next Monday\n // Ex: Sun(0) -> (8-0)%7 = 1 (+1 day) -> Mon\n // Ex: Sat(6) -> (8-6)%7 = 2 (+2 days) -> Mon\n // Ex: Wed(3) -> (8-3)%7 = 5 (+5 days) -> Mon\n const daysToNextMonday = (8 - day) % 7;\n result.setUTCDate(date.getUTCDate() + daysToNextMonday);\n break;\n }\n\n case 'observedUS':\n // Only affects weekends\n if (day === 0) {\n // Sunday -> Monday (+1)\n result.setUTCDate(date.getUTCDate() + 1);\n } else if (day === 6) {\n // Saturday -> Friday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else {\n return { date, shifted: false };\n }\n break;\n\n case 'nearestMonday':\n // Argentina rule:\n // Tue/Wed -> Previous Monday\n // Thu/Fri -> Next Monday\n if (day === 2) {\n // Tuesday -> Monday (-1)\n result.setUTCDate(date.getUTCDate() - 1);\n } else if (day === 3) {\n // Wednesday -> Monday (-2)\n result.setUTCDate(date.getUTCDate() - 2);\n } else if (day === 4) {\n // Thursday -> Next Monday (+4)\n result.setUTCDate(date.getUTCDate() + 4);\n } else if (day === 5) {\n // Friday -> Next Monday (+3)\n result.setUTCDate(date.getUTCDate() + 3);\n } else {\n return { date, shifted: false };\n }\n break;\n\n default:\n return { date, shifted: false };\n }\n\n return { date: result, shifted: true };\n}\n","import type { HolidayDefinition, HolidayRule, Holiday } from './types';\nimport { getEasterSunday } from './algorithms/easter';\nimport { getNthWeekday } from './algorithms/nth-weekday';\nimport { applyShift } from './algorithms/shifts';\n\n/** Resolves a rule to a concrete date */\nfunction resolveRule(rule: HolidayRule, year: number): Date | null {\n switch (rule.type) {\n case 'fixed':\n return new Date(Date.UTC(year, rule.month - 1, rule.day));\n\n case 'nthWeekday':\n return getNthWeekday(year, rule.month, rule.weekday, rule.n);\n\n case 'easterRelative': {\n const easter = getEasterSunday(year);\n const result = new Date(easter);\n result.setUTCDate(easter.getUTCDate() + rule.offset);\n return result;\n }\n\n case 'custom':\n return rule.calc(year);\n }\n}\n\n/** Formats Date to ISO string (date only) */\nfunction toISODate(date: Date): string {\n try {\n return date.toISOString().split('T')[0];\n } catch {\n return '';\n }\n}\n\n/** Checks if a date is valid */\nfunction isValidDate(date: Date): boolean {\n return date instanceof Date && !Number.isNaN(date.getTime());\n}\n\n/** Generates holidays for a year */\nexport function resolveHolidays(\n definitions: HolidayDefinition[],\n year: number,\n names: Record<string, string> = {},\n): Holiday[] {\n if (typeof year !== 'number' || Number.isNaN(year)) {\n return [];\n }\n\n return definitions\n .map((def) => {\n const rawDate = resolveRule(def.rule, year);\n if (!rawDate || !isValidDate(rawDate)) return null;\n\n const { date, shifted } = applyShift(rawDate, def.shift ?? 'none');\n if (!isValidDate(date)) return null;\n\n return {\n date: toISODate(date),\n key: def.key,\n name: names[def.key] ?? def.key,\n ...(shifted && { isShifted: true }),\n };\n })\n .filter((h): h is Holiday => h !== null)\n .sort((a, b) => a.date.localeCompare(b.date));\n}\n\n/** Checks if a date is a holiday */\nexport function checkIsHoliday(\n definitions: HolidayDefinition[],\n date: Date,\n names?: Record<string, string>,\n): Holiday | null {\n if (!isValidDate(date)) return null;\n\n const year = date.getUTCFullYear();\n const isoDate = toISODate(date);\n if (!isoDate) return null;\n\n const holidays = resolveHolidays(definitions, year, names);\n return holidays.find((h) => h.date === isoDate) ?? null;\n}\n\n/** Gets the next holiday from a date */\nexport function findNextHoliday(\n definitions: HolidayDefinition[],\n from: Date,\n names?: Record<string, string>,\n): Holiday | null {\n if (!isValidDate(from)) return null;\n\n const isoFrom = toISODate(from);\n if (!isoFrom) return null;\n\n const year = from.getUTCFullYear();\n\n // Search in current year\n let holidays = resolveHolidays(definitions, year, names);\n let next = holidays.find((h) => h.date >= isoFrom);\n\n // If none, search in next year\n if (!next) {\n holidays = resolveHolidays(definitions, year + 1, names);\n next = holidays[0];\n }\n\n return next ?? null;\n}\n","import type { HolidayDefinition } from './types';\nimport { checkIsHoliday } from './engine';\n\n/**\n * Checks if a date is a weekend (Saturday or Sunday)\n * Uses UTC date to avoid timezone issues\n */\nexport function isWeekend(date: Date): boolean {\n const day = date.getUTCDay();\n return day === 0 || day === 6; // 0 = Sunday, 6 = Saturday\n}\n\n/**\n * Checks if a date is a business day (not weekend AND not holiday)\n */\nexport function checkIsBusinessDay(definitions: HolidayDefinition[], date: Date): boolean {\n if (isWeekend(date)) return false;\n return checkIsHoliday(definitions, date) === null;\n}\n\n/**\n * Adds (or subtracts) business days to a date\n */\nexport function addBusinessDays(\n definitions: HolidayDefinition[],\n startDate: Date,\n amount: number,\n): Date {\n const result = new Date(startDate);\n let remaining = Math.abs(amount);\n const direction = amount >= 0 ? 1 : -1;\n\n while (remaining > 0) {\n result.setUTCDate(result.getUTCDate() + direction);\n if (checkIsBusinessDay(definitions, result)) {\n remaining--;\n }\n }\n\n return result;\n}\n\n/**\n * Calculates the number of business days between two dates\n * Returns the number of days to add to startDate to get endDate (can be negative)\n * If startDate and endDate are the same, returns 0\n */\nexport function getBusinessDaysBetween(\n definitions: HolidayDefinition[],\n startDate: Date,\n endDate: Date,\n): number {\n const start = new Date(startDate);\n const end = new Date(endDate);\n\n // Reset hours to avoid issues with daylight saving time or partial days\n start.setUTCHours(0, 0, 0, 0);\n end.setUTCHours(0, 0, 0, 0);\n\n if (start.getTime() === end.getTime()) return 0;\n\n const direction = start < end ? 1 : -1;\n let count = 0;\n const current = new Date(start);\n\n // If direction is positive, we count days starting from start+1 until end\n // If direction is negative, we count days starting from start-1 until end\n\n while (current.getTime() !== end.getTime()) {\n current.setUTCDate(current.getUTCDate() + direction);\n if (checkIsBusinessDay(definitions, current)) {\n count += direction;\n }\n }\n\n return count;\n}\n","/**\n * Options for relative time formatting\n */\nexport interface RelativeTimeOptions {\n /** The locale to use for formatting (default: 'en') */\n locale?: string;\n /** The base date to compare against (default: new Date()) */\n baseDate?: Date;\n /** numeric option for Intl.RelativeTimeFormat (default: 'auto') */\n numeric?: 'always' | 'auto';\n /** style option for Intl.RelativeTimeFormat (default: 'long') */\n style?: 'long' | 'short' | 'narrow';\n}\n\nfunction isFiniteDate(date: Date): boolean {\n return date instanceof Date && Number.isFinite(date.getTime());\n}\n\n/**\n * Formats a date relative to another date (usually \"now\").\n * Uses Intl.RelativeTimeFormat for localization.\n *\n * @param date The date to format\n * @param options Configuration options\n * @returns The formatted relative time string (e.g., \"2 days ago\")\n */\nexport function formatRelativeTime(date: Date, options: RelativeTimeOptions = {}): string {\n const { locale = 'en', baseDate = new Date(), numeric = 'always', style = 'long' } = options;\n\n if (!isFiniteDate(date) || !isFiniteDate(baseDate)) {\n return '';\n }\n\n const diffMs = date.getTime() - baseDate.getTime();\n const diffSecs = Math.round(diffMs / 1000);\n const formatter = new Intl.RelativeTimeFormat(locale, { numeric, style });\n\n // Array of units and their values in seconds\n const units: { unit: Intl.RelativeTimeFormatUnit; seconds: number }[] = [\n { unit: 'year', seconds: 60 * 60 * 24 * 365 },\n { unit: 'month', seconds: 60 * 60 * 24 * 30 },\n { unit: 'week', seconds: 60 * 60 * 24 * 7 },\n { unit: 'day', seconds: 60 * 60 * 24 },\n { unit: 'hour', seconds: 60 * 60 },\n { unit: 'minute', seconds: 60 },\n { unit: 'second', seconds: 1 },\n ];\n\n for (const { unit, seconds } of units) {\n if (Math.abs(diffSecs) >= seconds || unit === 'second') {\n const value = Math.round(diffSecs / seconds);\n return formatter.format(value, unit);\n }\n }\n\n return '';\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -25,4 +25,27 @@ declare function addBusinessDays(definitions: HolidayDefinition[], startDate: Da
|
|
|
25
25
|
*/
|
|
26
26
|
declare function getBusinessDaysBetween(definitions: HolidayDefinition[], startDate: Date, endDate: Date): number;
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Options for relative time formatting
|
|
30
|
+
*/
|
|
31
|
+
interface RelativeTimeOptions {
|
|
32
|
+
/** The locale to use for formatting (default: 'en') */
|
|
33
|
+
locale?: string;
|
|
34
|
+
/** The base date to compare against (default: new Date()) */
|
|
35
|
+
baseDate?: Date;
|
|
36
|
+
/** numeric option for Intl.RelativeTimeFormat (default: 'auto') */
|
|
37
|
+
numeric?: 'always' | 'auto';
|
|
38
|
+
/** style option for Intl.RelativeTimeFormat (default: 'long') */
|
|
39
|
+
style?: 'long' | 'short' | 'narrow';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Formats a date relative to another date (usually "now").
|
|
43
|
+
* Uses Intl.RelativeTimeFormat for localization.
|
|
44
|
+
*
|
|
45
|
+
* @param date The date to format
|
|
46
|
+
* @param options Configuration options
|
|
47
|
+
* @returns The formatted relative time string (e.g., "2 days ago")
|
|
48
|
+
*/
|
|
49
|
+
declare function formatRelativeTime(date: Date, options?: RelativeTimeOptions): string;
|
|
50
|
+
|
|
51
|
+
export { HolidayDefinition, addBusinessDays, checkIsBusinessDay, formatRelativeTime, getBusinessDaysBetween, isWeekend };
|