@absoluteui/helpers 0.0.0-stage → 0.13.2
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,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business calendar definition, validation, and the cached per-year engine. A calendar is an
|
|
3
|
+
* immutable frozen value; its caches live in a `WeakMap` keyed by the calendar, so they never
|
|
4
|
+
* leak and never make the value mutable.
|
|
5
|
+
*
|
|
6
|
+
* Precedence for a date (compatible with the components business-calendar engine):
|
|
7
|
+
* exception, then a full holiday, then a half-day holiday (only on a working weekday), then
|
|
8
|
+
* the weekday pattern.
|
|
9
|
+
*/
|
|
10
|
+
import { type DateInput, type IsoWeekday, type PlainDate } from '../date/index.js';
|
|
11
|
+
import { type MinuteRange, type TimeRange } from './internal.js';
|
|
12
|
+
import { type HolidayProvider, type HolidayRule, type NormalizedRule, type ResolvedHoliday } from './rules.js';
|
|
13
|
+
/**
|
|
14
|
+
* Overrides the weekday pattern and holidays for one date (a compensatory working Saturday, a
|
|
15
|
+
* stocktaking closure). At most one exception per date.
|
|
16
|
+
* @example
|
|
17
|
+
* const ex: BusinessDayException = { date: '2026-10-24', working: true, reason: 'Compensatory working day' };
|
|
18
|
+
* const cal = createBusinessCalendar({ exceptions: [ex] });
|
|
19
|
+
* isBusinessDay('2026-10-24', cal); // => true // a Saturday made working
|
|
20
|
+
* isWeekend('2026-10-24', cal); // => true // the weekday pattern is unchanged
|
|
21
|
+
* getBusinessDay('2026-10-24', cal).reason; // => 'Compensatory working day'
|
|
22
|
+
*/
|
|
23
|
+
export interface BusinessDayException {
|
|
24
|
+
readonly date: DateInput;
|
|
25
|
+
readonly working: boolean;
|
|
26
|
+
/** Hours of a working exception; default the weekday's hours (or half-day hours with `halfDay`). */
|
|
27
|
+
readonly hours?: readonly TimeRange[];
|
|
28
|
+
/** A working half day. */
|
|
29
|
+
readonly halfDay?: boolean;
|
|
30
|
+
/** Plain-text reason, used as the accessible description. */
|
|
31
|
+
readonly reason?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Working hours: `default` for every working day plus per-ISO-weekday overrides (`5` = Friday).
|
|
35
|
+
* An empty list means a working day without scheduled hours.
|
|
36
|
+
* @example
|
|
37
|
+
* const hours: WorkingHoursDefinition = { default: [['09:00', '13:00'], ['14:00', '18:00']], 5: [['09:00', '13:00']] };
|
|
38
|
+
* const cal = createBusinessCalendar({ workingHours: hours });
|
|
39
|
+
* cal.workingHours['1']; // => [['09:00', '13:00'], ['14:00', '18:00']]
|
|
40
|
+
* cal.workingHours['5']; // => [['09:00', '13:00']]
|
|
41
|
+
*/
|
|
42
|
+
export type WorkingHoursDefinition = Readonly<Partial<Record<'default' | `${IsoWeekday}`, readonly TimeRange[]>>>;
|
|
43
|
+
/**
|
|
44
|
+
* Restricts holidays to rules carrying one of `tags`; untagged rules apply unless
|
|
45
|
+
* `includeUntagged: false`.
|
|
46
|
+
* @example
|
|
47
|
+
* const scope: TagScope = { tags: ['IN-KA'] };
|
|
48
|
+
* const cal = createBusinessCalendar({
|
|
49
|
+
* tagScope: scope,
|
|
50
|
+
* holidays: [fixedHoliday('Maharashtra Day', 5, 1, { tags: ['IN-MH'] }), fixedHoliday('Kannada Rajyotsava', 11, 1, { tags: ['IN-KA'] })],
|
|
51
|
+
* });
|
|
52
|
+
* isBusinessDay('2026-05-01', cal); // => true // IN-MH is out of scope
|
|
53
|
+
* isHoliday('2026-11-01', cal)?.name; // => 'Kannada Rajyotsava'
|
|
54
|
+
*/
|
|
55
|
+
export interface TagScope {
|
|
56
|
+
readonly tags: readonly string[];
|
|
57
|
+
readonly includeUntagged?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Input for `createBusinessCalendar`. Every field is optional.
|
|
61
|
+
* @example
|
|
62
|
+
* const def: BusinessCalendarDefinition = { weekend: [5, 6], timeZone: 'Asia/Riyadh' };
|
|
63
|
+
* const cal = createBusinessCalendar(def);
|
|
64
|
+
* cal.workingWeekdays; // => [1, 2, 3, 4, 7]
|
|
65
|
+
* isBusinessDay('2026-10-04', cal); // => true // Sunday
|
|
66
|
+
*/
|
|
67
|
+
export interface BusinessCalendarDefinition {
|
|
68
|
+
readonly name?: string;
|
|
69
|
+
/** Derives `weekend` and `firstDayOfWeek` when those are omitted (`Intl.Locale#getWeekInfo`). */
|
|
70
|
+
readonly locale?: string;
|
|
71
|
+
/** Weekend ISO weekdays; default `[6, 7]` (or the locale's). `[]` = no weekend. */
|
|
72
|
+
readonly weekend?: readonly IsoWeekday[];
|
|
73
|
+
readonly firstDayOfWeek?: IsoWeekday;
|
|
74
|
+
readonly holidays?: readonly HolidayRule[];
|
|
75
|
+
/** Rules that mark working half days (same as holiday rules with `halfDay: true`). */
|
|
76
|
+
readonly halfDays?: readonly HolidayRule[];
|
|
77
|
+
/** Business-day value of a half day, 0..1; default 0.5 (B2). */
|
|
78
|
+
readonly halfDayValue?: number;
|
|
79
|
+
/** Default hours of a half day; default the first half of the weekday's hours. */
|
|
80
|
+
readonly halfDayHours?: readonly TimeRange[];
|
|
81
|
+
readonly exceptions?: readonly BusinessDayException[];
|
|
82
|
+
/** Default `{ default: [['09:00', '17:00']] }`. */
|
|
83
|
+
readonly workingHours?: WorkingHoursDefinition;
|
|
84
|
+
/** IANA zone used for instants (working time, `businessDayAt`); default `'UTC'`. */
|
|
85
|
+
readonly timeZone?: string;
|
|
86
|
+
/** Fiscal year start month 1-12 (B5); default 1. */
|
|
87
|
+
readonly fiscalYearStartMonth?: number;
|
|
88
|
+
/** A fiscal year is named by the calendar year it ends in (default) or starts in. */
|
|
89
|
+
readonly fiscalYearNaming?: 'end' | 'start';
|
|
90
|
+
readonly providers?: readonly HolidayProvider[];
|
|
91
|
+
readonly tagScope?: TagScope | undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Immutable, validated business calendar. Create with `createBusinessCalendar`.
|
|
95
|
+
* @example
|
|
96
|
+
* const cal: BusinessCalendar = createBusinessCalendar({ timeZone: 'Asia/Kolkata' });
|
|
97
|
+
* cal.weekend; // => [6, 7]
|
|
98
|
+
* cal.timeZone; // => 'Asia/Kolkata'
|
|
99
|
+
*/
|
|
100
|
+
export interface BusinessCalendar {
|
|
101
|
+
readonly kind: 'BusinessCalendar';
|
|
102
|
+
readonly name: string;
|
|
103
|
+
readonly weekend: readonly IsoWeekday[];
|
|
104
|
+
readonly workingWeekdays: readonly IsoWeekday[];
|
|
105
|
+
readonly firstDayOfWeek: IsoWeekday;
|
|
106
|
+
readonly timeZone: string;
|
|
107
|
+
readonly fiscalYearStartMonth: number;
|
|
108
|
+
readonly fiscalYearNaming: 'end' | 'start';
|
|
109
|
+
readonly halfDayValue: number;
|
|
110
|
+
/** Resolved hours per ISO weekday (keys `'1'`..`'7'`). */
|
|
111
|
+
readonly workingHours: Readonly<Record<`${IsoWeekday}`, readonly TimeRange[]>>;
|
|
112
|
+
readonly holidays: readonly HolidayRule[];
|
|
113
|
+
readonly halfDays: readonly HolidayRule[];
|
|
114
|
+
readonly exceptions: readonly BusinessDayException[];
|
|
115
|
+
readonly providers: readonly HolidayProvider[];
|
|
116
|
+
readonly tagScope: TagScope | undefined;
|
|
117
|
+
/** Normalized definition; `createBusinessCalendar(cal.definition)` recreates the calendar. */
|
|
118
|
+
readonly definition: BusinessCalendarDefinition;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Why a day is special. The UI localizes `'weekend'`; the others come with `reason` text.
|
|
122
|
+
* @example const code: BusinessDayReasonCode = 'holiday';
|
|
123
|
+
*/
|
|
124
|
+
export type BusinessDayReasonCode = 'weekend' | 'holiday' | 'exception' | 'half-day';
|
|
125
|
+
/**
|
|
126
|
+
* Everything about one date in a calendar.
|
|
127
|
+
* @example
|
|
128
|
+
* const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25)], halfDays: [fixedHoliday('Christmas Eve', 12, 24)] });
|
|
129
|
+
* getBusinessDay('2026-12-25', cal).reasonCode; // => 'holiday'
|
|
130
|
+
* getBusinessDay('2026-12-26', cal).reasonCode; // => 'weekend'
|
|
131
|
+
* const eve = getBusinessDay('2026-12-24', cal);
|
|
132
|
+
* [eve.working, eve.halfDay, eve.businessDayValue, eve.hours]; // => [true, true, 0.5, [['09:00', '13:00']]]
|
|
133
|
+
*/
|
|
134
|
+
export interface BusinessDayInfo {
|
|
135
|
+
readonly date: PlainDate;
|
|
136
|
+
readonly weekday: IsoWeekday;
|
|
137
|
+
/** A business day (half days included). */
|
|
138
|
+
readonly working: boolean;
|
|
139
|
+
/** The weekday pattern alone makes the day non-working. */
|
|
140
|
+
readonly weekend: boolean;
|
|
141
|
+
/** Every holiday entry on the date, including shifted originals (`movedTo`) and half days. */
|
|
142
|
+
readonly holidays: readonly ResolvedHoliday[];
|
|
143
|
+
/** The exception deciding the day, or null. */
|
|
144
|
+
readonly exception: BusinessDayException | null;
|
|
145
|
+
readonly halfDay: boolean;
|
|
146
|
+
/** Working hours; empty on a non-working day. */
|
|
147
|
+
readonly hours: readonly TimeRange[];
|
|
148
|
+
/** Null for an ordinary working day. */
|
|
149
|
+
readonly reasonCode: BusinessDayReasonCode | null;
|
|
150
|
+
/** Holiday name or exception reason (plain text), or null. */
|
|
151
|
+
readonly reason: string | null;
|
|
152
|
+
/** 1, the half-day value, or 0. */
|
|
153
|
+
readonly businessDayValue: number;
|
|
154
|
+
}
|
|
155
|
+
interface NormEx {
|
|
156
|
+
readonly e: number;
|
|
157
|
+
readonly ex: BusinessDayException;
|
|
158
|
+
readonly hours: readonly MinuteRange[] | undefined;
|
|
159
|
+
readonly halfDay: boolean;
|
|
160
|
+
}
|
|
161
|
+
/** Special (non-pattern) day. Internal. */
|
|
162
|
+
export interface DayRecord {
|
|
163
|
+
readonly holidays: readonly ResolvedHoliday[];
|
|
164
|
+
readonly exception: NormEx | undefined;
|
|
165
|
+
readonly pattern: boolean;
|
|
166
|
+
/** 0 non-working, 1 full working day, 2 working half day. */
|
|
167
|
+
readonly status: 0 | 1 | 2;
|
|
168
|
+
readonly anyFull: boolean;
|
|
169
|
+
readonly halfHours: readonly MinuteRange[] | undefined;
|
|
170
|
+
}
|
|
171
|
+
interface YearData {
|
|
172
|
+
readonly days: readonly number[];
|
|
173
|
+
readonly records: ReadonlyMap<number, DayRecord>;
|
|
174
|
+
/** Prefix sums, K per slot, (days.length + 1) slots. */
|
|
175
|
+
readonly cum: Float64Array;
|
|
176
|
+
}
|
|
177
|
+
/** Fields of the special-day prefix sums. */
|
|
178
|
+
export declare const S_PATTERN = 0;
|
|
179
|
+
export declare const S_FULL = 1;
|
|
180
|
+
export declare const S_HALF = 2;
|
|
181
|
+
export declare const S_HOL_WEEKDAY = 3;
|
|
182
|
+
export declare const S_HOL_WEEKEND = 4;
|
|
183
|
+
export declare const S_NONWORKING_WEEKDAY = 5;
|
|
184
|
+
export declare const S_WORKING_WEEKEND = 6;
|
|
185
|
+
/** Internal engine of a calendar. */
|
|
186
|
+
export interface Engine {
|
|
187
|
+
readonly cal: BusinessCalendar;
|
|
188
|
+
readonly working: readonly boolean[];
|
|
189
|
+
readonly workingCount: number;
|
|
190
|
+
readonly pre: readonly number[];
|
|
191
|
+
readonly hours: readonly (readonly MinuteRange[])[];
|
|
192
|
+
readonly halfHours: readonly (readonly MinuteRange[])[];
|
|
193
|
+
readonly zone: string;
|
|
194
|
+
readonly rules: readonly NormalizedRule[];
|
|
195
|
+
readonly providers: readonly HolidayProvider[];
|
|
196
|
+
readonly scope: TagScope | undefined;
|
|
197
|
+
readonly exceptions: ReadonlyMap<number, NormEx>;
|
|
198
|
+
readonly exceptionDays: readonly number[];
|
|
199
|
+
readonly workingExceptionDays: readonly number[];
|
|
200
|
+
readonly years: Map<number, YearData>;
|
|
201
|
+
readonly provided: Map<number, readonly NormalizedRule[]>;
|
|
202
|
+
readonly occurrences: Map<string, readonly number[]>;
|
|
203
|
+
}
|
|
204
|
+
/** Engine of a calendar; throws `HLP_BIZCAL_INVALID_CALENDAR` for anything else. */
|
|
205
|
+
export declare function engineOf(calendar: BusinessCalendar): Engine;
|
|
206
|
+
/** Error for calendars without any business day in reach. */
|
|
207
|
+
export declare function noWorkingDays(): never;
|
|
208
|
+
/** Special-day record of an epoch day, if any. */
|
|
209
|
+
export declare function recordAt(eng: Engine, e: number): DayRecord | undefined;
|
|
210
|
+
/** Working days of the weekday pattern in [lo, hi] (arithmetic, O(1)). */
|
|
211
|
+
export declare function patternCount(eng: Engine, lo: number, hi: number): number;
|
|
212
|
+
/** Sums of the special-day fields over [lo, hi]: per-year prefix sums + binary search. */
|
|
213
|
+
export declare function specialCounts(eng: Engine, lo: number, hi: number): Float64Array;
|
|
214
|
+
/** Calls `fn` for every special-day record in [lo, hi], ascending. */
|
|
215
|
+
export declare function recordsIn(eng: Engine, lo: number, hi: number, fn: (e: number, rec: DayRecord) => void): void;
|
|
216
|
+
/** Business-day value over [lo, hi], half days weighted by `halfValue`. */
|
|
217
|
+
export declare function businessValue(eng: Engine, lo: number, hi: number, halfValue: number): number;
|
|
218
|
+
/** Business days (half days count 1) over [lo, hi]. */
|
|
219
|
+
export declare const businessCount: (eng: Engine, lo: number, hi: number) => number;
|
|
220
|
+
/** Status of an epoch day: 0 non-working, 1 working, 2 half day. O(1) after the year is cached. */
|
|
221
|
+
export declare function statusAt(eng: Engine, e: number): 0 | 1 | 2;
|
|
222
|
+
/** The `n`-th (n >= 1) business day after `e0`. */
|
|
223
|
+
export declare function stepForward(eng: Engine, e0: number, n: number): number;
|
|
224
|
+
/** The `n`-th (n >= 1) business day before `e0`. */
|
|
225
|
+
export declare function stepBackward(eng: Engine, e0: number, n: number): number;
|
|
226
|
+
/** Working hours (minutes) of an epoch day, respecting exceptions and half days. */
|
|
227
|
+
export declare function rangesAt(eng: Engine, e: number, rec?: DayRecord | undefined): readonly MinuteRange[];
|
|
228
|
+
/** Public info for an epoch day. */
|
|
229
|
+
export declare function infoAt(eng: Engine, e: number): BusinessDayInfo;
|
|
230
|
+
/**
|
|
231
|
+
* Creates an immutable, validated business calendar. Invalid definitions throw
|
|
232
|
+
* `ValidationError` (`HLP_BIZCAL_*`; details name the property path, never the value); list
|
|
233
|
+
* sizes are bounded (`LimitError`). Holidays are expanded lazily per year and cached (200
|
|
234
|
+
* years, LRU) on the instance.
|
|
235
|
+
* @example
|
|
236
|
+
* const cal = createBusinessCalendar({
|
|
237
|
+
* weekend: [6, 7],
|
|
238
|
+
* holidays: [fixedHoliday('New Year', 1, 1, { observed: 'nearest-weekday' }), easterHoliday('Good Friday', -2)],
|
|
239
|
+
* workingHours: { default: [['09:00', '13:00'], ['14:00', '18:00']], 5: [['09:00', '13:00']] },
|
|
240
|
+
* timeZone: 'Asia/Kolkata',
|
|
241
|
+
* });
|
|
242
|
+
* isHoliday('2027-03-26', cal)?.name; // => 'Good Friday'
|
|
243
|
+
* isBusinessDay('2027-12-31', cal); // => false // New Year 2028 falls on a Saturday
|
|
244
|
+
* getBusinessDay('2026-10-02', cal).hours; // => [['09:00', '13:00']] // Friday hours
|
|
245
|
+
* @example
|
|
246
|
+
* createBusinessCalendar({ fiscalYearStartMonth: 13 }); // => throws HLP_BIZCAL_INVALID_FISCAL
|
|
247
|
+
*/
|
|
248
|
+
export declare function createBusinessCalendar(definition?: BusinessCalendarDefinition): BusinessCalendar;
|
|
249
|
+
/**
|
|
250
|
+
* True for values created by `createBusinessCalendar`.
|
|
251
|
+
* @example
|
|
252
|
+
* isBusinessCalendar(createBusinessCalendar()); // => true
|
|
253
|
+
* isBusinessCalendar({ kind: 'BusinessCalendar', weekend: [6, 7] }); // => false // not created by createBusinessCalendar
|
|
254
|
+
*/
|
|
255
|
+
export declare function isBusinessCalendar(value: unknown): value is BusinessCalendar;
|
|
256
|
+
/**
|
|
257
|
+
* The shared default calendar: Saturday/Sunday weekend, no holidays, 09:00-17:00, UTC. Used
|
|
258
|
+
* when a function's `calendar` argument is omitted.
|
|
259
|
+
* @example
|
|
260
|
+
* isBusinessDay('2026-09-26', defaultBusinessCalendar()); // => false // Saturday
|
|
261
|
+
* isBusinessDay('2026-12-25', defaultBusinessCalendar()); // => true // no holidays by default
|
|
262
|
+
* defaultBusinessCalendar().timeZone; // => 'UTC'
|
|
263
|
+
*/
|
|
264
|
+
export declare function defaultBusinessCalendar(): BusinessCalendar;
|
|
265
|
+
/**
|
|
266
|
+
* Weekend days of a locale (CLDR via `Intl.Locale#getWeekInfo`, with an embedded fallback).
|
|
267
|
+
* @example weekendForLocale('ar-SA') // => [5, 6]
|
|
268
|
+
* @example weekendForLocale('en-IN') // => [7]
|
|
269
|
+
*/
|
|
270
|
+
export declare function weekendForLocale(locale?: string): readonly IsoWeekday[];
|
|
271
|
+
/**
|
|
272
|
+
* Combines calendars: the union of holidays, half days, providers, and exceptions (the first
|
|
273
|
+
* calendar wins when two define an exception for the same date). Weekend, hours, time zone,
|
|
274
|
+
* fiscal settings, and half-day settings come from the first calendar unless `overrides` sets
|
|
275
|
+
* them. Each input's tag scope is applied to its own holidays before merging.
|
|
276
|
+
* @example
|
|
277
|
+
* const company = createBusinessCalendar({ name: 'Company', holidays: [fixedHoliday('Founders Day', 3, 16)] });
|
|
278
|
+
* const regional = createBusinessCalendar({ name: 'Karnataka', holidays: [fixedHoliday('Kannada Rajyotsava', 11, 1, { observed: 'next-weekday' })] });
|
|
279
|
+
* const team = mergeCalendars([company, regional], { name: 'Bengaluru team' });
|
|
280
|
+
* team.name; // => 'Bengaluru team'
|
|
281
|
+
* isBusinessDay('2026-03-16', team); // => false // Founders Day, a Monday
|
|
282
|
+
* isHoliday('2026-11-02', team)?.name; // => 'Kannada Rajyotsava' // Sunday 1st observed on Monday
|
|
283
|
+
*/
|
|
284
|
+
export declare function mergeCalendars(calendars: readonly BusinessCalendar[], overrides?: BusinessCalendarDefinition): BusinessCalendar;
|
|
285
|
+
/**
|
|
286
|
+
* A copy of the calendar whose holidays are limited to rules tagged with one of `tags`
|
|
287
|
+
* (untagged rules stay unless `includeUntagged: false`). Replaces any previous scope.
|
|
288
|
+
* @example
|
|
289
|
+
* const india = createBusinessCalendar({
|
|
290
|
+
* weekend: [7],
|
|
291
|
+
* holidays: [
|
|
292
|
+
* fixedHoliday('Republic Day', 1, 26),
|
|
293
|
+
* fixedHoliday('Maharashtra Day', 5, 1, { tags: ['IN-MH'] }),
|
|
294
|
+
* fixedHoliday('Kannada Rajyotsava', 11, 1, { tags: ['IN-KA'] }),
|
|
295
|
+
* ],
|
|
296
|
+
* });
|
|
297
|
+
* const karnataka = withTags(india, ['IN-KA']);
|
|
298
|
+
* listHolidays('2026-01-01', '2026-12-31', karnataka).map((h) => h.name); // => ['Republic Day', 'Kannada Rajyotsava']
|
|
299
|
+
* isBusinessDay('2026-05-01', karnataka); // => true // Maharashtra Day does not apply
|
|
300
|
+
* listHolidays('2026-01-01', '2026-12-31', withTags(india, ['IN-MH'], { includeUntagged: false })).map((h) => h.name); // => ['Maharashtra Day']
|
|
301
|
+
*/
|
|
302
|
+
export declare function withTags(calendar: BusinessCalendar, tags: readonly string[], options?: {
|
|
303
|
+
readonly includeUntagged?: boolean;
|
|
304
|
+
}): BusinessCalendar;
|
|
305
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{MAX_YEAR as ae,fromEpochDay as T,getWeekInfo as te,toEpochDay as se}from"../date/index.js";import{isValidTimeZone as be}from"../timezone/index.js";import{epochOf as ie,firstHalf as De,invalid as y,isArray as z,isRecord as O,limit as j,lowerBound as Z,normalizeRanges as Y,optionalText as de,rangesToText as W,requiredName as we,upperBound as v,weekdayOfEpoch as H}from"./internal.js";import{normalizeRule as $,normalizeTags as ke}from"./rules.js";const Ie=0,_e=1,Ee=2,Ke=3,Ge=4,qe=5,Je=6,S=7,J=new WeakMap,xe=200,Ae=5e3,le=5e3,Re=1e5,Le=32,ue=1e4,ce=45,U=2e4,fe=366*100;function ye(e){const n=e,o=typeof n=="object"&&n!==null?J.get(n):void 0;if(!o)throw y("HLP_BIZCAL_INVALID_CALENDAR","Expected a calendar created by createBusinessCalendar.");return o}function F(){throw y("HLP_BIZCAL_NO_WORKING_DAYS","The calendar has no business day within the search limit.")}const V=e=>T(e).year;function Q(e,n){return e?n.length===0?e.includeUntagged??!0:n.some(o=>e.tags.includes(o)):!0}function pe(e,n){const o=e.get(n);return o!==void 0&&(e.delete(n),e.set(n,o)),o}function me(e,n,o){if(e.size>=xe){const a=e.keys().next();a.done!==!0&&e.delete(a.value)}return e.set(n,o),o}function Ce(e,n){if(e.providers.length===0||Math.abs(n)>ae)return[];const o=pe(e.provided,n);if(o)return o;const a=[];return e.providers.forEach((i,r)=>{const t=i.holidaysFor(n);if(!z(t))throw y("HLP_BIZCAL_INVALID_PROVIDER","A holiday provider must return an array.",`providers[${String(r)}]`);if(t.length>ue)throw j("HLP_BIZCAL_PROVIDER_LIMIT","A holiday provider returned too many holidays for one year.",ue);t.forEach((d,l)=>a.push($(d,`providers[${String(r)}][${String(l)}]`,{allowProvided:!0})))}),me(e.provided,n,Object.freeze(a))}function He(e,n,o,a){const i=n.occurrences;if(!i)return[];if(o<0)return i(a);const r=`${String(o)}:${String(a)}`,t=e.occurrences.get(r);if(t)return t;const d=i(a);return e.occurrences.size>=Ae&&e.occurrences.clear(),e.occurrences.set(r,d),d}function Se(e,n,o,a){if(o==="none")return;const i=H(n),r=l=>e.working[H(l)]===!0;let t,d;if(typeof o=="string"){if(r(n)||e.workingCount===0)return;if(o==="next-weekday")t=1;else if(o==="previous-weekday")t=-1;else{let l=1;for(;!r(n+l)&&!r(n-l);)l++;t=r(n+l)?1:-1}d=n+t}else{const l=o[i];if(l===void 0||l===0)return;t=l>0?1:-1,d=n+l}for(let l=0;l<366;l++){if(r(d)&&!a.has(d))return d;d+=t}}function Ne(e,n,o,a,i){return Object.freeze({date:T(e),name:n.name,kind:n.kind,...n.id===void 0?{}:{id:n.id},tags:n.tags,halfDay:n.halfDay,observed:o,...a===void 0?{}:{originalDate:T(a)},...i===void 0?{}:{movedTo:T(i)}})}function Oe(e,n){const o=ie(n,1,1),a=ie(n+1,1,1)-1,i=o-ce,r=a+ce,t=[];let d=0;const l=(s,f,D)=>{if(d++,!!Q(e.scope,s.tags)){if(s.span){const g=Math.min(s.span[1],r);for(let h=Math.max(s.span[0],i);h<=g;h++)t.push({e:h,r:s,order:d});return}for(const g of D)if(!(g<s.fromYear||g>s.toYear||Math.abs(g)>=ae))for(const h of He(e,s,f,g))h>=i&&h<=r&&t.push({e:h,r:s,order:d})}},p=[n-1,n,n+1];e.rules.forEach((s,f)=>{l(s,f,p)});for(const s of p)for(const f of Ce(e,s))l(f,-1,[s]);t.sort((s,f)=>s.e-f.e||s.order-f.order);const c=new Set;for(const s of t)s.r.halfDay||c.add(s.e);const m=new Map,I=new Set,x=(s,f,D,g,h)=>{if(s<o||s>a)return;const C=`${String(s)}|${String(D)}|${String(f.halfDay)}|${f.kind}|${f.name}`;if(I.has(C))return;I.add(C);let E=m.get(s);E||(E=[],m.set(s,E)),E.push({h:Ne(s,f,D,g,h),r:f})};for(const s of t){const f=Se(e,s.e,s.r.observed,c);f===void 0?x(s.e,s.r,!1):(x(s.e,s.r,!1,void 0,f),x(f,s.r,!0,s.e),s.r.halfDay||c.add(f))}const w=Z(e.exceptionDays,o),R=v(e.exceptionDays,a),A=new Set(m.keys());for(let s=w;s<R;s++)A.add(e.exceptionDays[s]??0);const B=[...A].sort((s,f)=>s-f),L=new Map,P=new Float64Array((B.length+1)*S);return B.forEach((s,f)=>{const D=m.get(s)??[],g=e.exceptions.get(s),h=e.working[H(s)]===!0,C=D.some(({h:b})=>!b.halfDay&&b.movedTo===void 0),E=D.some(({h:b})=>!b.halfDay),M=D.find(({h:b})=>b.halfDay&&b.movedTo===void 0);let k;g?k=g.ex.working?g.halfDay?2:1:0:C?k=0:M&&h?k=2:k=h?1:0,L.set(s,Object.freeze({holidays:Object.freeze(D.map(b=>b.h)),exception:g,pattern:h,status:k,anyFull:E,halfHours:M?.r.halfHours}));const N=f*S,G=N+S;[h,k===1,k===2,h&&C,!h&&E,h&&k===0,!h&&k>0].forEach((b,u)=>{P[G+u]=(P[N+u]??0)+(b?1:0)})}),Object.freeze({days:B,records:L,cum:P})}function ee(e,n){return pe(e.years,n)??me(e.years,n,Oe(e,n))}function ne(e,n){return ee(e,V(n)).records.get(n)}function Be(e,n,o){if(o<n)return 0;const a=i=>Math.floor(i/7)*e.workingCount+(e.pre[(i%7+7)%7]??0);return a(o+1)-a(n)}function Pe(e,n,o){const a=new Float64Array(S);if(o<n)return a;const i=V(n),r=V(o);if(r-i>U)throw j("HLP_BIZCAL_RANGE_LIMIT","The date range spans too many years.",U);for(let t=i;t<=r;t++){const d=ee(e,t),l=t===i?Z(d.days,n):0,p=t===r?v(d.days,o):d.days.length;if(!(p<=l))for(let c=0;c<S;c++)a[c]=(a[c]??0)+(d.cum[p*S+c]??0)-(d.cum[l*S+c]??0)}return a}function Qe(e,n,o,a){if(o<n)return;const i=V(n),r=V(o);if(r-i>U)throw j("HLP_BIZCAL_RANGE_LIMIT","The date range spans too many years.",U);for(let t=i;t<=r;t++){const d=ee(e,t),l=t===r?v(d.days,o):d.days.length;for(let p=t===i?Z(d.days,n):0;p<l;p++){const c=d.days[p]??0,m=d.records.get(c);m&&a(c,m)}}}function Me(e,n,o,a){if(o<n)return 0;const i=Pe(e,n,o);return Be(e,n,o)-(i[Ie]??0)+(i[_e]??0)+a*(i[Ee]??0)}const X=(e,n,o)=>Me(e,n,o,1);function en(e,n){const o=ne(e,n);return o?o.status:e.working[H(n)]===!0?1:0}function nn(e,n,o){if(e.workingCount===0)return e.workingExceptionDays[v(e.workingExceptionDays,n)+o-1]??F();const a=Math.ceil(o/e.workingCount)*7+7,i=a+fe;let r=a;for(;X(e,n+1,n+r)<o;)r>=i&&F(),r=Math.min(r*2,i);let t=1,d=r;for(;t<d;){const l=t+Math.floor((d-t)/2);X(e,n+1,n+l)>=o?d=l:t=l+1}return n+t}function on(e,n,o){if(e.workingCount===0)return e.workingExceptionDays[Z(e.workingExceptionDays,n)-o]??F();const a=Math.ceil(o/e.workingCount)*7+7,i=a+fe;let r=a;for(;X(e,n-r,n-1)<o;)r>=i&&F(),r=Math.min(r*2,i);let t=1,d=r;for(;t<d;){const l=t+Math.floor((d-t)/2);X(e,n-l,n-1)>=o?d=l:t=l+1}return n-t}function Te(e,n,o=ne(e,n)){const a=H(n),i=o?o.status:e.working[a]===!0?1:0;if(i===0)return[];const r=o?.exception;return r?r.hours??(r.halfDay?e.halfHours[a]??[]:e.hours[a]??[]):i===2?o?.halfHours??e.halfHours[a]??[]:e.hours[a]??[]}function rn(e,n){const o=ne(e,n),a=H(n),i=e.working[a]===!0,r=o?o.status:i?1:0,t=o?.holidays??[],d=o?.exception;let l=null,p=null;if(d)l="exception",p=d.ex.reason??null;else if(r===0){const c=t.find(m=>!m.halfDay&&m.movedTo===void 0)??t.find(m=>!m.halfDay);c?(l="holiday",p=c.name):l="weekend"}else r===2&&(l="half-day",p=t.find(c=>c.halfDay&&c.movedTo===void 0)?.name??null);return Object.freeze({date:T(n),weekday:a,working:r!==0,weekend:!i,holidays:t,exception:d?.ex??null,halfDay:r===2,hours:W(Te(e,n,o)),reasonCode:l,reason:p,businessDayValue:r===0?0:r===2?e.cal.halfDayValue:1})}const oe=Object.freeze([Object.freeze(["09:00","17:00"])]),ze=new Set(["default","1","2","3","4","5","6","7"]);function he(e,n){if(typeof e!="number"||!Number.isInteger(e)||e<1||e>7)throw y("HLP_BIZCAL_INVALID_WEEKDAY","Expected an ISO weekday 1 (Monday) to 7 (Sunday).",n);return e}function We(e){if(!z(e)||e.length>7)throw y("HLP_BIZCAL_INVALID_WEEKEND","Weekend must be an array of distinct ISO weekdays.","weekend");const n=e.map(o=>he(o,"weekend"));if(new Set(n).size!==n.length)throw y("HLP_BIZCAL_INVALID_WEEKEND","Weekend must be an array of distinct ISO weekdays.","weekend");return Object.freeze([...n].sort((o,a)=>o-a))}function Ve(e){if(e===void 0&&(e={default:oe}),!O(e))throw y("HLP_BIZCAL_INVALID_HOURS","workingHours must be an object.","workingHours");const n={},o=new Map;for(const r of Object.keys(e)){if(!ze.has(r))throw y("HLP_BIZCAL_INVALID_HOURS",'workingHours keys must be "default" or ISO weekdays 1-7.',"workingHours");const t=Y(e[r],`workingHours.${r}`);o.set(r,t),n[r]=W(t)}o.has("default")||(o.set("default",Y(oe,"workingHours.default")),n.default=oe);const a=o.get("default")??[],i=[[]];for(let r=1;r<=7;r++)i.push(o.get(String(r))??a);return{text:Object.freeze(n),byDay:Object.freeze(i)}}function je(e,n){if(!O(e))throw y("HLP_BIZCAL_INVALID_EXCEPTION","An exception must be an object.",n);const o=$({kind:"date",name:"exception",date:e.date},n).rule;if(typeof e.working!="boolean")throw y("HLP_BIZCAL_INVALID_EXCEPTION","Exception working must be a boolean.",`${n}.working`);if(e.halfDay!==void 0&&typeof e.halfDay!="boolean")throw y("HLP_BIZCAL_INVALID_EXCEPTION","Exception halfDay must be a boolean.",`${n}.halfDay`);const a=e.halfDay===!0;if(!e.working&&(a||e.hours!==void 0))throw y("HLP_BIZCAL_INVALID_EXCEPTION","Only working exceptions may set hours or halfDay.",n);const i=e.hours===void 0?void 0:Y(e.hours,`${n}.hours`),r=de(e.reason,`${n}.reason`),t=Object.freeze({date:o.date,working:e.working,...i===void 0?{}:{hours:W(i)},...a?{halfDay:a}:{},...r===void 0?{}:{reason:r}});return Object.freeze({e:se(o.date),ex:t,hours:i,halfDay:a})}function K(e,n,o){if(e===void 0)return[];if(!z(e))throw y("HLP_BIZCAL_INVALID_DEFINITION","Expected an array.",n);if(e.length>o)throw j("HLP_BIZCAL_TOO_MANY_ITEMS","Too many items in a calendar definition list.",o);return e}function Ze(e){if(e===void 0)return;if(!O(e))throw y("HLP_BIZCAL_INVALID_TAGS","tagScope must be an object.","tagScope");const n=ke(e.tags,"tagScope.tags");if(e.includeUntagged!==void 0&&typeof e.includeUntagged!="boolean")throw y("HLP_BIZCAL_INVALID_TAGS","includeUntagged must be a boolean.","tagScope.includeUntagged");return Object.freeze({tags:n,...e.includeUntagged===void 0?{}:{includeUntagged:e.includeUntagged}})}function re(e={}){if(!O(e))throw y("HLP_BIZCAL_INVALID_DEFINITION","A business calendar definition must be an object.");const n=e,o=n.name===void 0?"Business calendar":we(n.name,"name"),a=de(n.locale,"locale",128),i=a===void 0?void 0:te(a),r=We(n.weekend??i?.weekend??[6,7]),t=n.firstDayOfWeek===void 0?i?.firstDay??1:he(n.firstDayOfWeek,"firstDayOfWeek"),d=n.timeZone??"UTC";if(typeof d!="string"||!be(d))throw y("HLP_BIZCAL_INVALID_TIME_ZONE","Unsupported time zone identifier.","timeZone");const l=n.fiscalYearStartMonth??1;if(typeof l!="number"||!Number.isInteger(l)||l<1||l>12)throw y("HLP_BIZCAL_INVALID_FISCAL","fiscalYearStartMonth must be 1-12.","fiscalYearStartMonth");const p=n.fiscalYearNaming??"end";if(p!=="end"&&p!=="start")throw y("HLP_BIZCAL_INVALID_FISCAL","fiscalYearNaming must be end or start.","fiscalYearNaming");const c=n.halfDayValue??.5;if(typeof c!="number"||!Number.isFinite(c)||c<0||c>1)throw y("HLP_BIZCAL_INVALID_HALF_DAY","halfDayValue must be between 0 and 1.","halfDayValue");const m=n.halfDayHours===void 0?void 0:Y(n.halfDayHours,"halfDayHours"),I=Ve(n.workingHours),x=K(n.holidays,"holidays",le).map((u,_)=>$(u,`holidays[${String(_)}]`)),w=K(n.halfDays,"halfDays",le).map((u,_)=>$(u,`halfDays[${String(_)}]`,{forceHalf:!0})),R=K(n.exceptions,"exceptions",Re).map((u,_)=>je(u,`exceptions[${String(_)}]`)),A=new Map;R.forEach((u,_)=>{if(A.has(u.e))throw y("HLP_BIZCAL_DUPLICATE_EXCEPTION","Only one exception per date is allowed.",`exceptions[${String(_)}].date`);A.set(u.e,u)});const B=K(n.providers,"providers",Le).map((u,_)=>{if(!O(u)||typeof u.holidaysFor!="function")throw y("HLP_BIZCAL_INVALID_PROVIDER","A holiday provider needs a holidaysFor(year) function.",`providers[${String(_)}]`);return u}),L=Ze(n.tagScope),P=new Set(r),s=[!1];for(let u=1;u<=7;u++)s.push(!P.has(u));const f=Object.freeze([1,2,3,4,5,6,7].filter(u=>s[u]===!0)),D=[0];for(let u=0;u<7;u++)D.push((D[u]??0)+(s[H(u)]===!0?1:0));const g=I.byDay.map(u=>m??De(u)),h=[...A.keys()].sort((u,_)=>u-_),C=h.filter(u=>A.get(u)?.ex.working===!0),E=Object.freeze(x.map(u=>u.rule)),M=Object.freeze(w.map(u=>u.rule)),k=Object.freeze(R.map(u=>u.ex)),N=Object.freeze([...B]),G=Object.freeze({name:o,weekend:r,firstDayOfWeek:t,holidays:E,halfDays:M,halfDayValue:c,...m===void 0?{}:{halfDayHours:W(m)},exceptions:k,workingHours:I.text,timeZone:d,fiscalYearStartMonth:l,fiscalYearNaming:p,providers:N,...L===void 0?{}:{tagScope:L}}),q={};for(let u=1;u<=7;u++)q[String(u)]=W(I.byDay[u]??[]);const b=Object.freeze({kind:"BusinessCalendar",name:o,weekend:r,workingWeekdays:f,firstDayOfWeek:t,timeZone:d,fiscalYearStartMonth:l,fiscalYearNaming:p,halfDayValue:c,workingHours:Object.freeze(q),holidays:E,halfDays:M,exceptions:k,providers:N,tagScope:L,definition:G});return J.set(b,{cal:b,working:Object.freeze(s),workingCount:f.length,pre:Object.freeze(D),hours:I.byDay,halfHours:Object.freeze(g),zone:d,rules:Object.freeze([...x,...w]),providers:N,scope:L,exceptions:A,exceptionDays:h,workingExceptionDays:C,years:new Map,provided:new Map,occurrences:new Map}),b}function an(e){return typeof e=="object"&&e!==null&&J.has(e)}let ge;function tn(){return ge??=re({name:"Default"}),ge}function sn(e){return te(e).weekend}function Ye(e){return!O(e)||!z(e.tags)?[]:e.tags.filter(n=>typeof n=="string")}function ve(e,n){return Object.freeze({holidaysFor:o=>e.holidaysFor(o).filter(a=>Q(n,Ye(a)))})}function dn(e,n={}){if(!z(e)||e.length===0)throw y("HLP_BIZCAL_INVALID_CALENDAR","mergeCalendars needs at least one calendar.","calendars");const o=e.map(c=>ye(c)),[a]=o;if(!a)throw y("HLP_BIZCAL_INVALID_CALENDAR","mergeCalendars needs at least one calendar.","calendars");const i=a.cal,r=[],t=[],d=[],l=[],p=new Set;for(const c of o){const{cal:m,scope:I}=c,x=w=>Q(I,w.tags??[]);r.push(...m.holidays.filter(x)),t.push(...m.halfDays.filter(x));for(const w of m.providers)d.push(I?ve(w,I):w);for(const w of m.exceptions){const R=se(w.date);p.has(R)||(p.add(R),l.push(w))}}return re({...i.definition,tagScope:void 0,name:e.map(c=>c.name).join(" + "),holidays:r,halfDays:t,providers:d,exceptions:l,...n})}function ln(e,n,o={}){const{cal:a}=ye(e);return re({...a.definition,tagScope:{tags:n,...o.includeUntagged===void 0?{}:{includeUntagged:o.includeUntagged}}})}export{_e as S_FULL,Ee as S_HALF,Ke as S_HOL_WEEKDAY,Ge as S_HOL_WEEKEND,qe as S_NONWORKING_WEEKDAY,Ie as S_PATTERN,Je as S_WORKING_WEEKEND,X as businessCount,Me as businessValue,re as createBusinessCalendar,tn as defaultBusinessCalendar,ye as engineOf,rn as infoAt,an as isBusinessCalendar,dn as mergeCalendars,F as noWorkingDays,Be as patternCount,Te as rangesAt,ne as recordAt,Qe as recordsIn,Pe as specialCounts,en as statusAt,on as stepBackward,nn as stepForward,sn as weekendForLocale,ln as withTags};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instant-level business time: working intervals, working time, business-hour differences and
|
|
3
|
+
* arithmetic, SLA deadlines. Wall-clock hours are converted to instants in the calendar's time
|
|
4
|
+
* zone with `'compatible'` disambiguation (Temporal/RFC 5545): on a DST day an interval lasts
|
|
5
|
+
* its real elapsed time: 09:00-17:00 is unaffected by a 02:00 transition, while 00:00-04:00
|
|
6
|
+
* lasts 3 h on the spring-forward day and 5 h on the fall-back day. Instants are epoch
|
|
7
|
+
* milliseconds.
|
|
8
|
+
*/
|
|
9
|
+
import { type DateInput, type InstantInput } from '../date/index.js';
|
|
10
|
+
import { type BusinessCalendar } from './engine.js';
|
|
11
|
+
/**
|
|
12
|
+
* A half-open instant interval `[start, end)` in epoch milliseconds.
|
|
13
|
+
* @example const i: InstantInterval = { start: Date.UTC(2026, 0, 5, 9), end: Date.UTC(2026, 0, 5, 17) };
|
|
14
|
+
*/
|
|
15
|
+
export interface InstantInterval {
|
|
16
|
+
readonly start: number;
|
|
17
|
+
readonly end: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Working hours of a date as instants in the calendar's time zone (empty on non-working days).
|
|
21
|
+
* @example
|
|
22
|
+
* workingIntervals('2026-10-05'); // => [{ start: Date.UTC(2026, 9, 5, 9), end: Date.UTC(2026, 9, 5, 17) }]
|
|
23
|
+
* workingIntervals('2026-10-03'); // => [] // Saturday
|
|
24
|
+
* @example
|
|
25
|
+
* const london = createBusinessCalendar({ timeZone: 'Europe/London', workingHours: { default: [['09:00', '12:30'], ['13:30', '17:30']] } });
|
|
26
|
+
* workingIntervals('2026-10-05', london); // => [{ start: Date.UTC(2026, 9, 5, 8), end: Date.UTC(2026, 9, 5, 11, 30) }, { start: Date.UTC(2026, 9, 5, 12, 30), end: Date.UTC(2026, 9, 5, 16, 30) }] // BST is UTC+1
|
|
27
|
+
*/
|
|
28
|
+
export declare function workingIntervals(date: DateInput, calendar?: BusinessCalendar): readonly InstantInterval[];
|
|
29
|
+
/**
|
|
30
|
+
* True when an instant falls inside working hours of a business day in the calendar's zone.
|
|
31
|
+
* @example
|
|
32
|
+
* const cal = createBusinessCalendar({ timeZone: 'Europe/London', holidays: [fixedHoliday('Christmas Day', 12, 25)] });
|
|
33
|
+
* isWorkingTime(Date.UTC(2026, 9, 5, 10), cal); // => true // Monday 11:00 in London
|
|
34
|
+
* isWorkingTime(Date.UTC(2026, 9, 5, 16, 30), cal); // => false // 17:30 in London
|
|
35
|
+
* isWorkingTime(Date.UTC(2026, 11, 25, 10), cal); // => false // holiday
|
|
36
|
+
*/
|
|
37
|
+
export declare function isWorkingTime(instant: InstantInput, calendar?: BusinessCalendar): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The instant itself when it is working time, otherwise the start of the next working interval.
|
|
40
|
+
* Throws `HLP_BIZCAL_NO_WORKING_DAYS` when there is no working time within ten years.
|
|
41
|
+
* @example
|
|
42
|
+
* const cal = createBusinessCalendar({ timeZone: 'UTC' });
|
|
43
|
+
* nextWorkingTime(Date.UTC(2026, 9, 3, 12), cal); // => Date.UTC(2026, 9, 5, 9) // Saturday noon → Monday 09:00
|
|
44
|
+
* nextWorkingTime(Date.UTC(2026, 9, 5, 10), cal); // => Date.UTC(2026, 9, 5, 10) // already working time
|
|
45
|
+
* @example
|
|
46
|
+
* const kolkata = createBusinessCalendar({ timeZone: 'Asia/Kolkata' });
|
|
47
|
+
* new Date(nextWorkingTime(Date.UTC(2026, 9, 5, 12), kolkata)).toISOString(); // => '2026-10-06T03:30:00.000Z' // 17:30 Monday → Tuesday 09:00 IST
|
|
48
|
+
*/
|
|
49
|
+
export declare function nextWorkingTime(instant: InstantInput, calendar?: BusinessCalendar): number;
|
|
50
|
+
/** Options for `diffBusinessHours`. */
|
|
51
|
+
export interface DiffBusinessHoursOptions {
|
|
52
|
+
/** Default `'hours'` (fractional); `'milliseconds'` for exact integer arithmetic. */
|
|
53
|
+
readonly unit?: 'hours' | 'milliseconds';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Working time between two instants (real elapsed time inside working intervals, DST-correct),
|
|
57
|
+
* negative when `end` is before `start`. Ranges may span at most 100 years.
|
|
58
|
+
* @example
|
|
59
|
+
* const cal = createBusinessCalendar({ timeZone: 'UTC', workingHours: { default: [['09:00', '17:00']] } });
|
|
60
|
+
* diffBusinessHours(Date.UTC(2026, 9, 2, 15), Date.UTC(2026, 9, 5, 11), cal); // => 4 // Fri 15-17 + Mon 9-11
|
|
61
|
+
* diffBusinessHours(Date.UTC(2026, 9, 5, 11), Date.UTC(2026, 9, 2, 15), cal); // => -4
|
|
62
|
+
* diffBusinessHours(Date.UTC(2026, 9, 2, 15), Date.UTC(2026, 9, 2, 15, 30), cal, { unit: 'milliseconds' }); // => 1800000
|
|
63
|
+
*/
|
|
64
|
+
export declare function diffBusinessHours(start: InstantInput, end: InstantInput, calendar?: BusinessCalendar, options?: DiffBusinessHoursOptions): number;
|
|
65
|
+
/**
|
|
66
|
+
* Adds working time to an instant (negative subtracts), skipping non-working time. A result
|
|
67
|
+
* that lands exactly on the end of an interval stays there (17:00, not the next 09:00). Zero
|
|
68
|
+
* returns the instant unchanged.
|
|
69
|
+
* @example
|
|
70
|
+
* const cal = createBusinessCalendar({ timeZone: 'UTC' });
|
|
71
|
+
* addBusinessHours(Date.UTC(2026, 9, 2, 15), 4, cal); // => Date.UTC(2026, 9, 5, 11) // Friday 15:00 → Monday 11:00
|
|
72
|
+
* addBusinessHours(Date.UTC(2026, 9, 2, 15), 2, cal); // => Date.UTC(2026, 9, 2, 17) // ends exactly at 17:00
|
|
73
|
+
* addBusinessHours(Date.UTC(2026, 9, 5, 10), -2, cal); // => Date.UTC(2026, 9, 2, 16) // back into Friday
|
|
74
|
+
*/
|
|
75
|
+
export declare function addBusinessHours(instant: InstantInput, hours: number, calendar?: BusinessCalendar): number;
|
|
76
|
+
/**
|
|
77
|
+
* An SLA target: working hours, or business days (due at the end of the working day).
|
|
78
|
+
* @example const target: SlaTarget = { businessHours: 8 };
|
|
79
|
+
*/
|
|
80
|
+
export type SlaTarget = {
|
|
81
|
+
readonly businessHours: number;
|
|
82
|
+
} | {
|
|
83
|
+
readonly businessDays: number;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Deadline for an SLA started at `start`. `{ businessHours }` adds working time
|
|
87
|
+
* (`addBusinessHours`). `{ businessDays: n }` is due at the end of the last working interval of
|
|
88
|
+
* the `n`-th business day after the start's local date (`n = 0`: that date, or the next
|
|
89
|
+
* business day); a business day without hours is due at the end of the day.
|
|
90
|
+
* @example
|
|
91
|
+
* const cal = createBusinessCalendar({ timeZone: 'UTC', holidays: [fixedHoliday('Christmas Day', 12, 25)] });
|
|
92
|
+
* slaDeadline(Date.UTC(2026, 9, 2, 16), { businessDays: 1 }, cal); // => Date.UTC(2026, 9, 5, 17) // Friday → end of Monday
|
|
93
|
+
* slaDeadline(Date.UTC(2026, 9, 2, 16), { businessHours: 4 }, cal); // => Date.UTC(2026, 9, 5, 12) // 1 h Friday + 3 h Monday
|
|
94
|
+
* slaDeadline(Date.UTC(2026, 11, 24, 16), { businessHours: 4 }, cal); // => Date.UTC(2026, 11, 28, 12) // skips Christmas and the weekend
|
|
95
|
+
*/
|
|
96
|
+
export declare function slaDeadline(start: InstantInput, target: SlaTarget, calendar?: BusinessCalendar): number;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{endOfDayInstant as v,fromEpochDay as N,plainDateFromInstant as z,plainDateTime as S,timeFromMilliseconds as Z,toEpochDay as B,toPlainDate as V}from"../date/index.js";import{toEpochMs as h}from"../date/zone.js";import{offsetAt as H,zonedToInstant as k}from"../timezone/index.js";import{defaultBusinessCalendar as y,engineOf as _,noWorkingDays as T,rangesAt as F,statusAt as O,stepForward as Y}from"./engine.js";import{DAY_MS as C,MINUTE_MS as x,invalid as D,limit as P}from"./internal.js";const M=36e5,g=366*100,w=3660;function E(s,n,o){const t=n+Math.floor(o/1440);return k(S(N(t),Z(o%1440*x)),s,{disambiguation:"compatible"})}function A(s,n){if(O(s,n)===0)return[];const o=F(s,n);if(o.length===0)return[];const t=n*C,r=H(t-14*M,s.zone),e=H(t+C+14*M,s.zone);if(r===e)return o.map(([u,f])=>[t+u*x-r,t+f*x-r]);const a=[];let i=Number.NEGATIVE_INFINITY;for(const[u,f]of o){const m=Math.max(E(s.zone,n,u),i),c=Math.max(E(s.zone,n,f),m);c>m&&a.push([m,c]),i=c}return a}const L=(s,n)=>B(z(n,s.zone));function q(s,n=y()){const o=_(n);return Object.freeze(A(o,B(V(s))).map(([t,r])=>Object.freeze({start:t,end:r})))}function J(s,n=y()){const o=_(n),t=h(s);return A(o,L(o,t)).some(([r,e])=>t>=r&&t<e)}function K(s,n=y()){const o=_(n),t=h(s),r=L(o,t);for(let e=0;e<=w;e++)for(const[a,i]of A(o,r+e))if(i>t)return Math.max(a,t);return T()}function Q(s,n,o=y(),t={}){const r=_(o),e=h(s),a=h(n),i=t.unit??"hours";if(i!=="hours"&&i!=="milliseconds")throw D("HLP_BIZCAL_INVALID_OPTION","unit must be hours or milliseconds.","unit");const u=Math.min(e,a),f=Math.max(e,a),m=L(r,u),c=L(r,f);if(c-m>g)throw P("HLP_BIZCAL_RANGE_LIMIT","The range spans too many days.",g);let d=0;for(let l=m;l<=c;l++)for(const[b,p]of A(r,l))d+=Math.max(0,Math.min(p,f)-Math.max(b,u));const I=i==="hours"?d/M:d;return I===0?0:a>=e?I:-I}function j(s,n,o=y()){const t=_(o),r=h(s);if(typeof n!="number"||!Number.isFinite(n))throw D("HLP_BIZCAL_INVALID_OPTION","hours must be a finite number.","hours");let e=Math.round(Math.abs(n)*M);if(e===0)return r;const a=n>0,i=L(t,r);let u=0;for(let f=0;f<=g;f++){const m=a?i+f:i-f,c=A(t,m);let d=!1;if(a)for(const[I,l]of c){const b=Math.max(I,r);if(!(l<=b)){if(d=!0,e<=l-b)return b+e;e-=l-b}}else for(let I=c.length-1;I>=0;I--){const[l,b]=c[I]??[0,0],p=Math.min(b,r);if(!(p<=l)){if(d=!0,e<=p-l)return p-e;e-=p-l}}u=d?0:u+1,u>w&&T()}throw P("HLP_BIZCAL_RANGE_LIMIT","The result is too far away.",g)}function $(s,n,o=y()){const t=_(o),r=h(s),e=n;if(typeof e!="object"||e===null)throw D("HLP_BIZCAL_INVALID_OPTION","Expected { businessHours } or { businessDays }.","target");const a="businessHours"in n?n.businessHours:void 0,i="businessDays"in n?n.businessDays:void 0;if(a===void 0==(i===void 0))throw D("HLP_BIZCAL_INVALID_OPTION","Expected exactly one of businessHours or businessDays.","target");if(a!==void 0){if(typeof a!="number"||!(a>=0))throw D("HLP_BIZCAL_INVALID_OPTION","businessHours must be a non-negative number.","businessHours");return j(r,a,o)}if(typeof i!="number"||!Number.isInteger(i)||i<0)throw D("HLP_BIZCAL_INVALID_OPTION","businessDays must be a non-negative integer.","businessDays");const u=L(t,r),f=i===0&&O(t,u)!==0?u:Y(t,u,Math.max(i,1)),m=A(t,f),c=m[m.length-1];return c?c[1]:v(N(f),t.zone)}export{j as addBusinessHours,Q as diffBusinessHours,J as isWorkingTime,K as nextWorkingTime,$ as slaDeadline,q as workingIntervals};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@absoluteui/helpers/business-calendar` (docs/PLAN-HELPERS.md section 4): weekends, holidays,
|
|
3
|
+
* business days, business hours, and day differences on an immutable calendar.
|
|
4
|
+
*
|
|
5
|
+
* Conventions
|
|
6
|
+
* - Dates are `DateInput` (`PlainDate | 'YYYY-MM-DD'`) and all day logic is date-only; instants
|
|
7
|
+
* (`number | Date`) are converted in the calendar's `timeZone` (default `'UTC'`).
|
|
8
|
+
* - The calendar argument comes after the dates and is optional: the shared default is a
|
|
9
|
+
* Saturday/Sunday weekend without holidays, 09:00-17:00, UTC (`defaultBusinessCalendar()`).
|
|
10
|
+
* - Precedence for a date: exception, then full holiday, then half-day holiday (working
|
|
11
|
+
* weekdays only), then the weekday pattern.
|
|
12
|
+
* - Half days are business days for navigation (`addBusinessDays`) and count `halfDayValue`
|
|
13
|
+
* (default 0.5, B2) in business-day totals.
|
|
14
|
+
* - Differences are signed; `inclusive` defaults to `'start'` ([earlier, later)), so calendar
|
|
15
|
+
* mode equals `daysBetween`; pass `inclusive: 'both'` for leave requests (see `Inclusivity`).
|
|
16
|
+
* Week, month, quarter, and year differences stay calendar-based (B1): use the date module.
|
|
17
|
+
* - No holiday data ships (B4): supply rules or a `HolidayProvider`.
|
|
18
|
+
*/
|
|
19
|
+
export { createBusinessCalendar, defaultBusinessCalendar, isBusinessCalendar, mergeCalendars, weekendForLocale, withTags } from './engine.js';
|
|
20
|
+
export type { BusinessCalendar, BusinessCalendarDefinition, BusinessDayException, BusinessDayInfo, BusinessDayReasonCode, TagScope, WorkingHoursDefinition } from './engine.js';
|
|
21
|
+
export { customHoliday, defineHolidays, easterHoliday, easterSunday, fixedHoliday, holidayRange, lastWeekdayHoliday, nthWeekdayHoliday, oneOffHoliday } from './rules.js';
|
|
22
|
+
export type { CustomHolidayRule, EasterHolidayRule, FixedHolidayRule, HolidayKind, HolidayProvider, HolidayRule, HolidayRuleBase, HolidayRuleOptions, HolidayYearBounds, NthWeekdayHolidayRule, ObservedPolicy, ObservedShiftMap, OneOffHolidayRule, ProvidedHoliday, RangeHolidayRule, ResolvedHoliday, } from './rules.js';
|
|
23
|
+
export type { TimeRange } from './internal.js';
|
|
24
|
+
export { addBusinessDays, adjustBusinessDay, businessDayAt, businessDayOfMonth, businessDaysIn, countBusinessDays, countHolidays, countWeekdays, countWeekends, diffBreakdown, diffDays, firstBusinessDayOfMonth, getBusinessDay, holidaysOn, isBusinessDay, isHalfDay, isHoliday, isWeekday, isWeekend, lastBusinessDayOfMonth, listBusinessDays, listHolidays, nextBusinessDay, nthBusinessDayOfMonth, periodRange, previousBusinessDay, } from './days.js';
|
|
25
|
+
export type { AddBusinessDaysOptions, BusinessDayConvention, BusinessPeriod, CountOptions, DiffBreakdown, DiffDaysOptions, DiffMode, HolidayCount, Inclusivity, ListBusinessDaysOptions, NextBusinessDayOptions } from './days.js';
|
|
26
|
+
export { addBusinessHours, diffBusinessHours, isWorkingTime, nextWorkingTime, slaDeadline, workingIntervals } from './hours.js';
|
|
27
|
+
export type { DiffBusinessHoursOptions, InstantInterval, SlaTarget } from './hours.js';
|
|
28
|
+
export { DEFAULT_BUSINESS_DAY_LABELS, describeBusinessDay } from './describe.js';
|
|
29
|
+
export type { BusinessDayLabels, DescribeBusinessDayOptions } from './describe.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{createBusinessCalendar as i,defaultBusinessCalendar as a,isBusinessCalendar as n,mergeCalendars as o,weekendForLocale as d,withTags as t}from"./engine.js";import{customHoliday as r,defineHolidays as u,easterHoliday as l,easterSunday as f,fixedHoliday as D,holidayRange as B,lastWeekdayHoliday as p,nthWeekdayHoliday as H,oneOffHoliday as O}from"./rules.js";import{addBusinessDays as x,adjustBusinessDay as R,businessDayAt as c,businessDayOfMonth as g,businessDaysIn as k,countBusinessDays as h,countHolidays as C,countWeekdays as v,countWeekends as W,diffBreakdown as b,diffDays as S,firstBusinessDayOfMonth as j,getBusinessDay as I,holidaysOn as T,isBusinessDay as L,isHalfDay as M,isHoliday as w,isWeekday as A,isWeekend as E,lastBusinessDayOfMonth as P,listBusinessDays as F,listHolidays as N,nextBusinessDay as _,nthBusinessDayOfMonth as U,periodRange as Y,previousBusinessDay as K}from"./days.js";import{addBusinessHours as z,diffBusinessHours as G,isWorkingTime as J,nextWorkingTime as Q,slaDeadline as V,workingIntervals as X}from"./hours.js";import{DEFAULT_BUSINESS_DAY_LABELS as $,describeBusinessDay as ss}from"./describe.js";export{$ as DEFAULT_BUSINESS_DAY_LABELS,x as addBusinessDays,z as addBusinessHours,R as adjustBusinessDay,c as businessDayAt,g as businessDayOfMonth,k as businessDaysIn,h as countBusinessDays,C as countHolidays,v as countWeekdays,W as countWeekends,i as createBusinessCalendar,r as customHoliday,a as defaultBusinessCalendar,u as defineHolidays,ss as describeBusinessDay,b as diffBreakdown,G as diffBusinessHours,S as diffDays,l as easterHoliday,f as easterSunday,j as firstBusinessDayOfMonth,D as fixedHoliday,I as getBusinessDay,B as holidayRange,T as holidaysOn,n as isBusinessCalendar,L as isBusinessDay,M as isHalfDay,w as isHoliday,A as isWeekday,E as isWeekend,J as isWorkingTime,P as lastBusinessDayOfMonth,p as lastWeekdayHoliday,F as listBusinessDays,N as listHolidays,o as mergeCalendars,_ as nextBusinessDay,Q as nextWorkingTime,U as nthBusinessDayOfMonth,H as nthWeekdayHoliday,O as oneOffHoliday,Y as periodRange,K as previousBusinessDay,V as slaDeadline,d as weekendForLocale,t as withTags,X as workingIntervals};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal helpers for the business-calendar module: time-of-day parsing, epoch-day weekday
|
|
3
|
+
* math, binary search, and error construction. Not part of the public API.
|
|
4
|
+
*/
|
|
5
|
+
import { LimitError, ValidationError } from '../error/index.js';
|
|
6
|
+
import { type IsoWeekday } from '../date/index.js';
|
|
7
|
+
export declare const DAY_MS = 86400000;
|
|
8
|
+
export declare const MINUTE_MS = 60000;
|
|
9
|
+
/**
|
|
10
|
+
* A working-time interval as `['HH:mm', 'HH:mm']`; start inclusive, end exclusive, `'24:00'`
|
|
11
|
+
* allowed as an end.
|
|
12
|
+
* @example const morning: TimeRange = ['09:00', '13:00'];
|
|
13
|
+
*/
|
|
14
|
+
export type TimeRange = readonly [start: string, end: string];
|
|
15
|
+
/** Internal form of a `TimeRange`: minutes since midnight, end up to 1440. */
|
|
16
|
+
export type MinuteRange = readonly [start: number, end: number];
|
|
17
|
+
/** A `ValidationError` whose details carry only a fixed property path, never user values. */
|
|
18
|
+
export declare function invalid(code: string, message: string, property?: string): ValidationError;
|
|
19
|
+
/** A `LimitError` with a fixed limit in its details. */
|
|
20
|
+
export declare function limit(code: string, message: string, max: number): LimitError;
|
|
21
|
+
export declare const isArray: (value: unknown) => value is readonly unknown[];
|
|
22
|
+
export declare const isRecord: (value: unknown) => value is Readonly<Record<string, unknown>>;
|
|
23
|
+
/** ISO weekday of an epoch day (1970-01-01 was a Thursday). */
|
|
24
|
+
export declare const weekdayOfEpoch: (e: number) => IsoWeekday;
|
|
25
|
+
/** Epoch day of a (valid) calendar date without allocating a frozen `PlainDate`. */
|
|
26
|
+
export declare const epochOf: (year: number, month: number, day: number) => number;
|
|
27
|
+
/** Minutes since midnight for `HH:mm`; `'24:00'` -> 1440 only when `allow24`. */
|
|
28
|
+
export declare function parseTime(text: unknown, allow24: boolean): number | undefined;
|
|
29
|
+
/** `HH:mm` for minutes since midnight (1440 -> `'24:00'`). */
|
|
30
|
+
export declare function formatMinutes(minutes: number): string;
|
|
31
|
+
/** Validates `TimeRange[]`: `HH:mm`, end after start, sorted, non-overlapping (touching is fine). */
|
|
32
|
+
export declare function normalizeRanges(value: unknown, property: string): readonly MinuteRange[];
|
|
33
|
+
/** Public `TimeRange[]` for internal minute ranges. */
|
|
34
|
+
export declare function rangesToText(ranges: readonly MinuteRange[]): readonly TimeRange[];
|
|
35
|
+
/** First half (by working minutes) of a day's intervals: the default half-day hours. */
|
|
36
|
+
export declare function firstHalf(ranges: readonly MinuteRange[]): readonly MinuteRange[];
|
|
37
|
+
/** Index of the first element >= `x` in an ascending array. */
|
|
38
|
+
export declare function lowerBound(sorted: readonly number[], x: number): number;
|
|
39
|
+
/** Index of the first element > `x` in an ascending array. */
|
|
40
|
+
export declare function upperBound(sorted: readonly number[], x: number): number;
|
|
41
|
+
/** Validates an optional short text field (name, id, reason). */
|
|
42
|
+
export declare function optionalText(value: unknown, property: string, max?: number): string | undefined;
|
|
43
|
+
/** Validates a required non-blank name. */
|
|
44
|
+
export declare function requiredName(value: unknown, property: string): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as g,ValidationError as h}from"../error/index.js";import{toEpochDay as p}from"../date/index.js";const I=864e5,L=6e4;function u(n,t,e){return new h(n,t,e===void 0?{}:{details:{property:e}})}function b(n,t,e){return new g(n,t,{details:{limit:e}})}const f=n=>Array.isArray(n),x=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),k=n=>((n+3)%7+7)%7+1,R=(n,t,e)=>p({kind:"PlainDate",year:n,month:t,day:e}),_=/^(\d{2}):(\d{2})$/;function c(n,t){if(typeof n!="string"||n.length!==5)return;const e=_.exec(n);if(!e)return;const o=Number(e[1]),r=Number(e[2]);if(o===24&&r===0)return t?1440:void 0;if(!(o>23||r>59))return o*60+r}function m(n){const t=e=>String(e).padStart(2,"0");return`${t(Math.floor(n/60))}:${t(n%60)}`}const l=48;function M(n,t){if(!f(n))throw u("HLP_BIZCAL_INVALID_HOURS","Working hours must be an array of [start, end] pairs.",t);if(n.length>l)throw b("HLP_BIZCAL_TOO_MANY_RANGES","Too many working-hour intervals in one day.",l);const e=[];let o=-1;return n.forEach((r,s)=>{const i=`${t}[${String(s)}]`;if(!f(r)||r.length!==2)throw u("HLP_BIZCAL_INVALID_HOURS","Each working-hours entry must be a [start, end] pair.",i);const a=c(r[0],!1),d=c(r[1],!0);if(a===void 0||d===void 0)throw u("HLP_BIZCAL_INVALID_HOURS","Working hours must use HH:mm (24:00 is allowed as an end).",i);if(d<=a)throw u("HLP_BIZCAL_INVALID_HOURS","A working-hours end must be after its start.",i);if(a<o)throw u("HLP_BIZCAL_INVALID_HOURS","Working hours must be sorted and must not overlap.",i);o=d,e.push(Object.freeze([a,d]))}),Object.freeze(e)}function H(n){return Object.freeze(n.map(([t,e])=>Object.freeze([m(t),m(e)])))}function E(n){const t=n.reduce((r,[s,i])=>r+i-s,0);let e=Math.round(t/2);const o=[];for(const[r,s]of n){if(e<=0)break;const i=Math.min(s-r,e);o.push(Object.freeze([r,r+i])),e-=i}return Object.freeze(o)}function N(n,t){let e=0,o=n.length;for(;e<o;){const r=e+o>>>1;(n[r]??0)<t?e=r+1:o=r}return e}function O(n,t){let e=0,o=n.length;for(;e<o;){const r=e+o>>>1;(n[r]??0)<=t?e=r+1:o=r}return e}function y(n,t,e=256){if(n!==void 0){if(typeof n!="string"||n.length>e)throw u("HLP_BIZCAL_INVALID_TEXT","Expected a string of at most 256 characters.",t);return n}}function S(n,t){const e=y(n,t);if(e===void 0||e.trim()==="")throw u("HLP_BIZCAL_INVALID_NAME","A non-empty name is required.",t);return e}export{I as DAY_MS,L as MINUTE_MS,R as epochOf,E as firstHalf,m as formatMinutes,u as invalid,f as isArray,x as isRecord,b as limit,N as lowerBound,M as normalizeRanges,y as optionalText,c as parseTime,H as rangesToText,S as requiredName,O as upperBound,k as weekdayOfEpoch};
|