@bevelo/date 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,302 @@
1
+ import { a as dayOfWeek, c as fromDate, d as isValidDate, f as toDate, i as Weekday, l as fromEpochDay, n as CivilDateTime, o as dayOfYear, p as toEpochDay, r as CivilTime, s as daysInMonth, t as CivilDate, u as isLeapYear } from "./civil-GPupvlwZ.cjs";
2
+ import { DateField, DateOrder, ParseTypedDateOptions, dateOrder, datePlaceholder, formatDateInput, parseDateInput, parseTypedDate } from "./pattern.cjs";
3
+ import { ZoneTime, ZonedParts, civilInZone, dayLength, formatInZone, instantFor, offsetAt, startOfDay as startOfDay$1, zoneIds, zonedParts } from "./timezone.cjs";
4
+ /**
5
+ * Largest day count `eachDay` and `eachDayInRange` will produce.
6
+ *
7
+ * A month or a year of days is a UI question; ten thousand days is already 27
8
+ * years, and anything larger is almost certainly a reversed or corrupted input
9
+ * that would allocate millions of objects. Throwing states the limit instead of
10
+ * silently truncating, which would return a range that looks complete.
11
+ */
12
+ export declare const MAX_RANGE_DAYS = 10000;
13
+ /**
14
+ * Adds a whole number of days.
15
+ *
16
+ * Works by converting to an epoch day, so month lengths, leap years and year
17
+ * boundaries need no special cases.
18
+ */
19
+ export declare function addDays(date: CivilDate, days: number): CivilDate;
20
+ /**
21
+ * Adds a whole number of months, clamping the day to the target month's length.
22
+ *
23
+ * Jan 31 + 1 month is Feb 28 (Feb 29 in a leap year), not Mar 2: the result is
24
+ * "the same day of the next month, or the last day of that month if it is
25
+ * shorter", which is the behaviour a date picker's stepper needs. Rejected
26
+ * alternative: overflow into the next month (what Date.setMonth does), which
27
+ * makes the stepper walk forward when the user asked for one month.
28
+ */
29
+ export declare function addMonths(date: CivilDate, months: number): CivilDate;
30
+ /**
31
+ * Adds a whole number of years, clamping Feb 29 to Feb 28 in non-leap years.
32
+ *
33
+ * Implemented through addMonths so the clamping rule exists once.
34
+ */
35
+ export declare function addYears(date: CivilDate, years: number): CivilDate;
36
+ /**
37
+ * Start of the day.
38
+ *
39
+ * A CivilDate has no time, so the date is returned as a fresh copy. The
40
+ * CivilDateTime overload resets the time to midnight, which is what a calendar
41
+ * needs when it turns a day cell into an instant. Both shapes are supported so
42
+ * a caller holding either type does not have to branch.
43
+ */
44
+ export declare function startOfDay(date: CivilDate): CivilDate;
45
+ export declare function startOfDay(dateTime: CivilDateTime): CivilDateTime;
46
+ /** The first day of the month. */
47
+ export declare function startOfMonth(date: CivilDate): CivilDate;
48
+ /** The last day of the month (28, 29, 30 or 31). */
49
+ export declare function endOfMonth(date: CivilDate): CivilDate;
50
+ /**
51
+ * The first day of the week containing `date`.
52
+ *
53
+ * `weekStartsOn` is an explicit input rather than a locale lookup: the locale
54
+ * decides what a calendar displays, and the caller owns that policy.
55
+ */
56
+ export declare function startOfWeek(date: CivilDate, weekStartsOn: Weekday): CivilDate;
57
+ /** The last day of the week containing `date` (the day before the next week starts). */
58
+ export declare function endOfWeek(date: CivilDate, weekStartsOn: Weekday): CivilDate;
59
+ /** True when both dates name the same calendar day. */
60
+ export declare function isSameDay(a: CivilDate, b: CivilDate): boolean;
61
+ /** True when both dates are in the same year and month. */
62
+ export declare function isSameMonth(a: CivilDate, b: CivilDate): boolean;
63
+ /**
64
+ * Orders two dates: -1 when `a` is earlier, 0 when equal, 1 when later.
65
+ *
66
+ * A comparator rather than a boolean because Array.prototype.sort needs exactly
67
+ * this shape, and callers need the direction.
68
+ */
69
+ export declare function compare(a: CivilDate, b: CivilDate): -1 | 0 | 1;
70
+ /**
71
+ * The earliest of the given dates.
72
+ *
73
+ * Accepts either an array (a list already in hand) or the first date plus rest
74
+ * (a list from variables). Ties keep the first occurrence, and an empty list
75
+ * throws: there is no honest "minimum of nothing".
76
+ */
77
+ export declare function min(dates: readonly CivilDate[]): CivilDate;
78
+ export declare function min(first: CivilDate, ...rest: CivilDate[]): CivilDate;
79
+ /** The latest of the given dates; same input shapes and tie rules as `min`. */
80
+ export declare function max(dates: readonly CivilDate[]): CivilDate;
81
+ export declare function max(first: CivilDate, ...rest: CivilDate[]): CivilDate;
82
+ /**
83
+ * Every day from `from` to `to`, inclusive, in ascending order.
84
+ *
85
+ * Returns an empty array when `from` is after `to` (a reversed range is an
86
+ * empty selection, not an error) and throws when the span exceeds
87
+ * MAX_RANGE_DAYS so a bad range cannot allocate without bound.
88
+ */
89
+ export declare function eachDay(from: CivilDate, to: CivilDate): CivilDate[];
90
+ /**
91
+ * Days from `from` to `to`: positive when `to` is later, negative when earlier,
92
+ * zero on the same day.
93
+ *
94
+ * Signed because a UI that says "3 days early" needs the direction; the absolute
95
+ * difference is `Math.abs(differenceInDays(a, b))`.
96
+ */
97
+ export declare function differenceInDays(from: CivilDate, to: CivilDate): number;
98
+ /** One cell of a month grid. */
99
+ type MonthGridCell = {
100
+ date: CivilDate;
101
+ /** False for a day that belongs to the previous or next month. */
102
+ inMonth: boolean;
103
+ };
104
+ /** Input for `generateMonthGrid`; defaults are declared once, below. */
105
+ type MonthGridOptions = {
106
+ /** Any day in the month to generate; the day itself is ignored. */
107
+ month: CivilDate;
108
+ /** First column of the grid. Defaults to Sunday, the 0..6 index's own order. */
109
+ weekStartsOn?: Weekday;
110
+ /** Whether leading/trailing days of adjacent months are included. Defaults to true. */
111
+ showOutsideDays?: boolean;
112
+ };
113
+ /** One entry of `generateYear`. */
114
+ type YearMonth = {
115
+ /** Month, 1..12. */
116
+ month: number;
117
+ /** Number of days in that month of that year. */
118
+ days: number;
119
+ };
120
+ /** An ISO-8601 week: weeks start Monday, week 1 is the week containing Jan 4. */
121
+ type IsoWeek = {
122
+ /** ISO week-numbering year, which can differ from the civil year. */
123
+ year: number;
124
+ /** Week number, 1..53. */
125
+ week: number;
126
+ };
127
+ /**
128
+ * Builds the weeks of a month grid.
129
+ *
130
+ * Always 4 to 6 rows and deterministic for the same inputs. With the default
131
+ * `showOutsideDays: true` every row has seven cells; every cell carries a
132
+ * complete CivilDate so a renderer never has to deal with a null or invent a
133
+ * placeholder.
134
+ *
135
+ * When `showOutsideDays` is false, cells of adjacent months are removed from
136
+ * the first and last rows, which can therefore be shorter than seven. This is a
137
+ * deliberate deviation from the seven-column shape: the cell type has no null,
138
+ * so leaving a hole would mean fabricating a date for it, and repacking the days
139
+ * would move Feb 1 out of its weekday column. Callers that need a fixed column
140
+ * count (the common case, and the default) keep outside days and use
141
+ * `inMonth` to blank them.
142
+ */
143
+ export declare function generateMonthGrid(options: MonthGridOptions): MonthGridCell[][];
144
+ /**
145
+ * The twelve months of a year with their lengths.
146
+ *
147
+ * A year view only needs names (from Intl, in the view) and lengths (here); it
148
+ * does not need 365 dates, so this returns the small summary.
149
+ */
150
+ export declare function generateYear(year: number): YearMonth[];
151
+ /**
152
+ * The ISO-8601 week number of a date.
153
+ *
154
+ * ISO weeks start Monday and week 1 is the week containing January 4, which
155
+ * means late December can belong to the next year's week 1 and early January to
156
+ * the previous year's last week. Computed from the ordinal day and the ISO
157
+ * weekday rather than by counting Thursdays, which is equivalent and shorter.
158
+ */
159
+ export declare function isoWeek(date: CivilDate): IsoWeek;
160
+ /**
161
+ * Number of ISO weeks in a year: 53 when January 1 is a Thursday, or a Wednesday
162
+ * in a leap year; 52 otherwise.
163
+ *
164
+ * Anchored on January 1 rather than on December 31 so the rule fits in one
165
+ * expression: a year has 53 ISO weeks exactly when it has a Thursday in its
166
+ * final week, which happens when Jan 1 is Thu (or Wed in a leap year).
167
+ */
168
+ export declare function isoWeeksInYear(year: number): number;
169
+ /**
170
+ * Short weekday names in a locale, ordered from `weekStartsOn`.
171
+ *
172
+ * Intl supplies the names (never a hand-rolled table: that is wrong for most
173
+ * locales). When Intl is unavailable or the locale is malformed, the English
174
+ * three-letter names are returned so a calendar still renders instead of
175
+ * throwing over a locale string.
176
+ */
177
+ export declare function weekdayNames(locale: string, weekStartsOn: Weekday): string[];
178
+ /** An inclusive range of civil dates. */
179
+ type DateRange = {
180
+ start: CivilDate;
181
+ end: CivilDate;
182
+ };
183
+ /**
184
+ * Orders the endpoints, returning a fresh range. Reversed ranges come out of a
185
+ * pointer drag before the user has dragged far enough, so normalizing is the
186
+ * default rather than the caller's responsibility.
187
+ */
188
+ export declare function normalizeRange(range: DateRange): DateRange;
189
+ /** True when `date` is inside the range, endpoints included. */
190
+ export declare function rangeContains(range: DateRange, date: CivilDate): boolean;
191
+ /**
192
+ * True when the two ranges share at least one day.
193
+ *
194
+ * Inclusive endpoints mean ranges that touch (one ends the day before the other
195
+ * starts) do not overlap; that distinction is what mergeRanges uses.
196
+ */
197
+ export declare function rangesOverlap(a: DateRange, b: DateRange): boolean;
198
+ /**
199
+ * The days both ranges contain, or undefined when they are disjoint.
200
+ *
201
+ * Undefined rather than an empty range: an empty inclusive range has no
202
+ * representation (end would be the day before start), and callers need to know
203
+ * the difference between "no overlap" and "a range covering zero days".
204
+ */
205
+ export declare function intersectRanges(a: DateRange, b: DateRange): DateRange | undefined;
206
+ /**
207
+ * Sorts and coalesces overlapping or adjacent ranges.
208
+ *
209
+ * Adjacent means one range ends the day before the next begins: with inclusive
210
+ * ends, Jan 1-5 and Jan 6-10 are one continuous selection, and showing two chips
211
+ * for it would be wrong. The input array and its dates are not mutated.
212
+ */
213
+ export declare function mergeRanges(list: readonly DateRange[]): DateRange[];
214
+ /**
215
+ * Clips a range to `bounds`, or undefined when they do not intersect.
216
+ *
217
+ * Clamping rather than shifting: a selection outside the allowed window should
218
+ * shrink to the visible part, not slide into it.
219
+ */
220
+ export declare function clampRange(range: DateRange, bounds: DateRange): DateRange | undefined;
221
+ /** Number of days in the range, endpoints included; at least 1. */
222
+ export declare function rangeLength(range: DateRange): number;
223
+ /** Every day of the range, ascending; capped by eachDay's MAX_RANGE_DAYS. */
224
+ export declare function eachDayInRange(range: DateRange): CivilDate[];
225
+ /** `Intl.DateTimeFormat` date styles: 3/5/24, Mar 5, 2024, March 5, 2024, Tuesday, March 5, 2024. */
226
+ type DateFormatStyle = "short" | "medium" | "long" | "full";
227
+ /** Options for `formatDate`. */
228
+ type FormatDateOptions = {
229
+ /** BCP 47 tag. Defaults to "en-US" so output does not change with the host. */
230
+ locale?: string;
231
+ /** Defaults to "medium". */
232
+ style?: DateFormatStyle;
233
+ };
234
+ /** Options for `formatRange` and `formatRelative`. */
235
+ type FormatLocaleOptions = {
236
+ /** BCP 47 tag. Defaults to "en-US". */
237
+ locale?: string;
238
+ };
239
+ /** Options for `parseDate`. */
240
+ type ParseDateOptions = {
241
+ /** BCP 47 tag whose numeric field order is used for non-ISO input. Defaults to "en-US". */
242
+ locale?: string;
243
+ };
244
+ /**
245
+ * Formats a date for display.
246
+ *
247
+ * @example formatDate({ year: 2024, month: 3, day: 5 }, { locale: "en-US", style: "long" }) // "March 5, 2024"
248
+ *
249
+ * Falls back to `formatISODate` when Intl is unavailable or the locale is
250
+ * malformed; a stray locale string should not crash a calendar.
251
+ */
252
+ export declare function formatDate(date: CivilDate, options?: FormatDateOptions): string;
253
+ /**
254
+ * Formats both ends of an inclusive range.
255
+ *
256
+ * The range is normalized first, so a reversed selection still renders in
257
+ * chronological order. Falls back to two ISO dates joined by an en dash when
258
+ * Intl or `formatRange` is missing.
259
+ */
260
+ export declare function formatRange(range: DateRange, options?: FormatLocaleOptions): string;
261
+ /**
262
+ * Formats a date relative to `now`.
263
+ *
264
+ * The ladder is deliberate: days under a week, then weeks under a month, then
265
+ * months under a year, then years — so the output stays useful at any distance
266
+ * instead of saying "412 days ago". Rounded with a minimum magnitude of one, so
267
+ * 8 days is "last week" and not "this week". `now` is an argument rather than
268
+ * Date.now() because a relative label must be reproducible in a test.
269
+ *
270
+ * Falls back to the date's ISO form when Intl is unavailable.
271
+ */
272
+ export declare function formatRelative(date: CivilDate, now: CivilDate, options?: FormatLocaleOptions): string;
273
+ /**
274
+ * Parses a date string, returning undefined instead of throwing.
275
+ *
276
+ * ISO `YYYY-MM-DD` (including expanded years like `+010000-01-01`) is tried
277
+ * first because it is unambiguous. Then the locale's numeric form is tried, in
278
+ * the field order Intl reports for that locale (`dateOrder`, from pattern.ts):
279
+ * "3/5/2024" is March 5 in en-US and "05/03/2024" is March 5 in en-GB. Only
280
+ * four-digit years are accepted, so a 2-digit year can never be silently
281
+ * reinterpreted. A malformed tag falls back to that function's ISO order, the
282
+ * same floor `formatDate` uses, so reading and writing agree.
283
+ *
284
+ * Undefined is the contract rather than an exception: this runs on every
285
+ * keystroke of a date input.
286
+ */
287
+ export declare function parseDate(input: string, options?: ParseDateOptions): CivilDate | undefined;
288
+ /**
289
+ * ISO 8601 date, e.g. "2024-03-05".
290
+ *
291
+ * Years outside 0..9999 use the expanded form ("+010000", "-000001") so the
292
+ * string always round-trips through the expanded-year parser.
293
+ */
294
+ export declare function formatISODate(date: CivilDate): string;
295
+ /**
296
+ * ISO 8601 date-time without a zone suffix, e.g. "2024-03-05T09:07:00.005".
297
+ *
298
+ * No "Z": a civil date-time names a wall clock, not an instant, and appending Z
299
+ * would be a lie about a timezone this type does not have.
300
+ */
301
+ export declare function formatISODateTime(value: CivilDateTime): string;
302
+ export { type CivilDate, type CivilDateTime, type CivilTime, type DateField, type DateFormatStyle, type DateOrder, type DateRange, type FormatDateOptions, type FormatLocaleOptions, type IsoWeek, type MonthGridCell, type MonthGridOptions, type ParseDateOptions, type ParseTypedDateOptions, type Weekday, type YearMonth, type ZoneTime, type ZonedParts, civilInZone, dateOrder, datePlaceholder, dayLength, dayOfWeek, dayOfYear, daysInMonth, formatDateInput, formatInZone, fromDate, fromEpochDay, instantFor, isLeapYear, isValidDate, offsetAt, parseDateInput, parseTypedDate, startOfDay$1 as startOfDayInZone, toDate, toEpochDay, zoneIds, zonedParts };
@@ -0,0 +1,302 @@
1
+ import { a as dayOfWeek, c as fromDate, d as isValidDate, f as toDate, i as Weekday, l as fromEpochDay, n as CivilDateTime, o as dayOfYear, p as toEpochDay, r as CivilTime, s as daysInMonth, t as CivilDate, u as isLeapYear } from "./civil-GPupvlwZ.js";
2
+ import { DateField, DateOrder, ParseTypedDateOptions, dateOrder, datePlaceholder, formatDateInput, parseDateInput, parseTypedDate } from "./pattern.js";
3
+ import { ZoneTime, ZonedParts, civilInZone, dayLength, formatInZone, instantFor, offsetAt, startOfDay as startOfDay$1, zoneIds, zonedParts } from "./timezone.js";
4
+ /**
5
+ * Largest day count `eachDay` and `eachDayInRange` will produce.
6
+ *
7
+ * A month or a year of days is a UI question; ten thousand days is already 27
8
+ * years, and anything larger is almost certainly a reversed or corrupted input
9
+ * that would allocate millions of objects. Throwing states the limit instead of
10
+ * silently truncating, which would return a range that looks complete.
11
+ */
12
+ export declare const MAX_RANGE_DAYS = 10000;
13
+ /**
14
+ * Adds a whole number of days.
15
+ *
16
+ * Works by converting to an epoch day, so month lengths, leap years and year
17
+ * boundaries need no special cases.
18
+ */
19
+ export declare function addDays(date: CivilDate, days: number): CivilDate;
20
+ /**
21
+ * Adds a whole number of months, clamping the day to the target month's length.
22
+ *
23
+ * Jan 31 + 1 month is Feb 28 (Feb 29 in a leap year), not Mar 2: the result is
24
+ * "the same day of the next month, or the last day of that month if it is
25
+ * shorter", which is the behaviour a date picker's stepper needs. Rejected
26
+ * alternative: overflow into the next month (what Date.setMonth does), which
27
+ * makes the stepper walk forward when the user asked for one month.
28
+ */
29
+ export declare function addMonths(date: CivilDate, months: number): CivilDate;
30
+ /**
31
+ * Adds a whole number of years, clamping Feb 29 to Feb 28 in non-leap years.
32
+ *
33
+ * Implemented through addMonths so the clamping rule exists once.
34
+ */
35
+ export declare function addYears(date: CivilDate, years: number): CivilDate;
36
+ /**
37
+ * Start of the day.
38
+ *
39
+ * A CivilDate has no time, so the date is returned as a fresh copy. The
40
+ * CivilDateTime overload resets the time to midnight, which is what a calendar
41
+ * needs when it turns a day cell into an instant. Both shapes are supported so
42
+ * a caller holding either type does not have to branch.
43
+ */
44
+ export declare function startOfDay(date: CivilDate): CivilDate;
45
+ export declare function startOfDay(dateTime: CivilDateTime): CivilDateTime;
46
+ /** The first day of the month. */
47
+ export declare function startOfMonth(date: CivilDate): CivilDate;
48
+ /** The last day of the month (28, 29, 30 or 31). */
49
+ export declare function endOfMonth(date: CivilDate): CivilDate;
50
+ /**
51
+ * The first day of the week containing `date`.
52
+ *
53
+ * `weekStartsOn` is an explicit input rather than a locale lookup: the locale
54
+ * decides what a calendar displays, and the caller owns that policy.
55
+ */
56
+ export declare function startOfWeek(date: CivilDate, weekStartsOn: Weekday): CivilDate;
57
+ /** The last day of the week containing `date` (the day before the next week starts). */
58
+ export declare function endOfWeek(date: CivilDate, weekStartsOn: Weekday): CivilDate;
59
+ /** True when both dates name the same calendar day. */
60
+ export declare function isSameDay(a: CivilDate, b: CivilDate): boolean;
61
+ /** True when both dates are in the same year and month. */
62
+ export declare function isSameMonth(a: CivilDate, b: CivilDate): boolean;
63
+ /**
64
+ * Orders two dates: -1 when `a` is earlier, 0 when equal, 1 when later.
65
+ *
66
+ * A comparator rather than a boolean because Array.prototype.sort needs exactly
67
+ * this shape, and callers need the direction.
68
+ */
69
+ export declare function compare(a: CivilDate, b: CivilDate): -1 | 0 | 1;
70
+ /**
71
+ * The earliest of the given dates.
72
+ *
73
+ * Accepts either an array (a list already in hand) or the first date plus rest
74
+ * (a list from variables). Ties keep the first occurrence, and an empty list
75
+ * throws: there is no honest "minimum of nothing".
76
+ */
77
+ export declare function min(dates: readonly CivilDate[]): CivilDate;
78
+ export declare function min(first: CivilDate, ...rest: CivilDate[]): CivilDate;
79
+ /** The latest of the given dates; same input shapes and tie rules as `min`. */
80
+ export declare function max(dates: readonly CivilDate[]): CivilDate;
81
+ export declare function max(first: CivilDate, ...rest: CivilDate[]): CivilDate;
82
+ /**
83
+ * Every day from `from` to `to`, inclusive, in ascending order.
84
+ *
85
+ * Returns an empty array when `from` is after `to` (a reversed range is an
86
+ * empty selection, not an error) and throws when the span exceeds
87
+ * MAX_RANGE_DAYS so a bad range cannot allocate without bound.
88
+ */
89
+ export declare function eachDay(from: CivilDate, to: CivilDate): CivilDate[];
90
+ /**
91
+ * Days from `from` to `to`: positive when `to` is later, negative when earlier,
92
+ * zero on the same day.
93
+ *
94
+ * Signed because a UI that says "3 days early" needs the direction; the absolute
95
+ * difference is `Math.abs(differenceInDays(a, b))`.
96
+ */
97
+ export declare function differenceInDays(from: CivilDate, to: CivilDate): number;
98
+ /** One cell of a month grid. */
99
+ type MonthGridCell = {
100
+ date: CivilDate;
101
+ /** False for a day that belongs to the previous or next month. */
102
+ inMonth: boolean;
103
+ };
104
+ /** Input for `generateMonthGrid`; defaults are declared once, below. */
105
+ type MonthGridOptions = {
106
+ /** Any day in the month to generate; the day itself is ignored. */
107
+ month: CivilDate;
108
+ /** First column of the grid. Defaults to Sunday, the 0..6 index's own order. */
109
+ weekStartsOn?: Weekday;
110
+ /** Whether leading/trailing days of adjacent months are included. Defaults to true. */
111
+ showOutsideDays?: boolean;
112
+ };
113
+ /** One entry of `generateYear`. */
114
+ type YearMonth = {
115
+ /** Month, 1..12. */
116
+ month: number;
117
+ /** Number of days in that month of that year. */
118
+ days: number;
119
+ };
120
+ /** An ISO-8601 week: weeks start Monday, week 1 is the week containing Jan 4. */
121
+ type IsoWeek = {
122
+ /** ISO week-numbering year, which can differ from the civil year. */
123
+ year: number;
124
+ /** Week number, 1..53. */
125
+ week: number;
126
+ };
127
+ /**
128
+ * Builds the weeks of a month grid.
129
+ *
130
+ * Always 4 to 6 rows and deterministic for the same inputs. With the default
131
+ * `showOutsideDays: true` every row has seven cells; every cell carries a
132
+ * complete CivilDate so a renderer never has to deal with a null or invent a
133
+ * placeholder.
134
+ *
135
+ * When `showOutsideDays` is false, cells of adjacent months are removed from
136
+ * the first and last rows, which can therefore be shorter than seven. This is a
137
+ * deliberate deviation from the seven-column shape: the cell type has no null,
138
+ * so leaving a hole would mean fabricating a date for it, and repacking the days
139
+ * would move Feb 1 out of its weekday column. Callers that need a fixed column
140
+ * count (the common case, and the default) keep outside days and use
141
+ * `inMonth` to blank them.
142
+ */
143
+ export declare function generateMonthGrid(options: MonthGridOptions): MonthGridCell[][];
144
+ /**
145
+ * The twelve months of a year with their lengths.
146
+ *
147
+ * A year view only needs names (from Intl, in the view) and lengths (here); it
148
+ * does not need 365 dates, so this returns the small summary.
149
+ */
150
+ export declare function generateYear(year: number): YearMonth[];
151
+ /**
152
+ * The ISO-8601 week number of a date.
153
+ *
154
+ * ISO weeks start Monday and week 1 is the week containing January 4, which
155
+ * means late December can belong to the next year's week 1 and early January to
156
+ * the previous year's last week. Computed from the ordinal day and the ISO
157
+ * weekday rather than by counting Thursdays, which is equivalent and shorter.
158
+ */
159
+ export declare function isoWeek(date: CivilDate): IsoWeek;
160
+ /**
161
+ * Number of ISO weeks in a year: 53 when January 1 is a Thursday, or a Wednesday
162
+ * in a leap year; 52 otherwise.
163
+ *
164
+ * Anchored on January 1 rather than on December 31 so the rule fits in one
165
+ * expression: a year has 53 ISO weeks exactly when it has a Thursday in its
166
+ * final week, which happens when Jan 1 is Thu (or Wed in a leap year).
167
+ */
168
+ export declare function isoWeeksInYear(year: number): number;
169
+ /**
170
+ * Short weekday names in a locale, ordered from `weekStartsOn`.
171
+ *
172
+ * Intl supplies the names (never a hand-rolled table: that is wrong for most
173
+ * locales). When Intl is unavailable or the locale is malformed, the English
174
+ * three-letter names are returned so a calendar still renders instead of
175
+ * throwing over a locale string.
176
+ */
177
+ export declare function weekdayNames(locale: string, weekStartsOn: Weekday): string[];
178
+ /** An inclusive range of civil dates. */
179
+ type DateRange = {
180
+ start: CivilDate;
181
+ end: CivilDate;
182
+ };
183
+ /**
184
+ * Orders the endpoints, returning a fresh range. Reversed ranges come out of a
185
+ * pointer drag before the user has dragged far enough, so normalizing is the
186
+ * default rather than the caller's responsibility.
187
+ */
188
+ export declare function normalizeRange(range: DateRange): DateRange;
189
+ /** True when `date` is inside the range, endpoints included. */
190
+ export declare function rangeContains(range: DateRange, date: CivilDate): boolean;
191
+ /**
192
+ * True when the two ranges share at least one day.
193
+ *
194
+ * Inclusive endpoints mean ranges that touch (one ends the day before the other
195
+ * starts) do not overlap; that distinction is what mergeRanges uses.
196
+ */
197
+ export declare function rangesOverlap(a: DateRange, b: DateRange): boolean;
198
+ /**
199
+ * The days both ranges contain, or undefined when they are disjoint.
200
+ *
201
+ * Undefined rather than an empty range: an empty inclusive range has no
202
+ * representation (end would be the day before start), and callers need to know
203
+ * the difference between "no overlap" and "a range covering zero days".
204
+ */
205
+ export declare function intersectRanges(a: DateRange, b: DateRange): DateRange | undefined;
206
+ /**
207
+ * Sorts and coalesces overlapping or adjacent ranges.
208
+ *
209
+ * Adjacent means one range ends the day before the next begins: with inclusive
210
+ * ends, Jan 1-5 and Jan 6-10 are one continuous selection, and showing two chips
211
+ * for it would be wrong. The input array and its dates are not mutated.
212
+ */
213
+ export declare function mergeRanges(list: readonly DateRange[]): DateRange[];
214
+ /**
215
+ * Clips a range to `bounds`, or undefined when they do not intersect.
216
+ *
217
+ * Clamping rather than shifting: a selection outside the allowed window should
218
+ * shrink to the visible part, not slide into it.
219
+ */
220
+ export declare function clampRange(range: DateRange, bounds: DateRange): DateRange | undefined;
221
+ /** Number of days in the range, endpoints included; at least 1. */
222
+ export declare function rangeLength(range: DateRange): number;
223
+ /** Every day of the range, ascending; capped by eachDay's MAX_RANGE_DAYS. */
224
+ export declare function eachDayInRange(range: DateRange): CivilDate[];
225
+ /** `Intl.DateTimeFormat` date styles: 3/5/24, Mar 5, 2024, March 5, 2024, Tuesday, March 5, 2024. */
226
+ type DateFormatStyle = "short" | "medium" | "long" | "full";
227
+ /** Options for `formatDate`. */
228
+ type FormatDateOptions = {
229
+ /** BCP 47 tag. Defaults to "en-US" so output does not change with the host. */
230
+ locale?: string;
231
+ /** Defaults to "medium". */
232
+ style?: DateFormatStyle;
233
+ };
234
+ /** Options for `formatRange` and `formatRelative`. */
235
+ type FormatLocaleOptions = {
236
+ /** BCP 47 tag. Defaults to "en-US". */
237
+ locale?: string;
238
+ };
239
+ /** Options for `parseDate`. */
240
+ type ParseDateOptions = {
241
+ /** BCP 47 tag whose numeric field order is used for non-ISO input. Defaults to "en-US". */
242
+ locale?: string;
243
+ };
244
+ /**
245
+ * Formats a date for display.
246
+ *
247
+ * @example formatDate({ year: 2024, month: 3, day: 5 }, { locale: "en-US", style: "long" }) // "March 5, 2024"
248
+ *
249
+ * Falls back to `formatISODate` when Intl is unavailable or the locale is
250
+ * malformed; a stray locale string should not crash a calendar.
251
+ */
252
+ export declare function formatDate(date: CivilDate, options?: FormatDateOptions): string;
253
+ /**
254
+ * Formats both ends of an inclusive range.
255
+ *
256
+ * The range is normalized first, so a reversed selection still renders in
257
+ * chronological order. Falls back to two ISO dates joined by an en dash when
258
+ * Intl or `formatRange` is missing.
259
+ */
260
+ export declare function formatRange(range: DateRange, options?: FormatLocaleOptions): string;
261
+ /**
262
+ * Formats a date relative to `now`.
263
+ *
264
+ * The ladder is deliberate: days under a week, then weeks under a month, then
265
+ * months under a year, then years — so the output stays useful at any distance
266
+ * instead of saying "412 days ago". Rounded with a minimum magnitude of one, so
267
+ * 8 days is "last week" and not "this week". `now` is an argument rather than
268
+ * Date.now() because a relative label must be reproducible in a test.
269
+ *
270
+ * Falls back to the date's ISO form when Intl is unavailable.
271
+ */
272
+ export declare function formatRelative(date: CivilDate, now: CivilDate, options?: FormatLocaleOptions): string;
273
+ /**
274
+ * Parses a date string, returning undefined instead of throwing.
275
+ *
276
+ * ISO `YYYY-MM-DD` (including expanded years like `+010000-01-01`) is tried
277
+ * first because it is unambiguous. Then the locale's numeric form is tried, in
278
+ * the field order Intl reports for that locale (`dateOrder`, from pattern.ts):
279
+ * "3/5/2024" is March 5 in en-US and "05/03/2024" is March 5 in en-GB. Only
280
+ * four-digit years are accepted, so a 2-digit year can never be silently
281
+ * reinterpreted. A malformed tag falls back to that function's ISO order, the
282
+ * same floor `formatDate` uses, so reading and writing agree.
283
+ *
284
+ * Undefined is the contract rather than an exception: this runs on every
285
+ * keystroke of a date input.
286
+ */
287
+ export declare function parseDate(input: string, options?: ParseDateOptions): CivilDate | undefined;
288
+ /**
289
+ * ISO 8601 date, e.g. "2024-03-05".
290
+ *
291
+ * Years outside 0..9999 use the expanded form ("+010000", "-000001") so the
292
+ * string always round-trips through the expanded-year parser.
293
+ */
294
+ export declare function formatISODate(date: CivilDate): string;
295
+ /**
296
+ * ISO 8601 date-time without a zone suffix, e.g. "2024-03-05T09:07:00.005".
297
+ *
298
+ * No "Z": a civil date-time names a wall clock, not an instant, and appending Z
299
+ * would be a lie about a timezone this type does not have.
300
+ */
301
+ export declare function formatISODateTime(value: CivilDateTime): string;
302
+ export { type CivilDate, type CivilDateTime, type CivilTime, type DateField, type DateFormatStyle, type DateOrder, type DateRange, type FormatDateOptions, type FormatLocaleOptions, type IsoWeek, type MonthGridCell, type MonthGridOptions, type ParseDateOptions, type ParseTypedDateOptions, type Weekday, type YearMonth, type ZoneTime, type ZonedParts, civilInZone, dateOrder, datePlaceholder, dayLength, dayOfWeek, dayOfYear, daysInMonth, formatDateInput, formatInZone, fromDate, fromEpochDay, instantFor, isLeapYear, isValidDate, offsetAt, parseDateInput, parseTypedDate, startOfDay$1 as startOfDayInZone, toDate, toEpochDay, zoneIds, zonedParts };