@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,339 @@
|
|
|
1
|
+
import { type DateInput, type IsoWeekday, type PlainDate } from './plain-date.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an ISO weekday option (1 = Monday ... 7 = Sunday).
|
|
4
|
+
* @example
|
|
5
|
+
* const weekday: number = 7; // e.g. from a form field
|
|
6
|
+
* assertIsoWeekday(weekday, 'weekday'); // narrows to IsoWeekday
|
|
7
|
+
* weekdayName(weekday, { locale: 'en' }); // => 'Sunday'
|
|
8
|
+
* assertIsoWeekday(0, 'weekday'); // => throws HLP_DATE_INVALID_WEEKDAY
|
|
9
|
+
*/
|
|
10
|
+
export declare function assertIsoWeekday(value: number, property?: string): asserts value is IsoWeekday;
|
|
11
|
+
export interface WeekOptions {
|
|
12
|
+
/** First day of the week, ISO numbering. Default 1 (Monday, ISO 8601). Use `getWeekInfo(locale).firstDay` for locale conventions. */
|
|
13
|
+
readonly firstDayOfWeek?: IsoWeekday;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Adds weeks (negative subtracts).
|
|
17
|
+
* @example addWeeks('2026-01-01', 2) // => '2026-01-15'
|
|
18
|
+
*/
|
|
19
|
+
export declare function addWeeks(date: DateInput, weeks: number): PlainDate;
|
|
20
|
+
/**
|
|
21
|
+
* Adds calendar months, clamping to the target month's last day (Jan 31 + 1 month = Feb 28/29).
|
|
22
|
+
* @example addMonths('2024-01-31', 1) // => '2024-02-29'
|
|
23
|
+
*/
|
|
24
|
+
export declare function addMonths(date: DateInput, months: number): PlainDate;
|
|
25
|
+
/**
|
|
26
|
+
* Adds quarters (3 months each, month-end clamped).
|
|
27
|
+
* @example addQuarters('2026-11-30', 1) // => '2027-02-28'
|
|
28
|
+
*/
|
|
29
|
+
export declare function addQuarters(date: DateInput, quarters: number): PlainDate;
|
|
30
|
+
/**
|
|
31
|
+
* Adds years; Feb 29 clamps to Feb 28 in non-leap years.
|
|
32
|
+
* @example addYears('2024-02-29', 1) // => '2025-02-28'
|
|
33
|
+
*/
|
|
34
|
+
export declare function addYears(date: DateInput, years: number): PlainDate;
|
|
35
|
+
/**
|
|
36
|
+
* Subtracts days.
|
|
37
|
+
* @example subDays('2026-03-01', 1) // => '2026-02-28'
|
|
38
|
+
*/
|
|
39
|
+
export declare function subDays(date: DateInput, days: number): PlainDate;
|
|
40
|
+
/**
|
|
41
|
+
* Subtracts weeks.
|
|
42
|
+
* @example subWeeks('2026-01-15', 2) // => '2026-01-01'
|
|
43
|
+
*/
|
|
44
|
+
export declare function subWeeks(date: DateInput, weeks: number): PlainDate;
|
|
45
|
+
/**
|
|
46
|
+
* Subtracts months (month-end clamped).
|
|
47
|
+
* @example subMonths('2026-03-31', 1) // => '2026-02-28'
|
|
48
|
+
*/
|
|
49
|
+
export declare function subMonths(date: DateInput, months: number): PlainDate;
|
|
50
|
+
/**
|
|
51
|
+
* Subtracts quarters.
|
|
52
|
+
* @example subQuarters('2026-05-31', 1) // => '2026-02-28'
|
|
53
|
+
*/
|
|
54
|
+
export declare function subQuarters(date: DateInput, quarters: number): PlainDate;
|
|
55
|
+
/**
|
|
56
|
+
* Subtracts years.
|
|
57
|
+
* @example subYears('2028-02-29', 1) // => '2027-02-28'
|
|
58
|
+
*/
|
|
59
|
+
export declare function subYears(date: DateInput, years: number): PlainDate;
|
|
60
|
+
/**
|
|
61
|
+
* First day of the week containing `date`.
|
|
62
|
+
* @example startOfWeek('2026-09-30', { firstDayOfWeek: 7 }) // => '2026-09-27' // Sunday
|
|
63
|
+
*/
|
|
64
|
+
export declare function startOfWeek(date: DateInput, options?: WeekOptions): PlainDate;
|
|
65
|
+
/**
|
|
66
|
+
* Last day of the week containing `date`.
|
|
67
|
+
* @example endOfWeek('2026-09-30') // => '2026-10-04' // Sunday
|
|
68
|
+
*/
|
|
69
|
+
export declare function endOfWeek(date: DateInput, options?: WeekOptions): PlainDate;
|
|
70
|
+
/**
|
|
71
|
+
* First day of the month.
|
|
72
|
+
* @example startOfMonth('2026-09-29') // => '2026-09-01'
|
|
73
|
+
*/
|
|
74
|
+
export declare function startOfMonth(date: DateInput): PlainDate;
|
|
75
|
+
/**
|
|
76
|
+
* Last day of the month.
|
|
77
|
+
* @example endOfMonth('2024-02-10') // => '2024-02-29'
|
|
78
|
+
*/
|
|
79
|
+
export declare function endOfMonth(date: DateInput): PlainDate;
|
|
80
|
+
/**
|
|
81
|
+
* Calendar quarter (1-4; Q1 = January to March).
|
|
82
|
+
* @example quarterOf('2026-09-29') // => 3
|
|
83
|
+
*/
|
|
84
|
+
export declare function quarterOf(date: DateInput): 1 | 2 | 3 | 4;
|
|
85
|
+
/**
|
|
86
|
+
* First day of the calendar quarter.
|
|
87
|
+
* @example startOfQuarter('2026-09-29') // => '2026-07-01'
|
|
88
|
+
*/
|
|
89
|
+
export declare function startOfQuarter(date: DateInput): PlainDate;
|
|
90
|
+
/**
|
|
91
|
+
* Last day of the calendar quarter.
|
|
92
|
+
* @example endOfQuarter('2026-09-29') // => '2026-09-30'
|
|
93
|
+
*/
|
|
94
|
+
export declare function endOfQuarter(date: DateInput): PlainDate;
|
|
95
|
+
/**
|
|
96
|
+
* January 1 of the year.
|
|
97
|
+
* @example startOfYear('2026-09-29') // => '2026-01-01'
|
|
98
|
+
*/
|
|
99
|
+
export declare function startOfYear(date: DateInput): PlainDate;
|
|
100
|
+
/**
|
|
101
|
+
* December 31 of the year.
|
|
102
|
+
* @example endOfYear('2026-09-29') // => '2026-12-31'
|
|
103
|
+
*/
|
|
104
|
+
export declare function endOfYear(date: DateInput): PlainDate;
|
|
105
|
+
/**
|
|
106
|
+
* Fiscal-year options. Naming convention: a fiscal year is labelled by the calendar year in
|
|
107
|
+
* which it **ends** (default `naming: 'end'`; US federal FY2027 = Oct 2026 - Sep 2027, India
|
|
108
|
+
* April 2026 - March 2027 = FY2027). `naming: 'start'` labels by the starting year. With
|
|
109
|
+
* `startMonth: 1` both conventions give the calendar year. Quarters are numbered from the
|
|
110
|
+
* fiscal start: Q1 is the first three months of the fiscal year.
|
|
111
|
+
*/
|
|
112
|
+
export interface FiscalYearOptions {
|
|
113
|
+
/** Month the fiscal year starts in, 1-12. Default 1 (calendar year). */
|
|
114
|
+
readonly startMonth?: number;
|
|
115
|
+
/** Which calendar year names the fiscal year. Default `'end'`. */
|
|
116
|
+
readonly naming?: 'end' | 'start';
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* First day of the fiscal year containing `date`.
|
|
120
|
+
* @example startOfFiscalYear('2026-09-29', { startMonth: 4 }) // => '2026-04-01'
|
|
121
|
+
*/
|
|
122
|
+
export declare function startOfFiscalYear(date: DateInput, options?: FiscalYearOptions): PlainDate;
|
|
123
|
+
/**
|
|
124
|
+
* Last day of the fiscal year containing `date`.
|
|
125
|
+
* @example endOfFiscalYear('2026-09-29', { startMonth: 4 }) // => '2027-03-31'
|
|
126
|
+
*/
|
|
127
|
+
export declare function endOfFiscalYear(date: DateInput, options?: FiscalYearOptions): PlainDate;
|
|
128
|
+
/**
|
|
129
|
+
* Fiscal year number (see `FiscalYearOptions` for the naming convention).
|
|
130
|
+
* @example fiscalYearOf('2026-09-29', { startMonth: 4 }) // => 2027
|
|
131
|
+
*/
|
|
132
|
+
export declare function fiscalYearOf(date: DateInput, options?: FiscalYearOptions): number;
|
|
133
|
+
/**
|
|
134
|
+
* Fiscal quarter 1-4, counted from the fiscal start month.
|
|
135
|
+
* @example fiscalQuarterOf('2026-09-29', { startMonth: 4 }) // => 2
|
|
136
|
+
*/
|
|
137
|
+
export declare function fiscalQuarterOf(date: DateInput, options?: FiscalYearOptions): 1 | 2 | 3 | 4;
|
|
138
|
+
/**
|
|
139
|
+
* First day of the fiscal quarter containing `date`.
|
|
140
|
+
* @example startOfFiscalQuarter('2026-09-29', { startMonth: 4 }) // => '2026-07-01'
|
|
141
|
+
*/
|
|
142
|
+
export declare function startOfFiscalQuarter(date: DateInput, options?: FiscalYearOptions): PlainDate;
|
|
143
|
+
/**
|
|
144
|
+
* Last day of the fiscal quarter containing `date`.
|
|
145
|
+
* @example endOfFiscalQuarter('2026-09-29', { startMonth: 4 }) // => '2026-09-30'
|
|
146
|
+
*/
|
|
147
|
+
export declare function endOfFiscalQuarter(date: DateInput, options?: FiscalYearOptions): PlainDate;
|
|
148
|
+
export interface FiscalLabelOptions extends FiscalYearOptions {
|
|
149
|
+
/** Default `'FY'`. */
|
|
150
|
+
readonly prefix?: string;
|
|
151
|
+
/** `'year'` -> `FY2027` (default); `'span'` -> `FY2026-27` (start year, two-digit end year). */
|
|
152
|
+
readonly style?: 'year' | 'span';
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Fiscal-year label such as `FY2027` or `FY2026-27`.
|
|
156
|
+
* @example fiscalYearLabel('2026-09-29', { startMonth: 4 }) // => 'FY2027'
|
|
157
|
+
*/
|
|
158
|
+
export declare function fiscalYearLabel(date: DateInput, options?: FiscalLabelOptions): string;
|
|
159
|
+
/**
|
|
160
|
+
* Fiscal-quarter label `Q1`-`Q4`.
|
|
161
|
+
* @example fiscalQuarterLabel('2026-09-29', { startMonth: 4 }) // => 'Q2'
|
|
162
|
+
*/
|
|
163
|
+
export declare function fiscalQuarterLabel(date: DateInput, options?: FiscalYearOptions): string;
|
|
164
|
+
/**
|
|
165
|
+
* Same calendar day.
|
|
166
|
+
* @example isSameDay('2026-01-01', plainDate(2026, 1, 1)) // => true
|
|
167
|
+
*/
|
|
168
|
+
export declare function isSameDay(a: DateInput, b: DateInput): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Same week (weeks start on `firstDayOfWeek`, default Monday).
|
|
171
|
+
* @example isSameWeek('2026-09-28', '2026-10-04') // => true
|
|
172
|
+
*/
|
|
173
|
+
export declare function isSameWeek(a: DateInput, b: DateInput, options?: WeekOptions): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Same month of the same year.
|
|
176
|
+
* @example isSameMonth('2026-09-01', '2026-09-30') // => true
|
|
177
|
+
*/
|
|
178
|
+
export declare function isSameMonth(a: DateInput, b: DateInput): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Same calendar quarter of the same year.
|
|
181
|
+
* @example isSameQuarter('2026-07-01', '2026-09-30') // => true
|
|
182
|
+
*/
|
|
183
|
+
export declare function isSameQuarter(a: DateInput, b: DateInput): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Same calendar year.
|
|
186
|
+
* @example isSameYear('2026-01-01', '2026-12-31') // => true
|
|
187
|
+
*/
|
|
188
|
+
export declare function isSameYear(a: DateInput, b: DateInput): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* `a` is strictly before `b`.
|
|
191
|
+
* @example isBefore('2026-01-01', '2026-01-02') // => true
|
|
192
|
+
*/
|
|
193
|
+
export declare function isBefore(a: DateInput, b: DateInput): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* `a` is strictly after `b`.
|
|
196
|
+
* @example isAfter('2026-01-02', '2026-01-01') // => true
|
|
197
|
+
*/
|
|
198
|
+
export declare function isAfter(a: DateInput, b: DateInput): boolean;
|
|
199
|
+
/** Which endpoints count as inside a range. */
|
|
200
|
+
export type Inclusivity = 'both' | 'none' | 'start' | 'end';
|
|
201
|
+
/**
|
|
202
|
+
* `start <= date <= end` by default; `inclusive` controls the endpoints. Throws
|
|
203
|
+
* `HLP_DATE_INVALID_INTERVAL` when `end` is before `start`.
|
|
204
|
+
* @example isBetween('2026-01-31', '2026-01-01', '2026-01-31', { inclusive: 'start' }) // => false
|
|
205
|
+
*/
|
|
206
|
+
export declare function isBetween(date: DateInput, start: DateInput, end: DateInput, options?: {
|
|
207
|
+
readonly inclusive?: Inclusivity;
|
|
208
|
+
}): boolean;
|
|
209
|
+
/**
|
|
210
|
+
* `date` is today in `timeZone` (default: runtime zone).
|
|
211
|
+
* @example isToday(today('Asia/Kolkata'), 'Asia/Kolkata') // => true
|
|
212
|
+
*/
|
|
213
|
+
export declare function isToday(date: DateInput, timeZone?: string): boolean;
|
|
214
|
+
/**
|
|
215
|
+
* `date` is before today in `timeZone`.
|
|
216
|
+
* @example isPast('2000-01-01') // => true
|
|
217
|
+
*/
|
|
218
|
+
export declare function isPast(date: DateInput, timeZone?: string): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* `date` is after today in `timeZone`.
|
|
221
|
+
* @example isFuture('2999-01-01') // => true
|
|
222
|
+
*/
|
|
223
|
+
export declare function isFuture(date: DateInput, timeZone?: string): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Earliest date, or `undefined` for none.
|
|
226
|
+
* @example minDate(['2026-02-01', '2026-01-01']) // => '2026-01-01'
|
|
227
|
+
*/
|
|
228
|
+
export declare function minDate(dates: Iterable<DateInput>): PlainDate | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* Latest date, or `undefined` for none.
|
|
231
|
+
* @example maxDate(['2026-02-01', '2026-01-01']) // => '2026-02-01'
|
|
232
|
+
*/
|
|
233
|
+
export declare function maxDate(dates: Iterable<DateInput>): PlainDate | undefined;
|
|
234
|
+
/**
|
|
235
|
+
* Clamps `date` into the closed range `[start, end]`.
|
|
236
|
+
* @example clampDate('2026-12-25', { start: '2026-01-01', end: '2026-06-30' }) // => '2026-06-30'
|
|
237
|
+
*/
|
|
238
|
+
export declare function clampDate(date: DateInput, range: {
|
|
239
|
+
readonly start: DateInput;
|
|
240
|
+
readonly end: DateInput;
|
|
241
|
+
}): PlainDate;
|
|
242
|
+
/**
|
|
243
|
+
* Candidate closest to `date` (ties: the first such candidate), or `undefined` for none.
|
|
244
|
+
* @example closestTo('2026-01-10', ['2026-01-01', '2026-01-12']) // => '2026-01-12'
|
|
245
|
+
*/
|
|
246
|
+
export declare function closestTo(date: DateInput, candidates: Iterable<DateInput>): PlainDate | undefined;
|
|
247
|
+
/**
|
|
248
|
+
* Calendar days from `earlier` to `later` (negative when `later` is earlier).
|
|
249
|
+
* @example differenceInDays('2026-03-01', '2026-02-01') // => 28
|
|
250
|
+
*/
|
|
251
|
+
export declare function differenceInDays(later: DateInput, earlier: DateInput): number;
|
|
252
|
+
/**
|
|
253
|
+
* Complete weeks (truncated toward zero).
|
|
254
|
+
* @example differenceInWeeks('2026-01-15', '2026-01-01') // => 2
|
|
255
|
+
*/
|
|
256
|
+
export declare function differenceInWeeks(later: DateInput, earlier: DateInput): number;
|
|
257
|
+
/**
|
|
258
|
+
* Complete calendar months, month-end aware (Jan 31 -> Feb 28 is one month).
|
|
259
|
+
* @example differenceInMonths('2026-02-28', '2026-01-31') // => 1
|
|
260
|
+
*/
|
|
261
|
+
export declare function differenceInMonths(later: DateInput, earlier: DateInput): number;
|
|
262
|
+
/**
|
|
263
|
+
* Complete quarters (3 months).
|
|
264
|
+
* @example differenceInQuarters('2026-12-31', '2026-01-01') // => 3
|
|
265
|
+
*/
|
|
266
|
+
export declare function differenceInQuarters(later: DateInput, earlier: DateInput): number;
|
|
267
|
+
/**
|
|
268
|
+
* Complete years (Feb 29 -> Feb 28 of a common year counts as a year, like `addYears`).
|
|
269
|
+
* @example differenceInYears('2026-09-28', '2000-09-29') // => 25
|
|
270
|
+
*/
|
|
271
|
+
export declare function differenceInYears(later: DateInput, earlier: DateInput): number;
|
|
272
|
+
/** Age-style breakdown returned by `dateDiff`. */
|
|
273
|
+
export interface DateDiff {
|
|
274
|
+
readonly years: number;
|
|
275
|
+
readonly months: number;
|
|
276
|
+
readonly days: number;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Years, months, and days from `from` to `to` such that
|
|
280
|
+
* `addDays(addMonths(from, years * 12 + months), days)` equals `to`. When `to` is earlier,
|
|
281
|
+
* every field is the negation of `dateDiff(to, from)`.
|
|
282
|
+
* @example dateDiff('2024-01-31', '2024-03-01') // => { years: 0, months: 1, days: 1 }
|
|
283
|
+
*/
|
|
284
|
+
export declare function dateDiff(from: DateInput, to: DateInput): DateDiff;
|
|
285
|
+
export interface AgeOptions {
|
|
286
|
+
/**
|
|
287
|
+
* When a Feb 29 birthday is reached in a common year. `'feb28'` (default, consistent with
|
|
288
|
+
* `addYears` clamping) or `'mar1'` (legal convention in, for example, England and Wales and Hong Kong).
|
|
289
|
+
*/
|
|
290
|
+
readonly leapDayBirthday?: 'feb28' | 'mar1';
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Age in whole years on `asOf` (default: today in the runtime zone). Throws
|
|
294
|
+
* `HLP_DATE_AGE_BEFORE_BIRTH` when `asOf` precedes `birthDate`.
|
|
295
|
+
* @example age('2000-02-29', '2025-02-28') // => 25 // 'mar1' → 24
|
|
296
|
+
*/
|
|
297
|
+
export declare function age(birthDate: DateInput, asOf?: DateInput, options?: AgeOptions): number;
|
|
298
|
+
export interface WeekNumberingOptions extends WeekOptions {
|
|
299
|
+
/** Days of the new year the first week must contain, 1-7. Default 4 (ISO 8601). */
|
|
300
|
+
readonly minimalDays?: number;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Week number and week-year under any week rule (default ISO: Monday, 4 minimal days; US: `{ firstDayOfWeek: 7, minimalDays: 1 }`).
|
|
304
|
+
* @example weekOfYear('2027-01-01') // => { week: 53, year: 2026 }
|
|
305
|
+
*/
|
|
306
|
+
export declare function weekOfYear(date: DateInput, options?: WeekNumberingOptions): {
|
|
307
|
+
readonly week: number;
|
|
308
|
+
readonly year: number;
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Number of weeks (52 or 53) in a week-year under a week rule.
|
|
312
|
+
* @example weeksInWeekYear(2026) // => 53
|
|
313
|
+
*/
|
|
314
|
+
export declare function weeksInWeekYear(year: number, options?: WeekNumberingOptions): number;
|
|
315
|
+
/**
|
|
316
|
+
* ISO 8601 week number (1-53).
|
|
317
|
+
* @example isoWeek('2026-09-29') // => 40
|
|
318
|
+
*/
|
|
319
|
+
export declare function isoWeek(date: DateInput): number;
|
|
320
|
+
/**
|
|
321
|
+
* ISO 8601 week-numbering year (differs from the calendar year around January 1).
|
|
322
|
+
* @example isoWeekYear('2027-01-01') // => 2026
|
|
323
|
+
*/
|
|
324
|
+
export declare function isoWeekYear(date: DateInput): number;
|
|
325
|
+
/**
|
|
326
|
+
* ISO weeks in a year (53 when January 1 is a Thursday, or a Wednesday in a leap year).
|
|
327
|
+
* @example isoWeeksInYear(2026) // => 53
|
|
328
|
+
*/
|
|
329
|
+
export declare function isoWeeksInYear(year: number): number;
|
|
330
|
+
/**
|
|
331
|
+
* 1-based row of `date` in its month's calendar (weeks start on `firstDayOfWeek`).
|
|
332
|
+
* @example weekOfMonth('2026-09-29') // => 5
|
|
333
|
+
*/
|
|
334
|
+
export declare function weekOfMonth(date: DateInput, options?: WeekOptions): number;
|
|
335
|
+
/**
|
|
336
|
+
* Day of the year, 1-366.
|
|
337
|
+
* @example dayOfYear('2026-02-01') // => 32
|
|
338
|
+
*/
|
|
339
|
+
export declare function dayOfYear(date: DateInput): 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{ValidationError as I}from"../error/index.js";import{comparePlainDates as f,daysBetween as Y,daysInMonth as O,isLeapYear as S,isoWeekday as w,plainDate as p,toEpochDay as c,toPlainDate as o,today as y,addDays as d}from"./plain-date.js";function D(e,t){if(!Number.isSafeInteger(e))throw new I("HLP_DATE_OUT_OF_RANGE","Amount must be a safe integer.",{details:{property:t}})}function T(e,t="firstDayOfWeek"){if(!Number.isInteger(e)||e<1||e>7)throw new I("HLP_DATE_INVALID_WEEKDAY","Weekday must be an integer 1 (Monday) to 7 (Sunday).",{details:{property:t}})}function Q(e,t){if(!Number.isInteger(e)||e<1||e>12)throw new I("HLP_DATE_INVALID_MONTH","Month must be an integer 1 to 12.",{details:{property:t}})}const P=e=>{const t=e.firstDayOfWeek??1;return T(t),t};function H(e,t){return D(t,"weeks"),d(e,t*7)}function l(e,t){D(t,"months");const n=o(e),r=n.year*12+(n.month-1)+t,a=Math.floor(r/12),u=r-a*12+1;return p(a,u,Math.min(n.day,O(a,u)))}function V(e,t){return D(t,"quarters"),l(e,t*3)}function $(e,t){return D(t,"years"),l(e,t*12)}function X(e,t){return D(t,"days"),d(e,0-t)}function Z(e,t){return D(t,"weeks"),H(e,0-t)}function tt(e,t){return D(t,"months"),l(e,0-t)}function et(e,t){return D(t,"quarters"),V(e,0-t)}function nt(e,t){return D(t,"years"),$(e,0-t)}function x(e,t={}){const n=P(t),r=o(e);return d(r,0-(w(r)-n+7)%7)}function rt(e,t={}){return d(x(e,t),6)}function at(e){const t=o(e);return p(t.year,t.month,1)}function B(e){const t=o(e);return p(t.year,t.month,O(t.year,t.month))}function k(e){return Math.floor((o(e).month-1)/3)+1}function v(e){const t=o(e);return p(t.year,(k(t)-1)*3+1,1)}function ot(e){return B(l(v(e),2))}function ut(e){return p(o(e).year,1,1)}function it(e){return p(o(e).year,12,31)}function W(e,t){return e.month>=t?e.year:e.year-1}function h(e){const t=e.startMonth??1;return Q(t,"startMonth"),t}function _(e,t={}){const n=h(t);return p(W(o(e),n),n,1)}function st(e,t={}){return d(l(_(e,t),12),-1)}function R(e,t={}){const n=h(t),r=W(o(e),n);return n===1||t.naming==="start"?r:r+1}function A(e,t={}){const n=h(t);return Math.floor((o(e).month-n+12)%12/3)+1}function j(e,t={}){return l(_(e,t),(A(e,t)-1)*3)}function ft(e,t={}){return d(l(j(e,t),3),-1)}function pt(e,t={}){const n=t.prefix??"FY";if(t.style==="span"){const r=h(t),a=W(o(e),r),u=r===1?a:a+1;return u===a?`${n}${String(a)}`:`${n}${String(a)}-${String((u%100+100)%100).padStart(2,"0")}`}return`${n}${String(R(e,t))}`}function ct(e,t={}){return`Q${String(A(e,t))}`}function F(e,t){return f(e,t)===0}function Dt(e,t,n={}){return F(x(e,n),x(t,n))}function lt(e,t){const n=o(e),r=o(t);return n.year===r.year&&n.month===r.month}function It(e,t){return o(e).year===o(t).year&&k(e)===k(t)}function dt(e,t){return o(e).year===o(t).year}function z(e,t){return f(e,t)<0}function G(e,t){return f(e,t)>0}function mt(e,t,n,r={}){const a=c(o(e)),u=c(o(t)),i=c(o(n));if(i<u)throw new I("HLP_DATE_INVALID_INTERVAL","Interval end is before its start.");const s=r.inclusive??"both",b=s==="both"||s==="start"?a>=u:a>u,N=s==="both"||s==="end"?a<=i:a<i;return b&&N}function bt(e,t){return F(e,y(t))}function yt(e,t){return z(e,y(t))}function xt(e,t){return G(e,y(t))}function ht(e){let t;for(const n of e){const r=o(n);(!t||f(r,t)<0)&&(t=r)}return t}function Ot(e){let t;for(const n of e){const r=o(n);(!t||f(r,t)>0)&&(t=r)}return t}function Pt(e,t){const n=o(t.start),r=o(t.end);if(f(r,n)<0)throw new I("HLP_DATE_INVALID_INTERVAL","Interval end is before its start.");const a=o(e);return f(a,n)<0?n:f(a,r)>0?r:a}function kt(e,t){const n=c(o(e));let r,a=1/0;for(const u of t){const i=o(u),s=Math.abs(c(i)-n);s<a&&(r=i,a=s)}return r}function q(e,t){return Y(t,e)}function Wt(e,t){return Math.trunc(q(e,t)/7)+0}function g(e,t){let n=(t.year-e.year)*12+(t.month-e.month);return Math.min(e.day,O(t.year,t.month))>t.day&&(n-=1),n}function M(e,t){const n=o(e),r=o(t);return f(n,r)>=0?g(r,n):0-g(n,r)}function gt(e,t){return M(e,t)}function Mt(e,t){return Math.trunc(M(e,t)/3)+0}function Yt(e,t){return Math.trunc(M(e,t)/12)+0}function K(e,t){const n=o(e),r=o(t);if(f(r,n)<0){const u=K(r,n);return Object.freeze({years:0-u.years,months:0-u.months,days:0-u.days})}const a=g(n,r);return Object.freeze({years:Math.floor(a/12),months:a%12,days:Y(l(n,a),r)})}function wt(e,t=y(),n={}){const r=o(e),a=o(t);if(f(a,r)<0)throw new I("HLP_DATE_AGE_BEFORE_BIRTH","The reference date is before the birth date.");let u=r.day;r.month===2&&r.day===29&&!S(a.year)&&(n.leapDayBirthday??"feb28")==="feb28"&&(u=28);let i=a.year-r.year;return(a.month<r.month||a.month===r.month&&a.day<u)&&(i-=1),i}function m(e,t,n){return c(x(p(e,1,n),{firstDayOfWeek:t}))}function L(e){const t=P(e),n=e.minimalDays??4;if(!Number.isInteger(n)||n<1||n>7)throw new I("HLP_DATE_INVALID_MINIMAL_DAYS","minimalDays must be an integer 1 to 7.");return[t,n]}function E(e,t={}){const[n,r]=L(t),a=o(e),u=c(a);let i=a.year,s=m(i,n,r);if(u<s)i-=1,s=m(i,n,r);else{const b=m(i+1,n,r);u>=b&&(i+=1,s=b)}return Object.freeze({week:Math.floor((u-s)/7)+1,year:i})}function U(e,t={}){const[n,r]=L(t);return(m(e+1,n,r)-m(e,n,r))/7}function _t(e){return E(e).week}function At(e){return E(e).year}function Ft(e){return U(e)}function Lt(e,t={}){const n=P(t),r=o(e),a=(w(p(r.year,r.month,1))-n+7)%7;return Math.floor((r.day-1+a)/7)+1}function Et(e){const t=o(e);return c(t)-c(p(t.year,1,1))+1}export{l as addMonths,V as addQuarters,H as addWeeks,$ as addYears,wt as age,T as assertIsoWeekday,Pt as clampDate,kt as closestTo,K as dateDiff,Et as dayOfYear,q as differenceInDays,gt as differenceInMonths,Mt as differenceInQuarters,Wt as differenceInWeeks,Yt as differenceInYears,ft as endOfFiscalQuarter,st as endOfFiscalYear,B as endOfMonth,ot as endOfQuarter,rt as endOfWeek,it as endOfYear,ct as fiscalQuarterLabel,A as fiscalQuarterOf,pt as fiscalYearLabel,R as fiscalYearOf,G as isAfter,z as isBefore,mt as isBetween,xt as isFuture,yt as isPast,F as isSameDay,lt as isSameMonth,It as isSameQuarter,Dt as isSameWeek,dt as isSameYear,bt as isToday,_t as isoWeek,At as isoWeekYear,Ft as isoWeeksInYear,Ot as maxDate,ht as minDate,k as quarterOf,j as startOfFiscalQuarter,_ as startOfFiscalYear,at as startOfMonth,v as startOfQuarter,x as startOfWeek,ut as startOfYear,X as subDays,tt as subMonths,et as subQuarters,Z as subWeeks,nt as subYears,Lt as weekOfMonth,E as weekOfYear,U as weeksInWeekYear};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type DateInput, type PlainDate } from './plain-date.js';
|
|
2
|
+
import { type PlainDateTime } from './plain-time.js';
|
|
3
|
+
import { type InstantInput } from './zone.js';
|
|
4
|
+
export interface PatternOptions {
|
|
5
|
+
/** Locale for names (`MMM`, `EEE`, `a`); default the runtime locale. */
|
|
6
|
+
readonly locale?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Formats a date or date-time with a pattern (token table at the top of this module).
|
|
10
|
+
* @example formatDate('2026-09-29', "EEE, d MMM yyyy 'Q'Q") // => 'Tue, 29 Sep 2026 Q3'
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatDate(value: DateInput | PlainDateTime, pattern: string, options?: PatternOptions): string;
|
|
13
|
+
export interface ParsePatternOptions extends PatternOptions {
|
|
14
|
+
/**
|
|
15
|
+
* `yy` maps to the year with those last two digits in `[referenceYear - 50, referenceYear + 49]`.
|
|
16
|
+
* Default 2000 (so `yy` covers 1950-2049).
|
|
17
|
+
*/
|
|
18
|
+
readonly referenceYear?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Strictly parses a date-time with a pattern (same tokens as `formatDate`). Returns `undefined`
|
|
22
|
+
* on any mismatch, impossible value, or inconsistent field (for example a weekday that does not
|
|
23
|
+
* match the date). The year is required; a missing month or day defaults to 1. `h`/`hh` require `a`.
|
|
24
|
+
* @example parseDateTime('29/09/2026 14:05', 'dd/MM/yyyy HH:mm') // => '2026-09-29T14:05:00'
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseDateTime(text: string, pattern: string, options?: ParsePatternOptions): PlainDateTime | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Strictly parses a date with a pattern; time tokens are validated and discarded.
|
|
29
|
+
* @example parseDate('Sep 29, 2026', 'MMM d, yyyy', { locale: 'en' }) // => '2026-09-29'
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseDate(text: string, pattern: string, options?: ParsePatternOptions): PlainDate | undefined;
|
|
32
|
+
/** `Intl.DateTimeFormat` options for wall-clock values (the zone is fixed internally). */
|
|
33
|
+
export type DateIntlOptions = Omit<Intl.DateTimeFormatOptions, 'timeZone' | 'timeZoneName'> & {
|
|
34
|
+
readonly locale?: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Formats a date or wall-clock date-time with `Intl.DateTimeFormat` (cached). The value is
|
|
38
|
+
* rendered in UTC internally, so the calendar date never shifts. Default `{ dateStyle: 'medium' }`.
|
|
39
|
+
* @example formatDateIntl('2026-09-29', { locale: 'de', dateStyle: 'long' }) // => '29. September 2026'
|
|
40
|
+
*/
|
|
41
|
+
export declare function formatDateIntl(value: DateInput | PlainDateTime, options?: DateIntlOptions): string;
|
|
42
|
+
/**
|
|
43
|
+
* Formats a range with `Intl.DateTimeFormat#formatRange` (shared parts collapsed, "Jan 1 - 5, 2026"),
|
|
44
|
+
* falling back to `start - end`. Throws `HLP_DATE_INVALID_INTERVAL` when `end < start`.
|
|
45
|
+
* @example formatDateRange('2026-01-01', '2026-01-05', { locale: 'en' }) // => 'Jan 1 – 5, 2026'
|
|
46
|
+
*/
|
|
47
|
+
export declare function formatDateRange(start: DateInput | PlainDateTime, end: DateInput | PlainDateTime, options?: DateIntlOptions): string;
|
|
48
|
+
export interface RelativeOptions {
|
|
49
|
+
readonly locale?: string;
|
|
50
|
+
/** `'auto'` (default) allows "yesterday"/"now"; `'always'` forces numbers. */
|
|
51
|
+
readonly numeric?: 'auto' | 'always';
|
|
52
|
+
readonly style?: 'long' | 'short' | 'narrow';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Describes `value` relative to `base` (default now) with the best unit, seconds to years
|
|
56
|
+
* (months and years use average Gregorian lengths).
|
|
57
|
+
* @example formatRelative(Date.UTC(2026, 8, 29, 9), Date.UTC(2026, 8, 29, 12), { locale: 'en' }) // => '3 hours ago'
|
|
58
|
+
* @example formatRelative(Date.now() - 3 * 3_600_000) // e.g. '3 hours ago' (relative to now, in the runtime locale)
|
|
59
|
+
*/
|
|
60
|
+
export declare function formatRelative(value: InstantInput, base?: InstantInput, options?: RelativeOptions): string;
|
|
61
|
+
/**
|
|
62
|
+
* Describes a date relative to `base` (default today in the runtime zone) in calendar units:
|
|
63
|
+
* days under a week, then weeks, complete months, and complete years.
|
|
64
|
+
* @example formatRelativeDate('2026-09-28', '2026-09-29') // => 'yesterday'
|
|
65
|
+
*/
|
|
66
|
+
export declare function formatRelativeDate(date: DateInput, base?: DateInput, options?: RelativeOptions): 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 z,ValidationError as w}from"../error/index.js";import{differenceInMonths as C,differenceInYears as q,isoWeek as O,quarterOf as _}from"./calendar.js";import{dateTimeFormat as g,relativeTimeFormat as U}from"./intl-cache.js";import{monthName as M,weekdayName as E}from"./locale.js";import{daysBetween as V,isoWeekday as k,plainDate as $,today as x,toPlainDate as W}from"./plain-date.js";import{isPlainDateTime as S,plainDateTime as v,plainDateTimeToEpochMilliseconds as A,plainTime as Z}from"./plain-time.js";import{toEpochMs as R}from"./zone.js";const j=new Set(["yyyy","yy","MMMM","MMM","MM","M","dd","d","EEEE","EEE","HH","H","hh","h","mm","ss","SSS","a","Q","w"]),Q=256,X=256,y=new Map,Y=e=>e>="a"&&e<="z"||e>="A"&&e<="Z",B=e=>j.has(e);function T(){return new w("HLP_DATE_INVALID_PATTERN","Unsupported date pattern.")}function F(e){const s=y.get(e);if(s)return s;if(typeof e!="string")throw T();if(e.length>Q)throw new z("HLP_DATE_PATTERN_TOO_LONG","Date pattern exceeds 256 characters.");const i=[];let u="";const r=()=>{u&&i.push({lit:u}),u=""};let o=0;for(;o<e.length;){const t=e.charAt(o);if(t==="'"){if(e.charAt(o+1)==="'"){u+="'",o+=2;continue}o++;let a=!1;for(;o<e.length;){const c=e.charAt(o);if(c==="'"){if(e.charAt(o+1)==="'"){u+="'",o+=2;continue}a=!0,o++;break}u+=c,o++}if(!a)throw T()}else if(Y(t)){let a=o;for(;e.charAt(a)===t;)a++;const c=e.slice(o,a);if(!B(c))throw T();r(),i.push({field:c}),o=a}else u+=t,o++}r();const d=Object.freeze(i);return y.size>=64&&y.clear(),y.set(e,d),d}function G(e){return S(e)?{date:e.date,...e.time}:{date:W(e),hour:0,minute:0,second:0,millisecond:0}}const f=(e,s)=>String(e).padStart(s,"0");function H(e){const s=g(e,{hour:"numeric",hour12:!0,timeZone:"UTC"}),i=(u,r)=>s.formatToParts(Date.UTC(2024,0,1,u)).find(o=>o.type==="dayPeriod")?.value??r;return[i(9,"AM"),i(21,"PM")]}function ce(e,s,i={}){const u=F(s),r=G(e),{locale:o}=i,d=o===void 0?{}:{locale:o};let t="";for(const a of u){if("lit"in a){t+=a.lit;continue}const{year:c,month:l,day:n}=r.date;switch(a.field){case"yyyy":t+=c<0?`-${f(-c,4)}`:f(c,4);break;case"yy":t+=f((c%100+100)%100,2);break;case"M":t+=String(l);break;case"MM":t+=f(l,2);break;case"MMM":t+=M(l,{...d,style:"short",context:"format"});break;case"MMMM":t+=M(l,{...d,style:"long",context:"format"});break;case"d":t+=String(n);break;case"dd":t+=f(n,2);break;case"EEE":t+=E(k(r.date),{...d,style:"short"});break;case"EEEE":t+=E(k(r.date),{...d,style:"long"});break;case"H":t+=String(r.hour);break;case"HH":t+=f(r.hour,2);break;case"h":t+=String(r.hour%12||12);break;case"hh":t+=f(r.hour%12||12,2);break;case"mm":t+=f(r.minute,2);break;case"ss":t+=f(r.second,2);break;case"SSS":t+=f(r.millisecond,3);break;case"a":t+=H(o)[r.hour<12?0:1];break;case"Q":t+=String(_(r.date));break;case"w":t+=String(O(r.date));break}}return t}const b=new Map;function D(e,s,i){const u=`${e??""}|${s}|${i}`,r=b.get(u);if(r)return r;const o=e===void 0?{}:{locale:e},d=[];if(s==="MMM"||s==="MMMM")for(let a=1;a<=12;a++)d.push(M(a,{...o,style:s==="MMM"?"short":"long",context:i}));else for(let a=1;a<=7;a++)d.push(E(a,{...o,style:s==="EEE"?"short":"long"}));const t=Object.freeze(d);return b.size>=128&&b.clear(),b.set(u,t),t}function p(e,s,i,u){let r;for(const o of i)o.forEach((d,t)=>{if(!d||r&&d.length<=r[1])return;const a=e.slice(s,s+d.length);a.length===d.length&&a.toLocaleLowerCase(u)===d.toLocaleLowerCase(u)&&(r=[t,d.length])});return r}const K=e=>e>="0"&&e<="9";function J(e,s,i){if(typeof e!="string"||e.length>X)return;const u=F(s),{locale:r}=i,o={};let d=0;const t=(c,l)=>{const n=o[c];return n!==void 0&&n!==l?!1:(o[c]=l,!0)},a=(c,l)=>{let n=d;for(;n<e.length&&n-d<l&&K(e.charAt(n));)n++;if(n-d<c)return;const m=Number(e.slice(d,n));return d=n,m};for(const c of u){if("lit"in c){if(!e.startsWith(c.lit,d))return;d+=c.lit.length;continue}let l;switch(c.field){case"yyyy":{const n=a(4,4);l=n!==void 0&&t("year",n);break}case"yy":{const n=a(2,2),m=i.referenceYear??2e3;if(n===void 0||!Number.isInteger(m))return;const h=m-50,N=h+((n-h)%100+100)%100;l=t("year",N);break}case"M":case"MM":{const n=c.field==="M"?a(1,2):a(2,2);l=n!==void 0&&t("month",n);break}case"MMM":case"MMMM":{const n=p(e,d,[D(r,c.field,"format"),D(r,c.field,"standalone")],r);if(!n)return;d+=n[1],l=t("month",n[0]+1);break}case"d":case"dd":{const n=c.field==="d"?a(1,2):a(2,2);l=n!==void 0&&t("day",n);break}case"EEE":case"EEEE":{const n=p(e,d,[D(r,c.field,"format")],r);if(!n)return;d+=n[1],l=t("weekday",n[0]+1);break}case"H":case"HH":{const n=c.field==="H"?a(1,2):a(2,2);l=n!==void 0&&t("hour24",n);break}case"h":case"hh":{const n=c.field==="h"?a(1,2):a(2,2);l=n!==void 0&&t("hour12",n);break}case"mm":{const n=a(2,2);l=n!==void 0&&t("minute",n);break}case"ss":{const n=a(2,2);l=n!==void 0&&t("second",n);break}case"SSS":{const n=a(3,3);l=n!==void 0&&t("millisecond",n);break}case"a":{const[n,m]=H(r),h=p(e,d,[[n,m]],r);if(!h)return;d+=h[1],l=t("pm",h[0]===1);break}case"Q":{const n=a(1,1);l=n!==void 0&&t("quarter",n);break}case"w":{const n=a(1,2);l=n!==void 0&&t("week",n);break}}if(!l)return}return d===e.length?o:void 0}function ee(e){if(e.year===void 0)return;let s=e.hour24??0;if(e.hour12!==void 0){if(e.pm===void 0||e.hour12<1||e.hour12>12)return;const u=e.hour12%12+(e.pm?12:0);if(e.hour24!==void 0&&e.hour24!==u)return;s=u}let i;try{i=v($(e.year,e.month??1,e.day??1),Z(s,e.minute??0,e.second??0,e.millisecond??0))}catch{return}if(!(e.weekday!==void 0&&e.weekday!==k(i.date))&&!(e.quarter!==void 0&&e.quarter!==_(i.date))&&!(e.week!==void 0&&e.week!==O(i.date)))return i}function ne(e,s,i={}){const u=J(e,s,i);return u?ee(u):void 0}function le(e,s,i={}){return ne(e,s,i)?.date}function P(e){return S(e)?A(e):A(v(e))}function L(e){const s=Object.keys(e).some(i=>i!=="locale"&&i!=="calendar"&&i!=="numberingSystem"&&i!=="hour12"&&i!=="hourCycle"&&i!=="localeMatcher"&&i!=="formatMatcher");return{...e,...s?{}:{dateStyle:"medium"},timeZone:"UTC"}}function fe(e,s={}){return g(s.locale,L(s)).format(P(e))}function me(e,s,i={}){const u=P(e),r=P(s);if(r<u)throw new w("HLP_DATE_INVALID_INTERVAL","Interval end is before its start.");const o=g(i.locale,L(i)),d=o.formatRange;return d?d.call(o,u,r):`${o.format(u)} to ${o.format(r)}`}const te=[["second",1e3,60],["minute",6e4,60],["hour",36e5,24],["day",864e5,7],["week",6048e5,4],["month",2629746e3,12],["year",31556952e3,1/0]];function I(e){return U(e.locale,{numeric:e.numeric??"auto",style:e.style??"long"})}function he(e,s=Date.now(),i={}){const u=R(e)-R(s),r=Math.abs(u);for(const[o,d,t]of te){const a=Math.round(r/d);if(a<t)return I(i).format(a===0?0:u<0?-a:a,o)}return I(i).format(0,"second")}function ye(e,s=x(),i={}){const u=V(s,e),r=I(i);if(Math.abs(u)<7)return r.format(u,"day");const o=C(e,s);return o===0?r.format(Math.round(u/7),"week"):Math.abs(o)<12?r.format(o,"month"):r.format(q(e,s),"year")}export{ce as formatDate,fe as formatDateIntl,me as formatDateRange,he as formatRelative,ye as formatRelativeDate,le as parseDate,ne as parseDateTime};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@absoluteui/helpers/date` (docs/PLAN-HELPERS.md section 2): date-only values and calendar math.
|
|
3
|
+
*
|
|
4
|
+
* Conventions
|
|
5
|
+
* - Date-only functions take `DateInput` (`PlainDate | 'YYYY-MM-DD'`) and return frozen
|
|
6
|
+
* `PlainDate`s. They never create a `Date` at local midnight, so no result shifts by a day
|
|
7
|
+
* because of the host zone or DST.
|
|
8
|
+
* - Parameters typed `InstantInput` (`number | Date`) are exact instants; functions that
|
|
9
|
+
* return an instant return epoch milliseconds and end in `Instant`
|
|
10
|
+
* (`startOfDayInstant`, `endOfDayInstant`, `parseInstant`). `plainDateFromInstant` and
|
|
11
|
+
* `toPlainDateTime` convert an instant to wall-clock values in a zone.
|
|
12
|
+
* - `differenceInX(later, earlier)` follows date-fns argument order; `daysBetween(a, b)` and
|
|
13
|
+
* `dateDiff(from, to)` measure from the first argument to the second.
|
|
14
|
+
* - Weeks start on Monday (ISO 8601) unless `firstDayOfWeek` is given; use
|
|
15
|
+
* `getWeekInfo(locale)` for locale conventions.
|
|
16
|
+
* - Parsers return `undefined`; invalid arguments throw `ValidationError` with `HLP_*` codes.
|
|
17
|
+
*/
|
|
18
|
+
export * from './plain-date.js';
|
|
19
|
+
export { plainTime, plainDateTime, isPlainTime, isPlainDateTime, timeToMilliseconds, timeFromMilliseconds, comparePlainTimes, comparePlainDateTimes, plainDateTimeToEpochMilliseconds, formatPlainTime, formatPlainDateTime, parsePlainTime, parseIsoDateTime, parsePlainDateTime, parseInstant, formatInstant } from './plain-time.js';
|
|
20
|
+
export type { PlainTime, PlainDateTime, IsoDateTimeParts } from './plain-time.js';
|
|
21
|
+
export * from './calendar.js';
|
|
22
|
+
export * from './locale.js';
|
|
23
|
+
export * from './intervals.js';
|
|
24
|
+
export * from './format.js';
|
|
25
|
+
export { toPlainDateTime, startOfDayInstant, endOfDayInstant } from './zone.js';
|
|
26
|
+
export type { InstantInput } from './zone.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
|
+
export*from"./plain-date.js";import{plainTime as t,plainDateTime as m,isPlainTime as o,isPlainDateTime as n,timeToMilliseconds as r,timeFromMilliseconds as s,comparePlainTimes as p,comparePlainDateTimes as l,plainDateTimeToEpochMilliseconds as T,formatPlainTime as f,formatPlainDateTime as D,parsePlainTime as P,parseIsoDateTime as x,parsePlainDateTime as I,parseInstant as c,formatInstant as d}from"./plain-time.js";export*from"./calendar.js";export*from"./locale.js";export*from"./intervals.js";export*from"./format.js";import{toPlainDateTime as u,startOfDayInstant as z,endOfDayInstant as E}from"./zone.js";export{l as comparePlainDateTimes,p as comparePlainTimes,E as endOfDayInstant,d as formatInstant,D as formatPlainDateTime,f as formatPlainTime,n as isPlainDateTime,o as isPlainTime,c as parseInstant,x as parseIsoDateTime,I as parsePlainDateTime,P as parsePlainTime,m as plainDateTime,T as plainDateTimeToEpochMilliseconds,t as plainTime,z as startOfDayInstant,s as timeFromMilliseconds,r as timeToMilliseconds,u as toPlainDateTime};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type WeekOptions } from './calendar.js';
|
|
2
|
+
import { type DateInput, type IsoWeekday, type PlainDate } from './plain-date.js';
|
|
3
|
+
/** Closed date interval: `start` and `end` are both included. */
|
|
4
|
+
export interface DateInterval {
|
|
5
|
+
readonly start: PlainDate;
|
|
6
|
+
readonly end: PlainDate;
|
|
7
|
+
}
|
|
8
|
+
/** Interval input: dates as `PlainDate` or `'YYYY-MM-DD'`. */
|
|
9
|
+
export interface DateIntervalInput {
|
|
10
|
+
readonly start: DateInput;
|
|
11
|
+
readonly end: DateInput;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a validated, frozen closed interval; throws `HLP_DATE_INVALID_INTERVAL` when `end < start`.
|
|
15
|
+
* @example dateInterval('2026-01-01', '2026-01-31')
|
|
16
|
+
*/
|
|
17
|
+
export declare function dateInterval(start: DateInput, end: DateInput): DateInterval;
|
|
18
|
+
/**
|
|
19
|
+
* Days in the interval, counting both endpoints.
|
|
20
|
+
* @example intervalLengthDays({ start: '2026-01-01', end: '2026-01-31' }) // => 31
|
|
21
|
+
*/
|
|
22
|
+
export declare function intervalLengthDays(interval: DateIntervalInput): number;
|
|
23
|
+
/**
|
|
24
|
+
* True when `date` lies inside the closed interval.
|
|
25
|
+
* @example containsDate({ start: '2026-01-01', end: '2026-01-31' }, '2026-01-31') // => true
|
|
26
|
+
*/
|
|
27
|
+
export declare function containsDate(interval: DateIntervalInput, date: DateInput): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* True when two closed intervals share at least one day. With `inclusive: false`, intervals that
|
|
30
|
+
* only touch at an endpoint (`a.end === b.start`) do not count.
|
|
31
|
+
* @example intervalsOverlap({ start: '2026-01-01', end: '2026-01-05' }, { start: '2026-01-05', end: '2026-01-09' }) // => true
|
|
32
|
+
*/
|
|
33
|
+
export declare function intervalsOverlap(a: DateIntervalInput, b: DateIntervalInput, options?: {
|
|
34
|
+
readonly inclusive?: boolean;
|
|
35
|
+
}): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Shared days of two intervals, or `undefined` when they are disjoint.
|
|
38
|
+
* @example intervalIntersection({ start: '2026-01-01', end: '2026-01-10' }, { start: '2026-01-05', end: '2026-02-01' }) // => { start: '2026-01-05', end: '2026-01-10' }
|
|
39
|
+
* @example intervalIntersection({ start: '2026-01-01', end: '2026-01-04' }, { start: '2026-01-05', end: '2026-01-06' }) // => undefined
|
|
40
|
+
*/
|
|
41
|
+
export declare function intervalIntersection(a: DateIntervalInput, b: DateIntervalInput): DateInterval | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Sorts and merges overlapping intervals in O(n log n). Adjacent intervals (one ends the day
|
|
44
|
+
* before the next starts) merge too unless `mergeAdjacent: false`.
|
|
45
|
+
* @example
|
|
46
|
+
* const leave = [{ start: '2026-01-01', end: '2026-01-03' }, { start: '2026-01-04', end: '2026-01-06' }];
|
|
47
|
+
* mergeIntervals(leave); // => [{ start: '2026-01-01', end: '2026-01-06' }]
|
|
48
|
+
* mergeIntervals(leave, { mergeAdjacent: false }).length; // => 2
|
|
49
|
+
*/
|
|
50
|
+
export declare function mergeIntervals(intervals: Iterable<DateIntervalInput>, options?: {
|
|
51
|
+
readonly mergeAdjacent?: boolean;
|
|
52
|
+
}): DateInterval[];
|
|
53
|
+
/**
|
|
54
|
+
* Uncovered sub-intervals of `within` (days not in any of `intervals`), ascending.
|
|
55
|
+
* @example
|
|
56
|
+
* const booked = [{ start: '2026-01-03', end: '2026-01-04' }];
|
|
57
|
+
* intervalGaps(booked, { start: '2026-01-01', end: '2026-01-06' }); // => [{ start: '2026-01-01', end: '2026-01-02' }, { start: '2026-01-05', end: '2026-01-06' }]
|
|
58
|
+
*/
|
|
59
|
+
export declare function intervalGaps(intervals: Iterable<DateIntervalInput>, within: DateIntervalInput): DateInterval[];
|
|
60
|
+
export interface IterateOptions {
|
|
61
|
+
/** Maximum number of items; exceeding it throws `HLP_DATE_TOO_MANY_ITEMS` before iteration starts. Default 100000. */
|
|
62
|
+
readonly limit?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Lazily yields every `step`-th day of the interval (both endpoints included).
|
|
66
|
+
* @example [...eachDayOfInterval({ start: '2026-01-30', end: '2026-02-02' })].length // => 4
|
|
67
|
+
*/
|
|
68
|
+
export declare function eachDayOfInterval(interval: DateIntervalInput, options?: IterateOptions & {
|
|
69
|
+
readonly step?: number;
|
|
70
|
+
}): Generator<PlainDate, void, undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* Lazily yields the first day of every week that overlaps the interval (the first item may precede `start`).
|
|
73
|
+
* @example [...eachWeekOfInterval({ start: '2026-09-30', end: '2026-10-12' })] // => ['2026-09-28', '2026-10-05', '2026-10-12'] // Mondays
|
|
74
|
+
*/
|
|
75
|
+
export declare function eachWeekOfInterval(interval: DateIntervalInput, options?: IterateOptions & WeekOptions): Generator<PlainDate, void, undefined>;
|
|
76
|
+
/**
|
|
77
|
+
* Lazily yields the first day of every month that overlaps the interval.
|
|
78
|
+
* @example [...eachMonthOfInterval({ start: '2026-01-15', end: '2026-03-01' })] // => ['2026-01-01', '2026-02-01', '2026-03-01']
|
|
79
|
+
*/
|
|
80
|
+
export declare function eachMonthOfInterval(interval: DateIntervalInput, options?: IterateOptions): Generator<PlainDate, void, undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* Lazily yields January 1 of every year that overlaps the interval.
|
|
83
|
+
* @example [...eachYearOfInterval({ start: '2025-06-01', end: '2026-01-01' })] // => ['2025-01-01', '2026-01-01']
|
|
84
|
+
*/
|
|
85
|
+
export declare function eachYearOfInterval(interval: DateIntervalInput, options?: IterateOptions): Generator<PlainDate, void, undefined>;
|
|
86
|
+
/** One cell of `calendarMonthGrid`. */
|
|
87
|
+
export interface CalendarDay {
|
|
88
|
+
readonly date: PlainDate;
|
|
89
|
+
/** False for leading/trailing days from the adjacent months. */
|
|
90
|
+
readonly inMonth: boolean;
|
|
91
|
+
/** True when `date` equals the `today` option (always false when it is omitted). */
|
|
92
|
+
readonly isToday: boolean;
|
|
93
|
+
readonly weekday: IsoWeekday;
|
|
94
|
+
}
|
|
95
|
+
export interface CalendarGridOptions extends WeekOptions {
|
|
96
|
+
/** Always return 6 weeks so the grid height never changes. Default true. */
|
|
97
|
+
readonly fixedWeeks?: boolean;
|
|
98
|
+
/** Marks this date with `isToday`. The function stays pure: nothing reads the clock. */
|
|
99
|
+
readonly today?: DateInput;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Weeks (rows of 7 days) covering a month, including adjacent-month days to fill the rows.
|
|
103
|
+
* @example
|
|
104
|
+
* const grid = calendarMonthGrid(2026, 9, { firstDayOfWeek: 7 }); // Sunday-first
|
|
105
|
+
* grid[0]?.[0]?.date; // => '2026-08-30'
|
|
106
|
+
* grid[0]?.[0]?.inMonth; // => false
|
|
107
|
+
* grid.length; // => 6 // fixed height by default
|
|
108
|
+
* calendarMonthGrid(2026, 9, { firstDayOfWeek: 7, fixedWeeks: false }).length; // => 5
|
|
109
|
+
*/
|
|
110
|
+
export declare function calendarMonthGrid(year: number, month: number, options?: CalendarGridOptions): CalendarDay[][];
|
|
@@ -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 k,ValidationError as m}from"../error/index.js";import{startOfWeek as O}from"./calendar.js";import{comparePlainDates as d,daysInMonth as M,fromEpochDay as c,isoWeekday as _,plainDate as x,toEpochDay as i,toPlainDate as v}from"./plain-date.js";function A(r,n){const t=v(r),e=v(n);if(d(e,t)<0)throw new m("HLP_DATE_INVALID_INTERVAL","Interval end is before its start.");return Object.freeze({start:t,end:e})}const l=r=>A(r.start,r.end);function G(r){const n=l(r);return i(n.end)-i(n.start)+1}function W(r,n){const t=l(r);return d(n,t.start)>=0&&d(n,t.end)<=0}function j(r,n,t={}){const e=l(r),a=l(n);return t.inclusive??!0?d(e.start,a.end)<=0&&d(a.start,e.end)<=0:d(e.start,a.end)<0&&d(a.start,e.end)<0}function N(r,n){const t=l(r),e=l(n),a=d(t.start,e.start)>=0?t.start:e.start,o=d(t.end,e.end)<=0?t.end:e.end;return d(a,o)<=0?Object.freeze({start:a,end:o}):void 0}function L(r,n={}){const t=n.mergeAdjacent??!0?1:0,e=Array.from(r,o=>{const s=l(o);return[i(s.start),i(s.end)]}).sort((o,s)=>o[0]-s[0]||o[1]-s[1]),a=[];for(const o of e){const s=a[a.length-1];s&&o[0]<=s[1]+t?s[1]=Math.max(s[1],o[1]):a.push([o[0],o[1]])}return a.map(([o,s])=>Object.freeze({start:c(o),end:c(s)}))}function z(r,n){const t=l(n),e=i(t.start),a=i(t.end),o=[];let s=e;for(const u of L(r)){const I=i(u.start),f=i(u.end);if(!(f<s)&&(I>a||(I>s&&o.push(Object.freeze({start:c(s),end:c(Math.min(I-1,a))})),s=Math.max(s,f+1),s>a)))break}return s<=a&&o.push(Object.freeze({start:c(s),end:t.end})),o}function D(r,n){const t=n.limit??1e5;if(!Number.isInteger(t)||t<0)throw new m("HLP_DATE_INVALID_LIMIT","limit must be a non-negative integer.");if(r>t)throw new k("HLP_DATE_TOO_MANY_ITEMS","The interval yields more items than the limit allows.",{details:{limit:t}})}function*w(r,n,t){for(let e=0;e<n;e++)yield c(r+e*t)}function C(r,n={}){const t=l(r),e=n.step??1;if(!Number.isSafeInteger(e)||e<1)throw new m("HLP_DATE_INVALID_STEP","step must be a positive integer.");const a=i(t.start),o=Math.floor((i(t.end)-a)/e)+1;return D(o,n),w(a,o,e)}function V(r,n={}){const t=l(r),e=i(O(t.start,n)),a=Math.floor((i(t.end)-e)/7)+1;return D(a,n),w(e,a,7)}function*P(r,n,t,e){const a=r*12+n-1;for(let o=0;o<t;o++){const s=a+o*e,u=Math.floor(s/12);yield x(u,s-u*12+1,1)}}function H(r,n={}){const t=l(r),e=(t.end.year-t.start.year)*12+(t.end.month-t.start.month)+1;return D(e,n),P(t.start.year,t.start.month,e,1)}function S(r,n={}){const t=l(r),e=t.end.year-t.start.year+1;return D(e,n),P(t.start.year,1,e,12)}function Y(r,n,t={}){const e=x(r,n,1),a=i(O(e,t)),o=i(e)+M(r,n)-1,s=t.fixedWeeks??!0?6:Math.floor((o-a)/7)+1,u=t.today===void 0?void 0:i(v(t.today)),I=[];for(let f=0;f<s;f++){const b=[];for(let y=0;y<7;y++){const h=a+f*7+y,p=c(h);b.push(Object.freeze({date:p,inMonth:p.month===n&&p.year===r,isToday:h===u,weekday:_(p)}))}I.push(b)}return I}export{Y as calendarMonthGrid,W as containsDate,A as dateInterval,C as eachDayOfInterval,H as eachMonthOfInterval,V as eachWeekOfInterval,S as eachYearOfInterval,z as intervalGaps,N as intervalIntersection,G as intervalLengthDays,j as intervalsOverlap,L as mergeIntervals};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Returns a cached instance for `kind|locale|options`, creating it with `create` on a miss. */
|
|
2
|
+
export declare function cachedIntl<T>(kind: string, locale: string | undefined, options: object, create: () => T): T;
|
|
3
|
+
/** Cached `Intl.DateTimeFormat`. */
|
|
4
|
+
export declare function dateTimeFormat(locale: string | undefined, options: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
|
|
5
|
+
/** Cached `Intl.NumberFormat`. */
|
|
6
|
+
export declare function numberFormat(locale: string | undefined, options: Intl.NumberFormatOptions): Intl.NumberFormat;
|
|
7
|
+
/** Cached `Intl.ListFormat`. */
|
|
8
|
+
export declare function listFormat(locale: string | undefined, options: Intl.ListFormatOptions): Intl.ListFormat;
|
|
9
|
+
/** Cached `Intl.RelativeTimeFormat`. */
|
|
10
|
+
export declare function relativeTimeFormat(locale: string | undefined, options: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat;
|
|
@@ -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{ValidationError as d}from"../error/index.js";const I=128,m=new Map;function r(t,n,s,u){let e=m.get(t);e||(e=new Map,m.set(t,e));const a=`${n??""}|${JSON.stringify(s)}`,o=e.get(a);if(o!==void 0)return o;let i;try{i=u()}catch(f){throw new d("HLP_INTL_INVALID_OPTIONS","Invalid locale or formatting options.",{cause:f})}return e.size>=I&&e.clear(),e.set(a,i),i}function l(t,n){return r("dtf",t,n,()=>new Intl.DateTimeFormat(t,n))}function F(t,n){return r("nf",t,n,()=>new Intl.NumberFormat(t,n))}function T(t,n){return r("lf",t,n,()=>new Intl.ListFormat(t,n))}function g(t,n){return r("rtf",t,n,()=>new Intl.RelativeTimeFormat(t,n))}export{r as cachedIntl,l as dateTimeFormat,T as listFormat,F as numberFormat,g as relativeTimeFormat};
|