@absoluteui/helpers 0.0.0-stage → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +47 -2
- package/SECURITY.md +102 -0
- package/dist/array/compare.d.ts +8 -0
- package/dist/array/compare.js +2 -0
- package/dist/array/index.d.ts +328 -0
- package/dist/array/index.js +2 -0
- package/dist/array/tree.d.ts +48 -0
- package/dist/array/tree.js +2 -0
- package/dist/async/batch.d.ts +103 -0
- package/dist/async/batch.js +2 -0
- package/dist/async/concurrency.d.ts +92 -0
- package/dist/async/concurrency.js +2 -0
- package/dist/async/control.d.ts +77 -0
- package/dist/async/control.js +2 -0
- package/dist/async/index.d.ts +8 -0
- package/dist/async/index.js +2 -0
- package/dist/async/signal.d.ts +95 -0
- package/dist/async/signal.js +2 -0
- package/dist/boolean/index.d.ts +83 -0
- package/dist/boolean/index.js +2 -0
- package/dist/business-calendar/days.d.ts +397 -0
- package/dist/business-calendar/days.js +2 -0
- package/dist/business-calendar/describe.d.ts +45 -0
- package/dist/business-calendar/describe.js +2 -0
- package/dist/business-calendar/engine.d.ts +305 -0
- package/dist/business-calendar/engine.js +2 -0
- package/dist/business-calendar/hours.d.ts +96 -0
- package/dist/business-calendar/hours.js +2 -0
- package/dist/business-calendar/index.d.ts +29 -0
- package/dist/business-calendar/index.js +2 -0
- package/dist/business-calendar/internal.d.ts +44 -0
- package/dist/business-calendar/internal.js +2 -0
- package/dist/business-calendar/rules.d.ts +260 -0
- package/dist/business-calendar/rules.js +2 -0
- package/dist/color/index.d.ts +200 -0
- package/dist/color/index.js +2 -0
- package/dist/color/named.d.ts +4 -0
- package/dist/color/named.js +2 -0
- package/dist/compare/index.d.ts +186 -0
- package/dist/compare/index.js +2 -0
- package/dist/convert/index.d.ts +152 -0
- package/dist/convert/index.js +2 -0
- package/dist/csv/index.d.ts +6 -0
- package/dist/csv/index.js +2 -0
- package/dist/csv/parse.d.ts +85 -0
- package/dist/csv/parse.js +12 -0
- package/dist/csv/stringify.d.ts +48 -0
- package/dist/csv/stringify.js +5 -0
- package/dist/date/calendar.d.ts +339 -0
- package/dist/date/calendar.js +2 -0
- package/dist/date/format.d.ts +66 -0
- package/dist/date/format.js +2 -0
- package/dist/date/index.d.ts +26 -0
- package/dist/date/index.js +2 -0
- package/dist/date/intervals.d.ts +110 -0
- package/dist/date/intervals.js +2 -0
- package/dist/date/intl-cache.d.ts +10 -0
- package/dist/date/intl-cache.js +2 -0
- package/dist/date/locale.d.ts +58 -0
- package/dist/date/locale.js +2 -0
- package/dist/date/plain-date.d.ts +105 -0
- package/dist/date/plain-date.js +2 -0
- package/dist/date/plain-time.d.ts +121 -0
- package/dist/date/plain-time.js +2 -0
- package/dist/date/zone.d.ts +121 -0
- package/dist/date/zone.js +2 -0
- package/dist/decimal/index.d.ts +149 -0
- package/dist/decimal/index.js +2 -0
- package/dist/ds/avl.d.ts +50 -0
- package/dist/ds/avl.js +2 -0
- package/dist/ds/bitset.d.ts +46 -0
- package/dist/ds/bitset.js +2 -0
- package/dist/ds/bloom.d.ts +41 -0
- package/dist/ds/bloom.js +2 -0
- package/dist/ds/caches.d.ts +141 -0
- package/dist/ds/caches.js +2 -0
- package/dist/ds/disjoint-set.d.ts +38 -0
- package/dist/ds/disjoint-set.js +2 -0
- package/dist/ds/emitter.d.ts +53 -0
- package/dist/ds/emitter.js +2 -0
- package/dist/ds/graph.d.ts +84 -0
- package/dist/ds/graph.js +2 -0
- package/dist/ds/heap.d.ts +49 -0
- package/dist/ds/heap.js +2 -0
- package/dist/ds/index.d.ts +20 -0
- package/dist/ds/index.js +2 -0
- package/dist/ds/internal.d.ts +19 -0
- package/dist/ds/internal.js +2 -0
- package/dist/ds/interval-tree.d.ts +49 -0
- package/dist/ds/interval-tree.js +2 -0
- package/dist/ds/linked-list.d.ts +54 -0
- package/dist/ds/linked-list.js +2 -0
- package/dist/ds/maps.d.ts +89 -0
- package/dist/ds/maps.js +2 -0
- package/dist/ds/ring.d.ts +99 -0
- package/dist/ds/ring.js +2 -0
- package/dist/ds/sorted.d.ts +104 -0
- package/dist/ds/sorted.js +2 -0
- package/dist/ds/stack.d.ts +28 -0
- package/dist/ds/stack.js +2 -0
- package/dist/ds/trie.d.ts +84 -0
- package/dist/ds/trie.js +2 -0
- package/dist/duration/index.d.ts +146 -0
- package/dist/duration/index.js +2 -0
- package/dist/encoding/index.d.ts +144 -0
- package/dist/encoding/index.js +2 -0
- package/dist/error/index.d.ts +316 -0
- package/dist/error/index.js +2 -0
- package/dist/fn/index.d.ts +129 -0
- package/dist/fn/index.js +2 -0
- package/dist/fn/memo.d.ts +46 -0
- package/dist/fn/memo.js +2 -0
- package/dist/fn/timing.d.ts +64 -0
- package/dist/fn/timing.js +2 -0
- package/dist/http/headers.d.ts +160 -0
- package/dist/http/headers.js +2 -0
- package/dist/http/index.d.ts +10 -0
- package/dist/http/index.js +2 -0
- package/dist/http/problem.d.ts +37 -0
- package/dist/http/problem.js +2 -0
- package/dist/http/response.d.ts +43 -0
- package/dist/http/response.js +2 -0
- package/dist/http/status.d.ts +169 -0
- package/dist/http/status.js +2 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +2 -0
- package/dist/internal/keys.d.ts +6 -0
- package/dist/internal/keys.js +2 -0
- package/dist/is/index.d.ts +219 -0
- package/dist/is/index.js +2 -0
- package/dist/json/index.d.ts +9 -0
- package/dist/json/index.js +2 -0
- package/dist/json/internal.d.ts +12 -0
- package/dist/json/internal.js +2 -0
- package/dist/json/ndjson.d.ts +28 -0
- package/dist/json/ndjson.js +4 -0
- package/dist/json/parse.d.ts +45 -0
- package/dist/json/parse.js +2 -0
- package/dist/json/patch.d.ts +62 -0
- package/dist/json/patch.js +2 -0
- package/dist/json/pointer.d.ts +43 -0
- package/dist/json/pointer.js +2 -0
- package/dist/json/stringify.d.ts +42 -0
- package/dist/json/stringify.js +2 -0
- package/dist/linq/enumerable.d.ts +208 -0
- package/dist/linq/enumerable.js +2 -0
- package/dist/linq/index.d.ts +6 -0
- package/dist/linq/index.js +2 -0
- package/dist/linq/operators.d.ts +503 -0
- package/dist/linq/operators.js +2 -0
- package/dist/number/core.d.ts +164 -0
- package/dist/number/core.js +2 -0
- package/dist/number/format.d.ts +80 -0
- package/dist/number/format.js +2 -0
- package/dist/number/index.d.ts +12 -0
- package/dist/number/index.js +2 -0
- package/dist/number/internal.d.ts +18 -0
- package/dist/number/internal.js +2 -0
- package/dist/number/parse.d.ts +45 -0
- package/dist/number/parse.js +2 -0
- package/dist/number/words.d.ts +19 -0
- package/dist/number/words.js +2 -0
- package/dist/object/basic.d.ts +130 -0
- package/dist/object/basic.js +2 -0
- package/dist/object/deep.d.ts +90 -0
- package/dist/object/deep.js +2 -0
- package/dist/object/diff.d.ts +57 -0
- package/dist/object/diff.js +2 -0
- package/dist/object/index.d.ts +8 -0
- package/dist/object/index.js +2 -0
- package/dist/object/internal.d.ts +21 -0
- package/dist/object/internal.js +2 -0
- package/dist/object/path.d.ts +17 -0
- package/dist/object/path.js +2 -0
- package/dist/random/core.d.ts +14 -0
- package/dist/random/core.js +2 -0
- package/dist/random/index.d.ts +167 -0
- package/dist/random/index.js +2 -0
- package/dist/random/seeded.d.ts +27 -0
- package/dist/random/seeded.js +2 -0
- package/dist/sanitize/index.d.ts +8 -0
- package/dist/sanitize/index.js +2 -0
- package/dist/sanitize/pii.d.ts +48 -0
- package/dist/sanitize/pii.js +2 -0
- package/dist/sanitize/records.d.ts +100 -0
- package/dist/sanitize/records.js +2 -0
- package/dist/sanitize/text.d.ts +101 -0
- package/dist/sanitize/text.js +2 -0
- package/dist/set/index.d.ts +162 -0
- package/dist/set/index.js +2 -0
- package/dist/stats/index.d.ts +190 -0
- package/dist/stats/index.js +2 -0
- package/dist/string/index.d.ts +494 -0
- package/dist/string/index.js +8 -0
- package/dist/string/internal.d.ts +33 -0
- package/dist/string/internal.js +2 -0
- package/dist/string/words.d.ts +14 -0
- package/dist/string/words.js +2 -0
- package/dist/timezone/index.d.ts +76 -0
- package/dist/timezone/index.js +2 -0
- package/dist/url/index.d.ts +178 -0
- package/dist/url/index.js +2 -0
- package/dist/validate/builders.d.ts +6 -0
- package/dist/validate/builders.js +2 -0
- package/dist/validate/formats.d.ts +237 -0
- package/dist/validate/formats.js +2 -0
- package/dist/validate/index.d.ts +13 -0
- package/dist/validate/index.js +2 -0
- package/dist/validate/schema.d.ts +220 -0
- package/dist/validate/schema.js +2 -0
- package/dist/zip/index.d.ts +8 -0
- package/dist/zip/index.js +2 -0
- package/dist/zip/internal.d.ts +69 -0
- package/dist/zip/internal.js +2 -0
- package/dist/zip/reader.d.ts +56 -0
- package/dist/zip/reader.js +2 -0
- package/dist/zip/writer.d.ts +65 -0
- package/dist/zip/writer.js +2 -0
- package/package.json +150 -4
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date-level business-calendar queries: weekend/weekday, holidays, business days, navigation,
|
|
3
|
+
* and differences. Counting is O(years + log h) per range: weekdays arithmetically, holidays and
|
|
4
|
+
* exceptions by binary search over cached per-year prefix sums.
|
|
5
|
+
*/
|
|
6
|
+
import { type DateInput, type Inclusivity, type InstantInput, type PlainDate } from '../date/index.js';
|
|
7
|
+
import { type BusinessCalendar, type BusinessDayInfo } from './engine.js';
|
|
8
|
+
import type { ResolvedHoliday } from './rules.js';
|
|
9
|
+
/**
|
|
10
|
+
* True when the weekday pattern makes the date a weekend day (holidays and exceptions do not
|
|
11
|
+
* matter). Default calendar: Saturday/Sunday.
|
|
12
|
+
* @example isWeekend('2026-10-03') // => true // Saturday
|
|
13
|
+
* @example isWeekend('2026-10-02', createBusinessCalendar({ weekend: [5, 6] })) // => true // Friday
|
|
14
|
+
*/
|
|
15
|
+
export declare function isWeekend(date: DateInput, calendar?: BusinessCalendar): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* True when the date is not a weekend day (it may still be a holiday).
|
|
18
|
+
* @example isWeekday('2026-10-02') // => true // Friday
|
|
19
|
+
* @example
|
|
20
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25)] });
|
|
21
|
+
* isWeekday('2026-12-25', cal); // => true // a holiday is still a weekday
|
|
22
|
+
* isBusinessDay('2026-12-25', cal); // => false
|
|
23
|
+
*/
|
|
24
|
+
export declare function isWeekday(date: DateInput, calendar?: BusinessCalendar): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Every holiday entry on a date (several rules may coincide), including shifted originals
|
|
27
|
+
* (`movedTo`) and half days.
|
|
28
|
+
* @example
|
|
29
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25, { observed: 'nearest-weekday' })] });
|
|
30
|
+
* holidaysOn('2026-12-25', cal).map((h) => h.name); // => ['Christmas Day']
|
|
31
|
+
* holidaysOn('2027-12-25', cal).map((h) => h.movedTo); // => ['2027-12-24'] // Saturday, observed Friday
|
|
32
|
+
* holidaysOn('2026-12-28', cal); // => []
|
|
33
|
+
*/
|
|
34
|
+
export declare function holidaysOn(date: DateInput, calendar?: BusinessCalendar): readonly ResolvedHoliday[];
|
|
35
|
+
/**
|
|
36
|
+
* The full (non-half-day) holiday on a date, preferring one that is in effect there over a
|
|
37
|
+
* weekend original that was shifted elsewhere; `undefined` when there is none. Half days are
|
|
38
|
+
* reported by `isHalfDay`.
|
|
39
|
+
* @example
|
|
40
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25, { observed: 'nearest-weekday' })] });
|
|
41
|
+
* isHoliday('2027-12-24', cal)?.observed; // => true // Christmas on Saturday, observed Friday
|
|
42
|
+
* isHoliday('2027-12-25', cal)?.movedTo; // => '2027-12-24'
|
|
43
|
+
* isHoliday('2027-12-27', cal); // => undefined
|
|
44
|
+
*/
|
|
45
|
+
export declare function isHoliday(date: DateInput, calendar?: BusinessCalendar): ResolvedHoliday | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* True for business days: working weekdays that are not holidays, plus working exceptions.
|
|
48
|
+
* Half days are business days.
|
|
49
|
+
* @example
|
|
50
|
+
* const cal = createBusinessCalendar({
|
|
51
|
+
* holidays: [fixedHoliday('Christmas Day', 12, 25)],
|
|
52
|
+
* exceptions: [{ date: '2026-12-19', working: true, reason: 'Year-end close' }],
|
|
53
|
+
* });
|
|
54
|
+
* isBusinessDay('2026-12-24', cal); // => true // Thursday
|
|
55
|
+
* isBusinessDay('2026-12-25', cal); // => false // holiday
|
|
56
|
+
* isBusinessDay('2026-12-26', cal); // => false // Saturday
|
|
57
|
+
* isBusinessDay('2026-12-19', cal); // => true // working Saturday exception
|
|
58
|
+
*/
|
|
59
|
+
export declare function isBusinessDay(date: DateInput, calendar?: BusinessCalendar): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* True for working half days.
|
|
62
|
+
* @example
|
|
63
|
+
* const cal = createBusinessCalendar({
|
|
64
|
+
* holidays: [fixedHoliday('Christmas Day', 12, 25, { observed: 'nearest-weekday' })],
|
|
65
|
+
* halfDays: [fixedHoliday('Christmas Eve', 12, 24)],
|
|
66
|
+
* });
|
|
67
|
+
* isHalfDay('2026-12-24', cal); // => true // Thursday
|
|
68
|
+
* isBusinessDay('2026-12-24', cal); // => true // half days are business days
|
|
69
|
+
* isHalfDay('2027-12-24', cal); // => false // the observed Christmas Day (a full holiday) wins
|
|
70
|
+
*/
|
|
71
|
+
export declare function isHalfDay(date: DateInput, calendar?: BusinessCalendar): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Full information about a date: working, weekend, holidays, exception, half day, hours, and
|
|
74
|
+
* an accessible reason (`reasonCode` + `reason` text).
|
|
75
|
+
* @example getBusinessDay('2026-10-03').reasonCode // => 'weekend'
|
|
76
|
+
* @example
|
|
77
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25)] });
|
|
78
|
+
* const info = getBusinessDay('2026-12-25', cal);
|
|
79
|
+
* [info.working, info.weekend, info.reasonCode, info.reason]; // => [false, false, 'holiday', 'Christmas Day']
|
|
80
|
+
* getBusinessDay('2026-12-28', cal).reasonCode; // => null // an ordinary working day
|
|
81
|
+
*/
|
|
82
|
+
export declare function getBusinessDay(date: DateInput, calendar?: BusinessCalendar): BusinessDayInfo;
|
|
83
|
+
/**
|
|
84
|
+
* `getBusinessDay` for the calendar date of an instant in the calendar's time zone.
|
|
85
|
+
* @example
|
|
86
|
+
* const indiaCal = createBusinessCalendar({ timeZone: 'Asia/Kolkata' });
|
|
87
|
+
* const instant = Date.UTC(2026, 9, 2, 20); // Friday 20:00 UTC
|
|
88
|
+
* businessDayAt(instant, indiaCal).date; // => '2026-10-03' // already Saturday 01:30 in Kolkata
|
|
89
|
+
* businessDayAt(instant, indiaCal).working; // => false
|
|
90
|
+
* businessDayAt(instant).date; // => '2026-10-02' // the default calendar uses UTC
|
|
91
|
+
*/
|
|
92
|
+
export declare function businessDayAt(instant: InstantInput, calendar?: BusinessCalendar): BusinessDayInfo;
|
|
93
|
+
/**
|
|
94
|
+
* Holiday entries between two dates (inclusive, either order), ascending by date. Ranges may
|
|
95
|
+
* span at most 1000 years.
|
|
96
|
+
* @example
|
|
97
|
+
* const cal = createBusinessCalendar({
|
|
98
|
+
* holidays: [fixedHoliday('New Year', 1, 1), easterHoliday('Good Friday', -2), fixedHoliday('Christmas Day', 12, 25)],
|
|
99
|
+
* });
|
|
100
|
+
* const holidays = listHolidays('2026-01-01', '2026-12-31', cal);
|
|
101
|
+
* holidays.map((h) => h.name); // => ['New Year', 'Good Friday', 'Christmas Day']
|
|
102
|
+
* holidays.map((h) => h.date); // => ['2026-01-01', '2026-04-03', '2026-12-25']
|
|
103
|
+
*/
|
|
104
|
+
export declare function listHolidays(from: DateInput, to: DateInput, calendar?: BusinessCalendar): ResolvedHoliday[];
|
|
105
|
+
/** Options for `listBusinessDays`. */
|
|
106
|
+
export interface ListBusinessDaysOptions {
|
|
107
|
+
/** Stop after this many dates. Default unlimited (the generator is lazy). */
|
|
108
|
+
readonly limit?: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Lazily yields the business days from `from` to `to` inclusive, in that direction (descending
|
|
112
|
+
* when `to` is earlier).
|
|
113
|
+
* @example [...listBusinessDays('2026-10-01', '2026-10-07')].length // => 5
|
|
114
|
+
* @example
|
|
115
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25)] });
|
|
116
|
+
* [...listBusinessDays('2026-12-23', '2026-12-29', cal)]; // => ['2026-12-23', '2026-12-24', '2026-12-28', '2026-12-29']
|
|
117
|
+
* [...listBusinessDays('2026-12-31', '2026-12-01', cal, { limit: 2 })]; // => ['2026-12-31', '2026-12-30'] // descending
|
|
118
|
+
*/
|
|
119
|
+
export declare function listBusinessDays(from: DateInput, to: DateInput, calendar?: BusinessCalendar, options?: ListBusinessDaysOptions): Generator<PlainDate, void, undefined>;
|
|
120
|
+
/**
|
|
121
|
+
* A period for `businessDaysIn`: a calendar year, month, or quarter, or a fiscal year or
|
|
122
|
+
* fiscal quarter per the calendar's `fiscalYearStartMonth` and `fiscalYearNaming`.
|
|
123
|
+
* @example
|
|
124
|
+
* const q: BusinessPeriod = { fiscalYear: 2027, quarter: 1 };
|
|
125
|
+
* periodRange(q, createBusinessCalendar({ fiscalYearStartMonth: 4 })); // => ['2026-04-01', '2026-06-30']
|
|
126
|
+
* periodRange({ year: 2026, quarter: 4 }); // => ['2026-10-01', '2026-12-31']
|
|
127
|
+
*/
|
|
128
|
+
export type BusinessPeriod = number | {
|
|
129
|
+
readonly year: number;
|
|
130
|
+
readonly month: number;
|
|
131
|
+
} | {
|
|
132
|
+
readonly year: number;
|
|
133
|
+
readonly quarter: number;
|
|
134
|
+
} | {
|
|
135
|
+
readonly fiscalYear: number;
|
|
136
|
+
readonly quarter?: number;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* First and last date (inclusive) of a `BusinessPeriod`.
|
|
140
|
+
* @example
|
|
141
|
+
* const cal = createBusinessCalendar({ fiscalYearStartMonth: 4 });
|
|
142
|
+
* periodRange({ fiscalYear: 2027 }, cal); // => ['2026-04-01', '2027-03-31'] // named by the year it ends in
|
|
143
|
+
* periodRange({ year: 2026, month: 2 }); // => ['2026-02-01', '2026-02-28']
|
|
144
|
+
*/
|
|
145
|
+
export declare function periodRange(period: BusinessPeriod, calendar?: BusinessCalendar): readonly [PlainDate, PlainDate];
|
|
146
|
+
/**
|
|
147
|
+
* Business days in a period, half days weighted (`halfDayValue`, default the calendar's).
|
|
148
|
+
* @example businessDaysIn({ year: 2026, month: 10 }) // => 22
|
|
149
|
+
* @example
|
|
150
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25)], halfDays: [fixedHoliday('Christmas Eve', 12, 24)] });
|
|
151
|
+
* businessDaysIn({ year: 2026, month: 12 }, cal); // => 21.5 // 23 weekdays − Christmas − half of Christmas Eve
|
|
152
|
+
* businessDaysIn({ year: 2026, month: 12 }, cal, { halfDayValue: 1 }); // => 22
|
|
153
|
+
*/
|
|
154
|
+
export declare function businessDaysIn(period: BusinessPeriod, calendar?: BusinessCalendar, options?: {
|
|
155
|
+
readonly halfDayValue?: number;
|
|
156
|
+
}): number;
|
|
157
|
+
/** Options for `nextBusinessDay` / `previousBusinessDay`. */
|
|
158
|
+
export interface NextBusinessDayOptions {
|
|
159
|
+
/** Return `date` itself when it is a business day. Default false. */
|
|
160
|
+
readonly includeSelf?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The first business day after `date` (or on it with `includeSelf`). Throws
|
|
164
|
+
* `HLP_BIZCAL_NO_WORKING_DAYS` when the calendar has no business day in reach.
|
|
165
|
+
* @example nextBusinessDay('2026-10-02') // => '2026-10-05' // Friday → Monday
|
|
166
|
+
* @example
|
|
167
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25)] });
|
|
168
|
+
* nextBusinessDay('2026-12-24', cal); // => '2026-12-28' // skips the holiday and the weekend
|
|
169
|
+
* nextBusinessDay('2026-12-24', cal, { includeSelf: true }); // => '2026-12-24'
|
|
170
|
+
*/
|
|
171
|
+
export declare function nextBusinessDay(date: DateInput, calendar?: BusinessCalendar, options?: NextBusinessDayOptions): PlainDate;
|
|
172
|
+
/**
|
|
173
|
+
* The last business day before `date` (or on it with `includeSelf`).
|
|
174
|
+
* @example previousBusinessDay('2026-10-05') // => '2026-10-02' // Monday → Friday
|
|
175
|
+
* @example
|
|
176
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('New Year', 1, 1)] });
|
|
177
|
+
* previousBusinessDay('2027-01-04', cal); // => '2026-12-31' // skips the weekend and New Year (Friday)
|
|
178
|
+
*/
|
|
179
|
+
export declare function previousBusinessDay(date: DateInput, calendar?: BusinessCalendar, options?: NextBusinessDayOptions): PlainDate;
|
|
180
|
+
/** Options for `addBusinessDays`. */
|
|
181
|
+
export interface AddBusinessDaysOptions {
|
|
182
|
+
/**
|
|
183
|
+
* Result for `n = 0`: `'following'` (default) returns `date` when it is a business day, else
|
|
184
|
+
* the next one; `'preceding'` the previous one; `'none'` returns `date` unchanged (Excel
|
|
185
|
+
* `WORKDAY(date, 0)`).
|
|
186
|
+
*/
|
|
187
|
+
readonly zero?: 'following' | 'preceding' | 'none';
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Moves `n` business days (negative moves back); half days count as one business day. The
|
|
191
|
+
* result is always a business day for `n != 0`. Runs in O(log n) range counts, never day by day.
|
|
192
|
+
* Inverse: `diffDays(d, addBusinessDays(d, n), { mode: 'business', inclusive: 'end', halfDayValue: 1 }) === n`
|
|
193
|
+
* for `n > 0` (use `inclusive: 'start'` for `n < 0`).
|
|
194
|
+
* @example addBusinessDays('2026-10-02', 1) // => '2026-10-05'
|
|
195
|
+
* @example addBusinessDays('2026-10-05', -1) // => '2026-10-02'
|
|
196
|
+
* @example
|
|
197
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25), fixedHoliday('New Year', 1, 1)] });
|
|
198
|
+
* addBusinessDays('2026-12-23', 5, cal); // => '2026-12-31' // Christmas and the weekend are skipped
|
|
199
|
+
* addBusinessDays('2026-12-26', 0, cal); // => '2026-12-28' // zero: 'following'
|
|
200
|
+
* addBusinessDays('2026-12-26', 0, cal, { zero: 'none' }); // => '2026-12-26'
|
|
201
|
+
*/
|
|
202
|
+
export declare function addBusinessDays(date: DateInput, n: number, calendar?: BusinessCalendar, options?: AddBusinessDaysOptions): PlainDate;
|
|
203
|
+
/**
|
|
204
|
+
* Business-day conventions (ISDA): `'following'`, `'modifiedFollowing'` (following unless that
|
|
205
|
+
* leaves the month, then preceding), `'preceding'`, `'modifiedPreceding'`, `'none'`.
|
|
206
|
+
* @example const c: BusinessDayConvention = 'modifiedFollowing';
|
|
207
|
+
*/
|
|
208
|
+
export type BusinessDayConvention = 'following' | 'modifiedFollowing' | 'preceding' | 'modifiedPreceding' | 'none';
|
|
209
|
+
/**
|
|
210
|
+
* Rolls a non-business date by a convention; business days are returned unchanged.
|
|
211
|
+
* @example
|
|
212
|
+
* adjustBusinessDay('2026-10-31', 'following'); // => '2026-11-02' // Saturday → Monday
|
|
213
|
+
* adjustBusinessDay('2026-10-31', 'modifiedFollowing'); // => '2026-10-30' // Monday is November, so Friday
|
|
214
|
+
* adjustBusinessDay('2026-10-28', 'modifiedFollowing'); // => '2026-10-28' // business days stay
|
|
215
|
+
*/
|
|
216
|
+
export declare function adjustBusinessDay(date: DateInput, convention: BusinessDayConvention, calendar?: BusinessCalendar): PlainDate;
|
|
217
|
+
/**
|
|
218
|
+
* The `n`-th business day of a month (`n` >= 1), or counting from the end (`-1` = last);
|
|
219
|
+
* `undefined` when the month has fewer.
|
|
220
|
+
* @example nthBusinessDayOfMonth(2026, 10, 1) // => '2026-10-01'
|
|
221
|
+
* @example nthBusinessDayOfMonth(2026, 10, -1) // => '2026-10-30'
|
|
222
|
+
*/
|
|
223
|
+
export declare function nthBusinessDayOfMonth(year: number, month: number, n: number, calendar?: BusinessCalendar): PlainDate | undefined;
|
|
224
|
+
/**
|
|
225
|
+
* First business day of a month, or `undefined` when there is none.
|
|
226
|
+
* @example firstBusinessDayOfMonth(2026, 11) // => '2026-11-02' // 1 November is a Sunday
|
|
227
|
+
* @example
|
|
228
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('New Year', 1, 1)] });
|
|
229
|
+
* firstBusinessDayOfMonth(2027, 1, cal); // => '2027-01-04' // Friday 1st is a holiday
|
|
230
|
+
*/
|
|
231
|
+
export declare function firstBusinessDayOfMonth(year: number, month: number, calendar?: BusinessCalendar): PlainDate | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* Last business day of a month, or `undefined` when there is none.
|
|
234
|
+
* @example lastBusinessDayOfMonth(2026, 10) // => '2026-10-30' // 31 October is a Saturday
|
|
235
|
+
* @example
|
|
236
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('New Year', 1, 1, { observed: 'nearest-weekday' })] });
|
|
237
|
+
* lastBusinessDayOfMonth(2027, 12, cal); // => '2027-12-30' // New Year 2028 (Saturday) is observed on Friday 31st
|
|
238
|
+
*/
|
|
239
|
+
export declare function lastBusinessDayOfMonth(year: number, month: number, calendar?: BusinessCalendar): PlainDate | undefined;
|
|
240
|
+
/**
|
|
241
|
+
* 1-based index of a business day within its month; `undefined` for non-business days.
|
|
242
|
+
* @example businessDayOfMonth('2026-10-05') // => 3
|
|
243
|
+
* @example
|
|
244
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Gandhi Jayanti', 10, 2)] });
|
|
245
|
+
* businessDayOfMonth('2026-10-05', cal); // => 2
|
|
246
|
+
* businessDayOfMonth('2026-10-02', cal); // => undefined // holiday
|
|
247
|
+
*/
|
|
248
|
+
export declare function businessDayOfMonth(date: DateInput, calendar?: BusinessCalendar): number | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* Which end dates of a range are counted. Inclusivity refers to the earlier (`start`) and
|
|
251
|
+
* later (`end`) date whatever the argument order; the sign of a difference gives the direction.
|
|
252
|
+
* For `a` = Monday and `b` = Friday of one week (weekdays mode):
|
|
253
|
+
*
|
|
254
|
+
* | inclusive | dates counted | count |
|
|
255
|
+
* |---|---|---|
|
|
256
|
+
* | `'start'` (default) | Mon..Thu, [a, b) | 4 |
|
|
257
|
+
* | `'end'` | Tue..Fri, (a, b] | 4 |
|
|
258
|
+
* | `'both'` | Mon..Fri, [a, b] (leave requests) | 5 |
|
|
259
|
+
* | `'none'` | Tue..Thu, (a, b) | 3 |
|
|
260
|
+
*
|
|
261
|
+
* When `a` and `b` are the same date only `'both'` counts it.
|
|
262
|
+
*/
|
|
263
|
+
export type { Inclusivity };
|
|
264
|
+
/** What `diffDays` counts. */
|
|
265
|
+
export type DiffMode = 'calendar' | 'weekdays' | 'business';
|
|
266
|
+
/** Options for `diffDays`. */
|
|
267
|
+
export interface DiffDaysOptions {
|
|
268
|
+
/** Default `'calendar'`. `'weekdays'` counts non-weekend days; `'business'` also removes holidays. */
|
|
269
|
+
readonly mode?: DiffMode;
|
|
270
|
+
/** Default `'start'`: [earlier, later), which equals `daysBetween` in calendar mode. */
|
|
271
|
+
readonly inclusive?: Inclusivity;
|
|
272
|
+
/** Default: the shared Saturday/Sunday calendar. */
|
|
273
|
+
readonly calendar?: BusinessCalendar;
|
|
274
|
+
/** Business mode: value of a half day (default the calendar's, 0.5). */
|
|
275
|
+
readonly halfDayValue?: number;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Days from `a` to `b`: calendar days, weekdays (non-weekend), or business days (weekdays minus
|
|
279
|
+
* holidays, plus working exceptions, half days weighted). Negative when `b` is before `a`.
|
|
280
|
+
* Week, month, quarter, and year differences are always calendar-based (B1): use
|
|
281
|
+
* `differenceInMonths` and friends from `@absoluteui/helpers/date`.
|
|
282
|
+
* @example diffDays('2026-09-28', '2026-10-02') // => 4
|
|
283
|
+
* @example diffDays('2026-09-28', '2026-10-02', { mode: 'business', inclusive: 'both' }) // => 5 // Mon..Fri leave
|
|
284
|
+
* @example diffDays('2026-10-02', '2026-09-28', { mode: 'weekdays' }) // => -4
|
|
285
|
+
* @example
|
|
286
|
+
* // Fri 25 Dec 2026 to Fri 1 Jan 2027, with Christmas and New Year as holidays.
|
|
287
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25), fixedHoliday('New Year', 1, 1)] });
|
|
288
|
+
* diffDays('2026-12-25', '2027-01-01', { mode: 'calendar', calendar: cal }); // => 7
|
|
289
|
+
* diffDays('2026-12-25', '2027-01-01', { mode: 'weekdays', calendar: cal }); // => 5
|
|
290
|
+
* diffDays('2026-12-25', '2027-01-01', { mode: 'business', calendar: cal }); // => 4
|
|
291
|
+
* diffDays('2026-12-25', '2027-01-01', { mode: 'business', inclusive: 'both', calendar: cal }); // => 4 // New Year is a holiday too
|
|
292
|
+
*/
|
|
293
|
+
export declare function diffDays(a: DateInput, b: DateInput, options?: DiffDaysOptions): number;
|
|
294
|
+
/** Options for the `count*` functions. */
|
|
295
|
+
export interface CountOptions {
|
|
296
|
+
/** Default `'start'` (see `Inclusivity`). */
|
|
297
|
+
readonly inclusive?: Inclusivity;
|
|
298
|
+
readonly calendar?: BusinessCalendar;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Weekend days between two dates (never negative; argument order does not matter).
|
|
302
|
+
* @example countWeekends('2026-10-01', '2026-10-31', { inclusive: 'both' }) // => 9
|
|
303
|
+
* @example countWeekends('2026-10-01', '2026-10-31', { inclusive: 'both', calendar: createBusinessCalendar({ weekend: [5, 6] }) }) // => 10 // five Fridays and five Saturdays
|
|
304
|
+
*/
|
|
305
|
+
export declare function countWeekends(a: DateInput, b: DateInput, options?: CountOptions): number;
|
|
306
|
+
/**
|
|
307
|
+
* Weekdays (non-weekend days, holidays included) between two dates (never negative).
|
|
308
|
+
* @example countWeekdays('2026-09-28', '2026-10-02', { inclusive: 'both' }) // => 5
|
|
309
|
+
*/
|
|
310
|
+
export declare function countWeekdays(a: DateInput, b: DateInput, options?: CountOptions): number;
|
|
311
|
+
/**
|
|
312
|
+
* Business days between two dates (never negative), half days weighted.
|
|
313
|
+
* @example
|
|
314
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25)], halfDays: [fixedHoliday('Christmas Eve', 12, 24)] });
|
|
315
|
+
* countWeekdays('2026-12-21', '2026-12-25', { inclusive: 'both', calendar: cal }); // => 5
|
|
316
|
+
* countBusinessDays('2026-12-21', '2026-12-25', { inclusive: 'both', calendar: cal }); // => 3.5 // Christmas off, Christmas Eve half
|
|
317
|
+
* countBusinessDays('2026-12-21', '2026-12-25', { inclusive: 'both', calendar: cal, halfDayValue: 1 }); // => 4
|
|
318
|
+
*/
|
|
319
|
+
export declare function countBusinessDays(a: DateInput, b: DateInput, options?: CountOptions & {
|
|
320
|
+
readonly halfDayValue?: number;
|
|
321
|
+
}): number;
|
|
322
|
+
/**
|
|
323
|
+
* Holiday dates in a range: `onWeekdays` (in effect on working weekdays) and `onWeekends`
|
|
324
|
+
* (falling on weekend days, shifted or not). A date with several holidays counts once.
|
|
325
|
+
* @example
|
|
326
|
+
* const cal = createBusinessCalendar({
|
|
327
|
+
* holidays: [fixedHoliday('Republic Day', 1, 26), fixedHoliday('Independence Day', 8, 15), fixedHoliday('Christmas Day', 12, 25)],
|
|
328
|
+
* });
|
|
329
|
+
* const count: HolidayCount = countHolidays('2026-01-01', '2026-12-31', { inclusive: 'both', calendar: cal });
|
|
330
|
+
* count; // => { total: 3, onWeekdays: 2, onWeekends: 1 } // 15 August 2026 is a Saturday
|
|
331
|
+
*/
|
|
332
|
+
export interface HolidayCount {
|
|
333
|
+
readonly total: number;
|
|
334
|
+
readonly onWeekdays: number;
|
|
335
|
+
readonly onWeekends: number;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Counts full-holiday dates between two dates (never negative); see `HolidayCount`.
|
|
339
|
+
* @example
|
|
340
|
+
* const cal = createBusinessCalendar({
|
|
341
|
+
* holidays: [fixedHoliday('Republic Day', 1, 26), fixedHoliday('Independence Day', 8, 15), fixedHoliday('Christmas Day', 12, 25)],
|
|
342
|
+
* });
|
|
343
|
+
* countHolidays('2026-01-01', '2026-12-31', { inclusive: 'both', calendar: cal }).onWeekdays; // => 2
|
|
344
|
+
* countHolidays('2026-08-01', '2026-08-31', { inclusive: 'both', calendar: cal }); // => { total: 1, onWeekdays: 0, onWeekends: 1 }
|
|
345
|
+
*/
|
|
346
|
+
export declare function countHolidays(a: DateInput, b: DateInput, options?: CountOptions): HolidayCount;
|
|
347
|
+
/**
|
|
348
|
+
* Breakdown of a range (all fields signed like `diffDays`). Identities:
|
|
349
|
+
* `weekdays + weekendDays === calendarDays` and
|
|
350
|
+
* `businessDays === weekdays - nonWorkingWeekdays + workingWeekendDays - (1 - halfDayValue) x halfDays`.
|
|
351
|
+
* A holiday on a weekend is counted in `holidaysOnWeekends` and never subtracted twice.
|
|
352
|
+
* `businessHours` is the nominal scheduled wall-clock time (DST-free); use `diffBusinessHours`
|
|
353
|
+
* for elapsed time between instants.
|
|
354
|
+
* @example
|
|
355
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25)] });
|
|
356
|
+
* const b: DiffBreakdown = diffBreakdown('2026-12-21', '2026-12-28', cal); // [Mon 21, Mon 28)
|
|
357
|
+
* [b.calendarDays, b.weekdays, b.weekendDays, b.holidays, b.businessDays]; // => [7, 5, 2, 1, 4]
|
|
358
|
+
* b.weekdays + b.weekendDays === b.calendarDays; // => true
|
|
359
|
+
*/
|
|
360
|
+
export interface DiffBreakdown {
|
|
361
|
+
readonly calendarDays: number;
|
|
362
|
+
readonly weekdays: number;
|
|
363
|
+
readonly weekendDays: number;
|
|
364
|
+
/** Full-holiday dates in effect on working weekdays. */
|
|
365
|
+
readonly holidays: number;
|
|
366
|
+
/** Full-holiday dates on weekend days. */
|
|
367
|
+
readonly holidaysOnWeekends: number;
|
|
368
|
+
/** Working half days. */
|
|
369
|
+
readonly halfDays: number;
|
|
370
|
+
/** Weekdays that are not worked (holidays, non-working exceptions). */
|
|
371
|
+
readonly nonWorkingWeekdays: number;
|
|
372
|
+
/** Weekend days made working by exceptions. */
|
|
373
|
+
readonly workingWeekendDays: number;
|
|
374
|
+
/** Half days weighted by `halfDayValue`. */
|
|
375
|
+
readonly businessDays: number;
|
|
376
|
+
readonly businessHours: number;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Calendar days, weekdays, weekend days, holidays, half days, business days, and nominal
|
|
380
|
+
* business hours of a range in one call (see `DiffBreakdown`).
|
|
381
|
+
* @example
|
|
382
|
+
* diffBreakdown('2026-09-28', '2026-10-02', undefined, { inclusive: 'both' }).businessHours; // => 40 // Mon..Fri, 8 h a day
|
|
383
|
+
* @example
|
|
384
|
+
* const cal = createBusinessCalendar({
|
|
385
|
+
* holidays: [fixedHoliday('Christmas Day', 12, 25), fixedHoliday('Boxing Day', 12, 26)],
|
|
386
|
+
* halfDays: [fixedHoliday('Christmas Eve', 12, 24)],
|
|
387
|
+
* });
|
|
388
|
+
* const b = diffBreakdown('2026-12-21', '2026-12-27', cal, { inclusive: 'both' }); // Mon..Sun
|
|
389
|
+
* [b.calendarDays, b.weekdays, b.weekendDays]; // => [7, 5, 2]
|
|
390
|
+
* [b.holidays, b.holidaysOnWeekends, b.halfDays, b.nonWorkingWeekdays]; // => [1, 1, 1, 1] // Boxing Day is a Saturday
|
|
391
|
+
* b.businessDays; // => 3.5 // 5 weekdays − Christmas − half of Christmas Eve
|
|
392
|
+
* b.businessHours; // => 28 // 3 × 8 h + 4 h on Christmas Eve
|
|
393
|
+
*/
|
|
394
|
+
export declare function diffBreakdown(a: DateInput, b: DateInput, calendar?: BusinessCalendar, options?: {
|
|
395
|
+
readonly inclusive?: Inclusivity;
|
|
396
|
+
readonly halfDayValue?: number;
|
|
397
|
+
}): DiffBreakdown;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{addMonths as k,fromEpochDay as d,plainDate as N,plainDateFromInstant as q,toEpochDay as b,toPlainDate as A}from"../date/index.js";import{S_FULL as G,S_HALF as W,S_HOL_WEEKDAY as E,S_HOL_WEEKEND as M,S_NONWORKING_WEEKDAY as K,S_PATTERN as U,S_WORKING_WEEKEND as X,businessCount as J,businessValue as H,defaultBusinessCalendar as u,engineOf as l,infoAt as v,patternCount as x,rangesAt as Q,recordAt as $,recordsIn as T,specialCounts as R,statusAt as p,stepBackward as O,stepForward as _}from"./engine.js";import{epochOf as ee,invalid as D,limit as Z,weekdayOfEpoch as z}from"./internal.js";const c=e=>b(A(e)),ne=new Set(["none","start","end","both"]),F=1e3,te=new Set(["following","modifiedFollowing","preceding","modifiedPreceding","none"]);function P(e,n){if(n===void 0)return e.cal.halfDayValue;if(typeof n!="number"||!Number.isFinite(n)||n<0||n>1)throw D("HLP_BIZCAL_INVALID_OPTION","halfDayValue must be between 0 and 1.","halfDayValue");return n}function se(e,n=u()){return l(n).working[z(c(e))]!==!0}function fe(e,n=u()){return!se(e,n)}function re(e,n=u()){const t=l(n);return $(t,c(e))?.holidays??[]}function ce(e,n=u()){const t=re(e,n);return t.find(s=>!s.halfDay&&s.movedTo===void 0)??t.find(s=>!s.halfDay)}function ye(e,n=u()){return p(l(n),c(e))!==0}function me(e,n=u()){return p(l(n),c(e))===2}function De(e,n=u()){return v(l(n),c(e))}function be(e,n=u()){const t=l(n);return v(t,b(q(e,t.zone)))}function pe(e,n,t=u()){const s=l(t),r=c(e),a=c(n),o=Math.min(r,a),i=Math.max(r,a);if(d(i).year-d(o).year>F)throw Z("HLP_BIZCAL_RANGE_LIMIT","The date range spans too many years.",F);const f=[];return T(s,o,i,(I,h)=>{f.push(...h.holidays)}),f}function Ie(e,n,t=u(),s={}){const r=l(t),a=c(e),o=c(n),i=s.limit??Number.POSITIVE_INFINITY;if(typeof i!="number"||Number.isNaN(i)||i<0||Number.isFinite(i)&&!Number.isInteger(i))throw D("HLP_BIZCAL_INVALID_OPTION","limit must be a non-negative integer.","limit");const f=o>=a?1:-1;function*I(){let h=0;for(let g=a;f>0?g<=o:g>=o;g+=f){if(h>=i)return;p(r,g)!==0&&(h++,yield d(g))}}return I()}function L(e,n,t,s){if(typeof e!="number"||!Number.isInteger(e)||e<n||e>t)throw D("HLP_BIZCAL_INVALID_OPTION","Period field is out of range.",s);return e}function ae(e,n=u()){const{cal:t}=l(n);let s,r;if(typeof e=="number")s=N(e,1,1),r=12;else if(typeof e=="object"&&"fiscalYear"in e){const a=L(e.fiscalYear,-27e4,27e4,"fiscalYear"),o=t.fiscalYearStartMonth;s=N(o===1||t.fiscalYearNaming==="start"?a:a-1,o,1),r=12,e.quarter!==void 0&&(s=k(s,3*(L(e.quarter,1,4,"quarter")-1)),r=3)}else if(typeof e=="object"&&"month"in e)s=N(e.year,L(e.month,1,12,"month"),1),r=1;else if(typeof e=="object"&&"quarter"in e)s=N(e.year,(L(e.quarter,1,4,"quarter")-1)*3+1,1),r=3;else throw D("HLP_BIZCAL_INVALID_OPTION","Unknown period.","period");return Object.freeze([s,d(b(k(s,r))-1)])}function he(e,n=u(),t={}){const s=l(n),[r,a]=ae(e,n);return H(s,b(r),b(a),P(s,t.halfDayValue))}function Be(e,n=u(),t={}){const s=l(n),r=c(e);return t.includeSelf===!0&&p(s,r)!==0?d(r):d(_(s,r,1))}function ge(e,n=u(),t={}){const s=l(n),r=c(e);return t.includeSelf===!0&&p(s,r)!==0?d(r):d(O(s,r,1))}const Y=1e7;function Oe(e,n,t=u(),s={}){const r=l(t),a=c(e);if(typeof n!="number"||!Number.isInteger(n))throw D("HLP_BIZCAL_INVALID_OPTION","n must be an integer.","n");if(Math.abs(n)>Y)throw Z("HLP_BIZCAL_RANGE_LIMIT","n exceeds the supported number of business days.",Y);if(n>0)return d(_(r,a,n));if(n<0)return d(O(r,a,-n));const o=s.zero??"following";if(o==="none"||p(r,a)!==0)return d(a);if(o==="following")return d(_(r,a,1));if(o==="preceding")return d(O(r,a,1));throw D("HLP_BIZCAL_INVALID_OPTION","Unknown zero option.","zero")}function _e(e,n,t=u()){const s=l(t),r=A(e),a=b(r);if(!te.has(n))throw D("HLP_BIZCAL_INVALID_OPTION","Unknown business-day convention.","convention");if(n==="none"||p(s,a)!==0)return r;switch(n){case"following":return d(_(s,a,1));case"preceding":return d(O(s,a,1));case"modifiedFollowing":{const o=d(_(s,a,1));return o.month===r.month&&o.year===r.year?o:d(O(s,a,1))}case"modifiedPreceding":{const o=d(O(s,a,1));return o.month===r.month&&o.year===r.year?o:d(_(s,a,1))}default:return r}}function oe(e,n){const t=N(e,n,1);return[b(t),b(k(t,1))-1]}function j(e,n,t,s=u()){const r=l(s);if(typeof t!="number"||!Number.isInteger(t)||t===0||Math.abs(t)>31)throw D("HLP_BIZCAL_INVALID_OPTION","n must be a non-zero integer from -31 to 31.","n");const[a,o]=oe(e,n);let i=Math.abs(t);for(let f=0;f<=o-a;f++){const I=t>0?a+f:o-f;if(p(r,I)!==0&&--i===0)return d(I)}}function Ce(e,n,t=u()){return j(e,n,1,t)}function Ne(e,n,t=u()){return j(e,n,-1,t)}function we(e,n=u()){const t=l(n),s=A(e),r=b(s);if(p(t,r)!==0)return J(t,ee(s.year,s.month,1),r)}function C(e,n,t){const s=c(e),r=c(n),a=t??"start";if(!ne.has(a))throw D("HLP_BIZCAL_INVALID_OPTION","inclusive must be none, start, end, or both.","inclusive");const o=Math.min(s,r),i=Math.max(s,r);return o===i?{sign:1,lo:o,hi:a==="both"?o:o-1}:{sign:r>=s?1:-1,lo:a==="both"||a==="start"?o:o+1,hi:a==="both"||a==="end"?i:i-1}}const y=(e,n)=>n===0?0:e*n;function xe(e,n,t={}){const s=l(t.calendar??u()),{sign:r,lo:a,hi:o}=C(e,n,t.inclusive),i=t.mode??"calendar";if(i==="calendar")return y(r,Math.max(0,o-a+1));if(i==="weekdays")return y(r,x(s,a,o));if(i==="business")return y(r,H(s,a,o,P(s,t.halfDayValue)));throw D("HLP_BIZCAL_INVALID_OPTION","mode must be calendar, weekdays, or business.","mode")}function Pe(e,n,t={}){const s=l(t.calendar??u()),{lo:r,hi:a}=C(e,n,t.inclusive);return Math.max(0,a-r+1)-x(s,r,a)}function Le(e,n,t={}){const s=l(t.calendar??u()),{lo:r,hi:a}=C(e,n,t.inclusive);return x(s,r,a)}function ke(e,n,t={}){const s=l(t.calendar??u()),{lo:r,hi:a}=C(e,n,t.inclusive);return H(s,r,a,P(s,t.halfDayValue))}function Ae(e,n,t={}){const s=l(t.calendar??u()),{lo:r,hi:a}=C(e,n,t.inclusive),o=R(s,r,a),i=o[E]??0,f=o[M]??0;return Object.freeze({total:i+f,onWeekdays:i,onWeekends:f})}function ie(e,n,t){if(n<e)return 0;const s=((t-4)%7+7)%7,r=a=>Math.floor((a-s)/7);return r(n)-r(e-1)}const V=e=>e.reduce((n,[t,s])=>n+s-t,0);function He(e,n,t=u(),s={}){const r=l(t),a=P(r,s.halfDayValue),{sign:o,lo:i,hi:f}=C(e,n,s.inclusive),I=Math.max(0,f-i+1),h=x(r,i,f),g=R(r,i,f);let w=0;for(let m=1;m<=7;m++)r.working[m]===!0&&(w+=ie(i,f,m)*V(r.hours[m]??[]));T(r,i,f,(m,S)=>{S.pattern&&(w-=V(r.hours[z(m)]??[])),w+=V(Q(r,m,S))});const B=m=>g[m]??0;return Object.freeze({calendarDays:y(o,I),weekdays:y(o,h),weekendDays:y(o,I-h),holidays:y(o,B(E)),holidaysOnWeekends:y(o,B(M)),halfDays:y(o,B(W)),nonWorkingWeekdays:y(o,B(K)),workingWeekendDays:y(o,B(X)),businessDays:y(o,h-B(U)+B(G)+a*B(W)),businessHours:y(o,w/60)})}export{Oe as addBusinessDays,_e as adjustBusinessDay,be as businessDayAt,we as businessDayOfMonth,he as businessDaysIn,ke as countBusinessDays,Ae as countHolidays,Le as countWeekdays,Pe as countWeekends,He as diffBreakdown,xe as diffDays,Ce as firstBusinessDayOfMonth,De as getBusinessDay,re as holidaysOn,ye as isBusinessDay,me as isHalfDay,ce as isHoliday,fe as isWeekday,se as isWeekend,Ne as lastBusinessDayOfMonth,Ie as listBusinessDays,pe as listHolidays,Be as nextBusinessDay,j as nthBusinessDayOfMonth,ae as periodRange,ge as previousBusinessDay};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BusinessDayInfo } from './engine.js';
|
|
2
|
+
/**
|
|
3
|
+
* Label catalog. `{name}` is replaced with the holiday names (joined with `Intl.ListFormat`)
|
|
4
|
+
* or the exception reason.
|
|
5
|
+
* @example const de: Partial<BusinessDayLabels> = { weekend: 'Wochenende', holiday: 'Feiertag: {name}' };
|
|
6
|
+
*/
|
|
7
|
+
export interface BusinessDayLabels {
|
|
8
|
+
readonly weekend: string;
|
|
9
|
+
readonly holiday: string;
|
|
10
|
+
readonly halfDay: string;
|
|
11
|
+
readonly halfDayUnnamed: string;
|
|
12
|
+
readonly nonWorking: string;
|
|
13
|
+
readonly nonWorkingUnnamed: string;
|
|
14
|
+
readonly working: string;
|
|
15
|
+
readonly workingUnnamed: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* English default labels.
|
|
19
|
+
* @example DEFAULT_BUSINESS_DAY_LABELS.weekend // => 'Weekend'
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_BUSINESS_DAY_LABELS: BusinessDayLabels;
|
|
22
|
+
/** Options for `describeBusinessDay`. */
|
|
23
|
+
export interface DescribeBusinessDayOptions {
|
|
24
|
+
/** Locale for joining several holiday names. */
|
|
25
|
+
readonly locale?: string;
|
|
26
|
+
readonly labels?: Partial<BusinessDayLabels>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Plain-text description of why a day is special: "Weekend", "Holiday: Diwali",
|
|
30
|
+
* "Half day: Christmas Eve", "Working day: Compensatory Saturday"; `''` for an ordinary
|
|
31
|
+
* working day.
|
|
32
|
+
* @example
|
|
33
|
+
* const cal = createBusinessCalendar({
|
|
34
|
+
* holidays: [fixedHoliday('Christmas Day', 12, 25)],
|
|
35
|
+
* halfDays: [fixedHoliday('Christmas Eve', 12, 24)],
|
|
36
|
+
* exceptions: [{ date: '2026-12-19', working: true, reason: 'Year-end close' }],
|
|
37
|
+
* });
|
|
38
|
+
* describeBusinessDay(getBusinessDay('2026-12-25', cal)); // => 'Holiday: Christmas Day'
|
|
39
|
+
* describeBusinessDay(getBusinessDay('2026-12-24', cal)); // => 'Half day: Christmas Eve'
|
|
40
|
+
* describeBusinessDay(getBusinessDay('2026-12-26', cal)); // => 'Weekend'
|
|
41
|
+
* describeBusinessDay(getBusinessDay('2026-12-19', cal)); // => 'Working day: Year-end close'
|
|
42
|
+
* describeBusinessDay(getBusinessDay('2026-12-21', cal)); // => '' // ordinary working day
|
|
43
|
+
* describeBusinessDay(getBusinessDay('2026-12-25', cal), { labels: { holiday: 'Feiertag: {name}' } }); // => 'Feiertag: Christmas Day'
|
|
44
|
+
*/
|
|
45
|
+
export declare function describeBusinessDay(info: BusinessDayInfo, options?: DescribeBusinessDayOptions): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{listFormat as t}from"../date/intl-cache.js";const y=Object.freeze({weekend:"Weekend",holiday:"Holiday: {name}",halfDay:"Half day: {name}",halfDayUnnamed:"Half day",nonWorking:"Non-working day: {name}",nonWorkingUnnamed:"Non-working day",working:"Working day: {name}",workingUnnamed:"Working day"}),r=(n,s)=>n.split("{name}").join(s);function g(n,s={}){const e={...y,...s.labels};switch(n.reasonCode){case"weekend":return e.weekend;case"holiday":{const l=n.holidays.filter(a=>!a.halfDay&&a.movedTo===void 0),i=[...new Set((l.length>0?l:n.holidays.filter(a=>!a.halfDay)).map(a=>a.name))];let o;try{o=t(s.locale,{type:"conjunction",style:"long"}).format(i)}catch{o=i.join(", ")}return r(e.holiday,o)}case"half-day":return n.reason===null?e.halfDayUnnamed:r(e.halfDay,n.reason);case"exception":return n.working?n.halfDay?n.reason===null?e.halfDayUnnamed:r(e.halfDay,n.reason):n.reason===null?e.workingUnnamed:r(e.working,n.reason):n.reason===null?e.nonWorkingUnnamed:r(e.nonWorking,n.reason);default:return""}}export{y as DEFAULT_BUSINESS_DAY_LABELS,g as describeBusinessDay};
|