@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.
- package/LICENSE +21 -0
- package/README.md +35 -2
- package/dist/civil-GPupvlwZ.d.cts +116 -0
- package/dist/civil-GPupvlwZ.d.ts +116 -0
- package/dist/civil-QU5EukOm.cjs +461 -0
- package/dist/civil-SGLjw0gL.js +366 -0
- package/dist/index.cjs +506 -0
- package/dist/index.d.cts +302 -0
- package/dist/index.d.ts +302 -0
- package/dist/index.js +449 -0
- package/dist/pattern.cjs +328 -0
- package/dist/pattern.d.cts +75 -0
- package/dist/pattern.d.ts +75 -0
- package/dist/pattern.js +323 -0
- package/dist/timezone-BmJA-u4N.js +417 -0
- package/dist/timezone-DiMSaNmI.cjs +560 -0
- package/dist/timezone.cjs +10 -0
- package/dist/timezone.d.cts +108 -0
- package/dist/timezone.d.ts +108 -0
- package/dist/timezone.js +1 -0
- package/package.json +45 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_civil = require("./civil-QU5EukOm.cjs");
|
|
3
|
+
const require_timezone = require("./timezone-DiMSaNmI.cjs");
|
|
4
|
+
const require_pattern = require("./pattern.cjs");
|
|
5
|
+
// src/calendar.ts
|
|
6
|
+
const MONTH_GRID_DEFAULTS = {
|
|
7
|
+
weekStartsOn: 0,
|
|
8
|
+
showOutsideDays: true
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Builds the weeks of a month grid.
|
|
12
|
+
*
|
|
13
|
+
* Always 4 to 6 rows and deterministic for the same inputs. With the default
|
|
14
|
+
* `showOutsideDays: true` every row has seven cells; every cell carries a
|
|
15
|
+
* complete CivilDate so a renderer never has to deal with a null or invent a
|
|
16
|
+
* placeholder.
|
|
17
|
+
*
|
|
18
|
+
* When `showOutsideDays` is false, cells of adjacent months are removed from
|
|
19
|
+
* the first and last rows, which can therefore be shorter than seven. This is a
|
|
20
|
+
* deliberate deviation from the seven-column shape: the cell type has no null,
|
|
21
|
+
* so leaving a hole would mean fabricating a date for it, and repacking the days
|
|
22
|
+
* would move Feb 1 out of its weekday column. Callers that need a fixed column
|
|
23
|
+
* count (the common case, and the default) keep outside days and use
|
|
24
|
+
* `inMonth` to blank them.
|
|
25
|
+
*/
|
|
26
|
+
function generateMonthGrid(options) {
|
|
27
|
+
const { month } = options;
|
|
28
|
+
require_civil.assertValidDate(month);
|
|
29
|
+
const weekStartsOn = options.weekStartsOn ?? MONTH_GRID_DEFAULTS.weekStartsOn;
|
|
30
|
+
const showOutsideDays = options.showOutsideDays ?? MONTH_GRID_DEFAULTS.showOutsideDays;
|
|
31
|
+
require_civil.assertWeekday(weekStartsOn);
|
|
32
|
+
const first = require_timezone.startOfWeek(require_timezone.startOfMonth(month), weekStartsOn);
|
|
33
|
+
const last = require_timezone.endOfWeek(require_timezone.endOfMonth(month), weekStartsOn);
|
|
34
|
+
const start = require_civil.toEpochDay(first);
|
|
35
|
+
const end = require_civil.toEpochDay(last);
|
|
36
|
+
const cells = [];
|
|
37
|
+
for (let day = start; day <= end; day += 1) {
|
|
38
|
+
const date = require_civil.fromEpochDay(day);
|
|
39
|
+
cells.push({
|
|
40
|
+
date,
|
|
41
|
+
inMonth: date.year === month.year && date.month === month.month
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const weeks = [];
|
|
45
|
+
for (let index = 0; index < cells.length; index += 7) {
|
|
46
|
+
const week = cells.slice(index, index + 7);
|
|
47
|
+
weeks.push(showOutsideDays ? week : week.filter((cell) => cell.inMonth));
|
|
48
|
+
}
|
|
49
|
+
return weeks;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The twelve months of a year with their lengths.
|
|
53
|
+
*
|
|
54
|
+
* A year view only needs names (from Intl, in the view) and lengths (here); it
|
|
55
|
+
* does not need 365 dates, so this returns the small summary.
|
|
56
|
+
*/
|
|
57
|
+
function generateYear(year) {
|
|
58
|
+
const months = [];
|
|
59
|
+
for (let month = 1; month <= 12; month += 1) months.push({
|
|
60
|
+
month,
|
|
61
|
+
days: require_civil.daysInMonth(year, month)
|
|
62
|
+
});
|
|
63
|
+
return months;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The ISO-8601 week number of a date.
|
|
67
|
+
*
|
|
68
|
+
* ISO weeks start Monday and week 1 is the week containing January 4, which
|
|
69
|
+
* means late December can belong to the next year's week 1 and early January to
|
|
70
|
+
* the previous year's last week. Computed from the ordinal day and the ISO
|
|
71
|
+
* weekday rather than by counting Thursdays, which is equivalent and shorter.
|
|
72
|
+
*/
|
|
73
|
+
function isoWeek(date) {
|
|
74
|
+
require_civil.assertValidDate(date);
|
|
75
|
+
const sunday = require_civil.dayOfWeek(date);
|
|
76
|
+
const weekday = sunday === 0 ? 7 : sunday;
|
|
77
|
+
const ordinal = require_civil.dayOfYear(date);
|
|
78
|
+
const week = Math.floor((ordinal - weekday + 10) / 7);
|
|
79
|
+
if (week < 1) {
|
|
80
|
+
const previousYear = date.year - 1;
|
|
81
|
+
return {
|
|
82
|
+
year: previousYear,
|
|
83
|
+
week: isoWeeksInYear(previousYear)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (week > isoWeeksInYear(date.year)) return {
|
|
87
|
+
year: date.year + 1,
|
|
88
|
+
week: 1
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
year: date.year,
|
|
92
|
+
week
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Number of ISO weeks in a year: 53 when January 1 is a Thursday, or a Wednesday
|
|
97
|
+
* in a leap year; 52 otherwise.
|
|
98
|
+
*
|
|
99
|
+
* Anchored on January 1 rather than on December 31 so the rule fits in one
|
|
100
|
+
* expression: a year has 53 ISO weeks exactly when it has a Thursday in its
|
|
101
|
+
* final week, which happens when Jan 1 is Thu (or Wed in a leap year).
|
|
102
|
+
*/
|
|
103
|
+
function isoWeeksInYear(year) {
|
|
104
|
+
const januaryFirst = require_civil.dayOfWeek({
|
|
105
|
+
year,
|
|
106
|
+
month: 1,
|
|
107
|
+
day: 1
|
|
108
|
+
});
|
|
109
|
+
const isoJanuaryFirst = januaryFirst === 0 ? 7 : januaryFirst;
|
|
110
|
+
return isoJanuaryFirst === 4 || require_civil.isLeapYear(year) && isoJanuaryFirst === 3 ? 53 : 52;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Short weekday names in a locale, ordered from `weekStartsOn`.
|
|
114
|
+
*
|
|
115
|
+
* Intl supplies the names (never a hand-rolled table: that is wrong for most
|
|
116
|
+
* locales). When Intl is unavailable or the locale is malformed, the English
|
|
117
|
+
* three-letter names are returned so a calendar still renders instead of
|
|
118
|
+
* throwing over a locale string.
|
|
119
|
+
*/
|
|
120
|
+
function weekdayNames(locale, weekStartsOn) {
|
|
121
|
+
require_civil.assertWeekday(weekStartsOn);
|
|
122
|
+
let base = ENGLISH_WEEKDAYS;
|
|
123
|
+
if (typeof Intl !== "undefined" && typeof Intl.DateTimeFormat === "function") try {
|
|
124
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
125
|
+
weekday: "short",
|
|
126
|
+
timeZone: "UTC"
|
|
127
|
+
});
|
|
128
|
+
base = SUNDAY_OFFSETS.map((offset) => formatter.format(new Date(Date.UTC(2021, 0, 3 + offset))));
|
|
129
|
+
} catch {
|
|
130
|
+
base = ENGLISH_WEEKDAYS;
|
|
131
|
+
}
|
|
132
|
+
return SUNDAY_OFFSETS.map((offset) => {
|
|
133
|
+
return base[(weekStartsOn + offset) % 7] ?? "";
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const SUNDAY_OFFSETS = [
|
|
137
|
+
0,
|
|
138
|
+
1,
|
|
139
|
+
2,
|
|
140
|
+
3,
|
|
141
|
+
4,
|
|
142
|
+
5,
|
|
143
|
+
6
|
|
144
|
+
];
|
|
145
|
+
const ENGLISH_WEEKDAYS = [
|
|
146
|
+
"Sun",
|
|
147
|
+
"Mon",
|
|
148
|
+
"Tue",
|
|
149
|
+
"Wed",
|
|
150
|
+
"Thu",
|
|
151
|
+
"Fri",
|
|
152
|
+
"Sat"
|
|
153
|
+
];
|
|
154
|
+
// src/range.ts
|
|
155
|
+
/**
|
|
156
|
+
* Orders the endpoints, returning a fresh range. Reversed ranges come out of a
|
|
157
|
+
* pointer drag before the user has dragged far enough, so normalizing is the
|
|
158
|
+
* default rather than the caller's responsibility.
|
|
159
|
+
*/
|
|
160
|
+
function normalizeRange(range) {
|
|
161
|
+
require_civil.assertValidDate(range.start);
|
|
162
|
+
require_civil.assertValidDate(range.end);
|
|
163
|
+
return require_civil.toEpochDay(range.start) <= require_civil.toEpochDay(range.end) ? {
|
|
164
|
+
start: { ...range.start },
|
|
165
|
+
end: { ...range.end }
|
|
166
|
+
} : {
|
|
167
|
+
start: { ...range.end },
|
|
168
|
+
end: { ...range.start }
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** True when `date` is inside the range, endpoints included. */
|
|
172
|
+
function rangeContains(range, date) {
|
|
173
|
+
const normalized = normalizeRange(range);
|
|
174
|
+
const value = require_civil.toEpochDay(date);
|
|
175
|
+
return require_civil.toEpochDay(normalized.start) <= value && value <= require_civil.toEpochDay(normalized.end);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* True when the two ranges share at least one day.
|
|
179
|
+
*
|
|
180
|
+
* Inclusive endpoints mean ranges that touch (one ends the day before the other
|
|
181
|
+
* starts) do not overlap; that distinction is what mergeRanges uses.
|
|
182
|
+
*/
|
|
183
|
+
function rangesOverlap(a, b) {
|
|
184
|
+
const left = normalizeRange(a);
|
|
185
|
+
const right = normalizeRange(b);
|
|
186
|
+
return require_civil.toEpochDay(left.start) <= require_civil.toEpochDay(right.end) && require_civil.toEpochDay(right.start) <= require_civil.toEpochDay(left.end);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The days both ranges contain, or undefined when they are disjoint.
|
|
190
|
+
*
|
|
191
|
+
* Undefined rather than an empty range: an empty inclusive range has no
|
|
192
|
+
* representation (end would be the day before start), and callers need to know
|
|
193
|
+
* the difference between "no overlap" and "a range covering zero days".
|
|
194
|
+
*/
|
|
195
|
+
function intersectRanges(a, b) {
|
|
196
|
+
const left = normalizeRange(a);
|
|
197
|
+
const right = normalizeRange(b);
|
|
198
|
+
const start = Math.max(require_civil.toEpochDay(left.start), require_civil.toEpochDay(right.start));
|
|
199
|
+
const end = Math.min(require_civil.toEpochDay(left.end), require_civil.toEpochDay(right.end));
|
|
200
|
+
if (start > end) return;
|
|
201
|
+
return {
|
|
202
|
+
start: require_civil.fromEpochDay(start),
|
|
203
|
+
end: require_civil.fromEpochDay(end)
|
|
204
|
+
};
|
|
205
|
+
}
|
|
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
|
+
function mergeRanges(list) {
|
|
214
|
+
const sorted = list.map((range) => normalizeRange(range)).sort((a, b) => require_civil.toEpochDay(a.start) - require_civil.toEpochDay(b.start));
|
|
215
|
+
const merged = [];
|
|
216
|
+
for (const range of sorted) {
|
|
217
|
+
const last = merged[merged.length - 1];
|
|
218
|
+
if (last !== void 0 && require_civil.toEpochDay(range.start) <= require_civil.toEpochDay(last.end) + 1) {
|
|
219
|
+
if (require_civil.toEpochDay(range.end) > require_civil.toEpochDay(last.end)) last.end = { ...range.end };
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
merged.push({
|
|
223
|
+
start: { ...range.start },
|
|
224
|
+
end: { ...range.end }
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return merged;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Clips a range to `bounds`, or undefined when they do not intersect.
|
|
231
|
+
*
|
|
232
|
+
* Clamping rather than shifting: a selection outside the allowed window should
|
|
233
|
+
* shrink to the visible part, not slide into it.
|
|
234
|
+
*/
|
|
235
|
+
function clampRange(range, bounds) {
|
|
236
|
+
return intersectRanges(range, bounds);
|
|
237
|
+
}
|
|
238
|
+
/** Number of days in the range, endpoints included; at least 1. */
|
|
239
|
+
function rangeLength(range) {
|
|
240
|
+
const normalized = normalizeRange(range);
|
|
241
|
+
return require_civil.toEpochDay(normalized.end) - require_civil.toEpochDay(normalized.start) + 1;
|
|
242
|
+
}
|
|
243
|
+
/** Every day of the range, ascending; capped by eachDay's MAX_RANGE_DAYS. */
|
|
244
|
+
function eachDayInRange(range) {
|
|
245
|
+
const normalized = normalizeRange(range);
|
|
246
|
+
return require_timezone.eachDay(normalized.start, normalized.end);
|
|
247
|
+
}
|
|
248
|
+
// src/format.ts
|
|
249
|
+
const DEFAULT_LOCALE = "en-US";
|
|
250
|
+
const DEFAULT_STYLE = "medium";
|
|
251
|
+
const dateFormatters = /* @__PURE__ */ new Map();
|
|
252
|
+
function dateFormatter(locale, style) {
|
|
253
|
+
const cacheKey = `${locale}\u0000${style}`;
|
|
254
|
+
const cached = dateFormatters.get(cacheKey);
|
|
255
|
+
if (cached !== void 0) return cached;
|
|
256
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
257
|
+
dateStyle: style,
|
|
258
|
+
timeZone: "UTC"
|
|
259
|
+
});
|
|
260
|
+
dateFormatters.set(cacheKey, formatter);
|
|
261
|
+
return formatter;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Formats a date for display.
|
|
265
|
+
*
|
|
266
|
+
* @example formatDate({ year: 2024, month: 3, day: 5 }, { locale: "en-US", style: "long" }) // "March 5, 2024"
|
|
267
|
+
*
|
|
268
|
+
* Falls back to `formatISODate` when Intl is unavailable or the locale is
|
|
269
|
+
* malformed; a stray locale string should not crash a calendar.
|
|
270
|
+
*/
|
|
271
|
+
function formatDate(date, options = {}) {
|
|
272
|
+
require_civil.assertValidDate(date);
|
|
273
|
+
if (!require_civil.hasIntl()) return formatISODate(date);
|
|
274
|
+
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
275
|
+
const style = options.style ?? DEFAULT_STYLE;
|
|
276
|
+
try {
|
|
277
|
+
return dateFormatter(locale, style).format(utcDate(date));
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (error instanceof RangeError) return formatISODate(date);
|
|
280
|
+
throw error;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const rangeFormatters = /* @__PURE__ */ new Map();
|
|
284
|
+
function rangeFormatter(locale) {
|
|
285
|
+
const cached = rangeFormatters.get(locale);
|
|
286
|
+
if (cached !== void 0) return cached;
|
|
287
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
288
|
+
dateStyle: DEFAULT_STYLE,
|
|
289
|
+
timeZone: "UTC"
|
|
290
|
+
});
|
|
291
|
+
rangeFormatters.set(locale, formatter);
|
|
292
|
+
return formatter;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Formats both ends of an inclusive range.
|
|
296
|
+
*
|
|
297
|
+
* The range is normalized first, so a reversed selection still renders in
|
|
298
|
+
* chronological order. Falls back to two ISO dates joined by an en dash when
|
|
299
|
+
* Intl or `formatRange` is missing.
|
|
300
|
+
*/
|
|
301
|
+
function formatRange(range, options = {}) {
|
|
302
|
+
const normalized = normalizeRange(range);
|
|
303
|
+
const fallback = `${formatISODate(normalized.start)} – ${formatISODate(normalized.end)}`;
|
|
304
|
+
if (!require_civil.hasIntl()) return fallback;
|
|
305
|
+
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
306
|
+
try {
|
|
307
|
+
const formatter = rangeFormatter(locale);
|
|
308
|
+
const start = utcDate(normalized.start);
|
|
309
|
+
const end = utcDate(normalized.end);
|
|
310
|
+
if (typeof formatter.formatRange === "function") return formatter.formatRange(start, end);
|
|
311
|
+
return `${formatter.format(start)} – ${formatter.format(end)}`;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
if (error instanceof RangeError) return fallback;
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Formats a date relative to `now`.
|
|
319
|
+
*
|
|
320
|
+
* The ladder is deliberate: days under a week, then weeks under a month, then
|
|
321
|
+
* months under a year, then years — so the output stays useful at any distance
|
|
322
|
+
* instead of saying "412 days ago". Rounded with a minimum magnitude of one, so
|
|
323
|
+
* 8 days is "last week" and not "this week". `now` is an argument rather than
|
|
324
|
+
* Date.now() because a relative label must be reproducible in a test.
|
|
325
|
+
*
|
|
326
|
+
* Falls back to the date's ISO form when Intl is unavailable.
|
|
327
|
+
*/
|
|
328
|
+
function formatRelative(date, now, options = {}) {
|
|
329
|
+
require_civil.assertValidDate(date);
|
|
330
|
+
require_civil.assertValidDate(now);
|
|
331
|
+
if (!require_civil.hasIntl() || typeof Intl.RelativeTimeFormat !== "function") return formatISODate(date);
|
|
332
|
+
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
333
|
+
const { value, unit } = relativeValue(require_timezone.differenceInDays(now, date));
|
|
334
|
+
try {
|
|
335
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: "auto" }).format(value, unit);
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (error instanceof RangeError) return formatISODate(date);
|
|
338
|
+
throw error;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function relativeValue(days) {
|
|
342
|
+
const magnitude = Math.abs(days);
|
|
343
|
+
const sign = days < 0 ? -1 : 1;
|
|
344
|
+
if (magnitude < 7) return {
|
|
345
|
+
value: days,
|
|
346
|
+
unit: "day"
|
|
347
|
+
};
|
|
348
|
+
if (magnitude < 30) return {
|
|
349
|
+
value: sign * Math.max(1, Math.round(magnitude / 7)),
|
|
350
|
+
unit: "week"
|
|
351
|
+
};
|
|
352
|
+
if (magnitude < 365) return {
|
|
353
|
+
value: sign * Math.max(1, Math.round(magnitude / 30.4375)),
|
|
354
|
+
unit: "month"
|
|
355
|
+
};
|
|
356
|
+
return {
|
|
357
|
+
value: sign * Math.max(1, Math.round(magnitude / 365.25)),
|
|
358
|
+
unit: "year"
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Parses a date string, returning undefined instead of throwing.
|
|
363
|
+
*
|
|
364
|
+
* ISO `YYYY-MM-DD` (including expanded years like `+010000-01-01`) is tried
|
|
365
|
+
* first because it is unambiguous. Then the locale's numeric form is tried, in
|
|
366
|
+
* the field order Intl reports for that locale (`dateOrder`, from pattern.ts):
|
|
367
|
+
* "3/5/2024" is March 5 in en-US and "05/03/2024" is March 5 in en-GB. Only
|
|
368
|
+
* four-digit years are accepted, so a 2-digit year can never be silently
|
|
369
|
+
* reinterpreted. A malformed tag falls back to that function's ISO order, the
|
|
370
|
+
* same floor `formatDate` uses, so reading and writing agree.
|
|
371
|
+
*
|
|
372
|
+
* Undefined is the contract rather than an exception: this runs on every
|
|
373
|
+
* keystroke of a date input.
|
|
374
|
+
*/
|
|
375
|
+
function parseDate(input, options = {}) {
|
|
376
|
+
if (typeof input !== "string") return;
|
|
377
|
+
const value = input.trim();
|
|
378
|
+
if (value === "") return;
|
|
379
|
+
const iso = parseIso(value);
|
|
380
|
+
if (iso !== void 0) return iso;
|
|
381
|
+
if (!require_civil.hasIntl()) return;
|
|
382
|
+
const order = require_pattern.dateOrder(options.locale ?? DEFAULT_LOCALE);
|
|
383
|
+
if (!/^\d/.test(value) || !/\d$/.test(value)) return;
|
|
384
|
+
const tokens = value.split(/\D+/);
|
|
385
|
+
if (tokens.length !== 3) return;
|
|
386
|
+
const fields = {};
|
|
387
|
+
for (const [index, field] of order.entries()) {
|
|
388
|
+
const token = tokens[index];
|
|
389
|
+
if (token === void 0) return;
|
|
390
|
+
if (field === "year" ? !/^\d{4}$/.test(token) : !/^\d{1,2}$/.test(token)) return;
|
|
391
|
+
fields[field] = Number(token);
|
|
392
|
+
}
|
|
393
|
+
const candidate = {
|
|
394
|
+
year: fields.year,
|
|
395
|
+
month: fields.month,
|
|
396
|
+
day: fields.day
|
|
397
|
+
};
|
|
398
|
+
return require_civil.isValidDate(candidate) ? candidate : void 0;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* ISO 8601 date, e.g. "2024-03-05".
|
|
402
|
+
*
|
|
403
|
+
* Years outside 0..9999 use the expanded form ("+010000", "-000001") so the
|
|
404
|
+
* string always round-trips through the expanded-year parser.
|
|
405
|
+
*/
|
|
406
|
+
function formatISODate(date) {
|
|
407
|
+
require_civil.assertValidDate(date);
|
|
408
|
+
return `${isoYear(date.year)}-${require_civil.pad(date.month, 2)}-${require_civil.pad(date.day, 2)}`;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* ISO 8601 date-time without a zone suffix, e.g. "2024-03-05T09:07:00.005".
|
|
412
|
+
*
|
|
413
|
+
* No "Z": a civil date-time names a wall clock, not an instant, and appending Z
|
|
414
|
+
* would be a lie about a timezone this type does not have.
|
|
415
|
+
*/
|
|
416
|
+
function formatISODateTime(value) {
|
|
417
|
+
require_civil.assertValidDateTime(value);
|
|
418
|
+
const { time } = value;
|
|
419
|
+
return `${formatISODate(value.date)}T${require_civil.pad(time.hour, 2)}:${require_civil.pad(time.minute, 2)}:${require_civil.pad(time.second, 2)}.${require_civil.pad(time.millisecond, 3)}`;
|
|
420
|
+
}
|
|
421
|
+
function isoYear(year) {
|
|
422
|
+
if (year >= 0 && year <= 9999) return require_civil.pad(year, 4);
|
|
423
|
+
return year < 0 ? `-${require_civil.pad(-year, 6)}` : `+${require_civil.pad(year, 6)}`;
|
|
424
|
+
}
|
|
425
|
+
function parseIso(value) {
|
|
426
|
+
const standard = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
427
|
+
if (standard !== null) return validOrUndefined(Number(standard[1]), Number(standard[2]), Number(standard[3]));
|
|
428
|
+
const expanded = /^([+-]\d{6})-(\d{2})-(\d{2})$/.exec(value);
|
|
429
|
+
if (expanded !== null) return validOrUndefined(Number(expanded[1]), Number(expanded[2]), Number(expanded[3]));
|
|
430
|
+
}
|
|
431
|
+
function validOrUndefined(year, month, day) {
|
|
432
|
+
const candidate = {
|
|
433
|
+
year,
|
|
434
|
+
month,
|
|
435
|
+
day
|
|
436
|
+
};
|
|
437
|
+
return require_civil.isValidDate(candidate) ? candidate : void 0;
|
|
438
|
+
}
|
|
439
|
+
function utcDate(date) {
|
|
440
|
+
return new Date(require_civil.utcMilliseconds({
|
|
441
|
+
date,
|
|
442
|
+
time: {
|
|
443
|
+
hour: 0,
|
|
444
|
+
minute: 0,
|
|
445
|
+
second: 0,
|
|
446
|
+
millisecond: 0
|
|
447
|
+
}
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
exports.MAX_RANGE_DAYS = require_timezone.MAX_RANGE_DAYS;
|
|
451
|
+
exports.addDays = require_timezone.addDays;
|
|
452
|
+
exports.addMonths = require_timezone.addMonths;
|
|
453
|
+
exports.addYears = require_timezone.addYears;
|
|
454
|
+
exports.civilInZone = require_timezone.civilInZone;
|
|
455
|
+
exports.clampRange = clampRange;
|
|
456
|
+
exports.compare = require_timezone.compare;
|
|
457
|
+
exports.dateOrder = require_pattern.dateOrder;
|
|
458
|
+
exports.datePlaceholder = require_pattern.datePlaceholder;
|
|
459
|
+
exports.dayLength = require_timezone.dayLength;
|
|
460
|
+
exports.dayOfWeek = require_civil.dayOfWeek;
|
|
461
|
+
exports.dayOfYear = require_civil.dayOfYear;
|
|
462
|
+
exports.daysInMonth = require_civil.daysInMonth;
|
|
463
|
+
exports.differenceInDays = require_timezone.differenceInDays;
|
|
464
|
+
exports.eachDay = require_timezone.eachDay;
|
|
465
|
+
exports.eachDayInRange = eachDayInRange;
|
|
466
|
+
exports.endOfMonth = require_timezone.endOfMonth;
|
|
467
|
+
exports.endOfWeek = require_timezone.endOfWeek;
|
|
468
|
+
exports.formatDate = formatDate;
|
|
469
|
+
exports.formatDateInput = require_pattern.formatDateInput;
|
|
470
|
+
exports.formatISODate = formatISODate;
|
|
471
|
+
exports.formatISODateTime = formatISODateTime;
|
|
472
|
+
exports.formatInZone = require_timezone.formatInZone;
|
|
473
|
+
exports.formatRange = formatRange;
|
|
474
|
+
exports.formatRelative = formatRelative;
|
|
475
|
+
exports.fromDate = require_civil.fromDate;
|
|
476
|
+
exports.fromEpochDay = require_civil.fromEpochDay;
|
|
477
|
+
exports.generateMonthGrid = generateMonthGrid;
|
|
478
|
+
exports.generateYear = generateYear;
|
|
479
|
+
exports.instantFor = require_timezone.instantFor;
|
|
480
|
+
exports.intersectRanges = intersectRanges;
|
|
481
|
+
exports.isLeapYear = require_civil.isLeapYear;
|
|
482
|
+
exports.isSameDay = require_timezone.isSameDay;
|
|
483
|
+
exports.isSameMonth = require_timezone.isSameMonth;
|
|
484
|
+
exports.isValidDate = require_civil.isValidDate;
|
|
485
|
+
exports.isoWeek = isoWeek;
|
|
486
|
+
exports.isoWeeksInYear = isoWeeksInYear;
|
|
487
|
+
exports.max = require_timezone.max;
|
|
488
|
+
exports.mergeRanges = mergeRanges;
|
|
489
|
+
exports.min = require_timezone.min;
|
|
490
|
+
exports.normalizeRange = normalizeRange;
|
|
491
|
+
exports.offsetAt = require_timezone.offsetAt;
|
|
492
|
+
exports.parseDate = parseDate;
|
|
493
|
+
exports.parseDateInput = require_pattern.parseDateInput;
|
|
494
|
+
exports.parseTypedDate = require_pattern.parseTypedDate;
|
|
495
|
+
exports.rangeContains = rangeContains;
|
|
496
|
+
exports.rangeLength = rangeLength;
|
|
497
|
+
exports.rangesOverlap = rangesOverlap;
|
|
498
|
+
exports.startOfDay = require_timezone.startOfDay$1;
|
|
499
|
+
exports.startOfDayInZone = require_timezone.startOfDay;
|
|
500
|
+
exports.startOfMonth = require_timezone.startOfMonth;
|
|
501
|
+
exports.startOfWeek = require_timezone.startOfWeek;
|
|
502
|
+
exports.toDate = require_civil.toDate;
|
|
503
|
+
exports.toEpochDay = require_civil.toEpochDay;
|
|
504
|
+
exports.weekdayNames = weekdayNames;
|
|
505
|
+
exports.zoneIds = require_timezone.zoneIds;
|
|
506
|
+
exports.zonedParts = require_timezone.zonedParts;
|