@cerberus-design/react 0.25.0-rc.7 → 0.25.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/combobox/combobox.cjs +1 -2
- package/dist/components/combobox/combobox.d.cts +1 -3
- package/dist/components/combobox/combobox.d.ts +1 -3
- package/dist/components/combobox/combobox.js +1 -2
- package/dist/components/cta-dialog/provider.cjs +3 -1
- package/dist/components/cta-dialog/provider.d.cts +2 -1
- package/dist/components/cta-dialog/provider.d.ts +2 -1
- package/dist/components/cta-dialog/provider.js +3 -1
- package/dist/components/date-picker/calendar.cjs +3 -1
- package/dist/components/date-picker/calendar.d.cts +4 -8
- package/dist/components/date-picker/calendar.d.ts +4 -8
- package/dist/components/date-picker/calendar.js +3 -1
- package/dist/components/date-picker/content.cjs +1 -3
- package/dist/components/date-picker/content.d.cts +1 -2
- package/dist/components/date-picker/content.d.ts +1 -2
- package/dist/components/date-picker/content.js +1 -3
- package/dist/components/date-picker/date-picker.cjs +47 -2
- package/dist/components/date-picker/date-picker.d.cts +1 -6
- package/dist/components/date-picker/date-picker.d.ts +1 -6
- package/dist/components/date-picker/date-picker.js +47 -2
- package/dist/components/date-picker/index.cjs +3 -3
- package/dist/components/date-picker/index.js +3 -3
- package/dist/components/date-picker/input.cjs +1 -1
- package/dist/components/date-picker/input.js +1 -1
- package/dist/components/date-picker/primitives.cjs +4 -1
- package/dist/components/date-picker/primitives.d.cts +1 -4
- package/dist/components/date-picker/primitives.d.ts +1 -4
- package/dist/components/date-picker/primitives.js +4 -1
- package/dist/components/date-picker/range-input.cjs +2 -2
- package/dist/components/date-picker/range-input.js +2 -2
- package/dist/components/field/status-indicator.cjs +1 -2
- package/dist/components/field/status-indicator.d.cts +1 -1
- package/dist/components/field/status-indicator.d.ts +1 -1
- package/dist/components/field/status-indicator.js +1 -2
- package/dist/components/file-upload/file-status.cjs +26 -43
- package/dist/components/file-upload/file-status.js +27 -44
- package/dist/components/file-upload/file-uploader.cjs +21 -47
- package/dist/components/file-upload/file-uploader.d.cts +7 -10
- package/dist/components/file-upload/file-uploader.d.ts +7 -10
- package/dist/components/file-upload/file-uploader.js +22 -48
- package/dist/components/file-upload/helpers.cjs +17 -0
- package/dist/components/file-upload/helpers.d.cts +16 -0
- package/dist/components/file-upload/helpers.d.ts +16 -0
- package/dist/components/file-upload/helpers.js +13 -0
- package/dist/components/file-upload/img-preview.cjs +30 -0
- package/dist/components/file-upload/img-preview.d.cts +2 -0
- package/dist/components/file-upload/img-preview.d.ts +2 -0
- package/dist/components/file-upload/img-preview.js +26 -0
- package/dist/components/file-upload/index.cjs +24 -0
- package/dist/components/file-upload/index.d.cts +4 -0
- package/dist/components/file-upload/index.d.ts +4 -0
- package/dist/components/file-upload/index.js +4 -0
- package/dist/components/file-upload/parts.cjs +28 -0
- package/dist/components/file-upload/parts.d.cts +86 -0
- package/dist/components/file-upload/parts.d.ts +86 -0
- package/dist/components/file-upload/parts.js +24 -0
- package/dist/components/file-upload/primitives.cjs +81 -0
- package/dist/components/file-upload/primitives.d.cts +45 -0
- package/dist/components/file-upload/primitives.d.ts +45 -0
- package/dist/components/file-upload/primitives.js +61 -0
- package/dist/components/file-upload/utils.cjs +18 -0
- package/dist/components/file-upload/utils.d.cts +7 -0
- package/dist/components/file-upload/utils.d.ts +7 -0
- package/dist/components/file-upload/utils.js +14 -0
- package/dist/components/select/select.cjs +6 -3
- package/dist/components/select/select.d.cts +1 -3
- package/dist/components/select/select.d.ts +1 -3
- package/dist/components/select/select.js +6 -3
- package/dist/context/confirm-modal.cjs +3 -1
- package/dist/context/confirm-modal.d.cts +2 -1
- package/dist/context/confirm-modal.d.ts +2 -1
- package/dist/context/confirm-modal.js +3 -1
- package/dist/context/prompt-modal.cjs +4 -2
- package/dist/context/prompt-modal.d.cts +2 -1
- package/dist/context/prompt-modal.d.ts +2 -1
- package/dist/context/prompt-modal.js +5 -3
- package/dist/index.cjs +163 -131
- package/dist/index.client.d.cts +1 -1
- package/dist/index.client.d.ts +1 -1
- package/dist/index.js +8 -4
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-clear-trigger.cjs +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-clear-trigger.js +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-context.cjs +10 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-context.js +6 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-dropzone.cjs +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-dropzone.js +18 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-hidden-input.cjs +21 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-hidden-input.js +17 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-delete-trigger.cjs +23 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-delete-trigger.js +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-group.cjs +23 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-group.js +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-name.cjs +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-name.js +18 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-preview-image.cjs +28 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-preview-image.js +24 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-preview.cjs +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-preview.js +18 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-size-text.cjs +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-size-text.js +18 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item.cjs +26 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item.js +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-label.cjs +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-label.js +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-root.cjs +47 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-root.js +43 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-trigger.cjs +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-trigger.js +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-context.cjs +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-context.js +10 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-item-group-props-context.cjs +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-item-group-props-context.js +10 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-item-props-context.cjs +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-item-props-context.js +10 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload.cjs +36 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload.js +32 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.0/node_modules/@internationalized/date/src/CalendarDate.js +3 -3
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.0/node_modules/@internationalized/date/src/conversion.js +1 -1
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.0/node_modules/@internationalized/date/src/queries.js +1 -1
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/CalendarDate.cjs +218 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/CalendarDate.js +212 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/DateFormatter.cjs +135 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/DateFormatter.js +131 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/calendars/GregorianCalendar.cjs +101 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/calendars/GregorianCalendar.js +93 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/conversion.cjs +200 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/conversion.js +186 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/manipulation.cjs +352 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/manipulation.js +336 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/queries.cjs +39 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/queries.js +30 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/string.cjs +44 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/string.js +37 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/utils.cjs +10 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/utils.js +6 -0
- package/dist/node_modules/.pnpm/@zag-js_file-upload@1.31.1/node_modules/@zag-js/file-upload/dist/index.cjs +649 -0
- package/dist/node_modules/.pnpm/@zag-js_file-upload@1.31.1/node_modules/@zag-js/file-upload/dist/index.js +643 -0
- package/dist/node_modules/.pnpm/@zag-js_file-utils@1.31.1/node_modules/@zag-js/file-utils/dist/index.cjs +147 -0
- package/dist/node_modules/.pnpm/@zag-js_file-utils@1.31.1/node_modules/@zag-js/file-utils/dist/index.js +138 -0
- package/dist/node_modules/.pnpm/@zag-js_i18n-utils@1.31.1/node_modules/@zag-js/i18n-utils/dist/index.cjs +53 -0
- package/dist/node_modules/.pnpm/@zag-js_i18n-utils@1.31.1/node_modules/@zag-js/i18n-utils/dist/index.js +48 -0
- package/dist/node_modules/.pnpm/@zag-js_utils@1.31.1/node_modules/@zag-js/utils/dist/index.cjs +9 -0
- package/dist/node_modules/.pnpm/@zag-js_utils@1.31.1/node_modules/@zag-js/utils/dist/index.js +9 -1
- package/package.json +7 -7
- package/src/components/combobox/combobox.tsx +7 -13
- package/src/components/cta-dialog/provider.tsx +8 -3
- package/src/components/date-picker/calendar.tsx +10 -9
- package/src/components/date-picker/content.tsx +4 -11
- package/src/components/date-picker/date-picker.tsx +55 -18
- package/src/components/date-picker/input.tsx +1 -1
- package/src/components/date-picker/primitives.tsx +4 -1
- package/src/components/date-picker/range-input.tsx +2 -2
- package/src/components/field/status-indicator.tsx +2 -5
- package/src/components/file-upload/file-status.tsx +14 -21
- package/src/components/file-upload/file-uploader.tsx +37 -49
- package/src/components/file-upload/helpers.ts +28 -0
- package/src/components/file-upload/img-preview.tsx +41 -0
- package/src/components/file-upload/index.ts +4 -0
- package/src/components/file-upload/parts.tsx +126 -0
- package/src/components/file-upload/primitives.ts +156 -0
- package/src/components/file-upload/utils.ts +20 -0
- package/src/components/select/select.tsx +11 -12
- package/src/context/confirm-modal.tsx +7 -2
- package/src/context/prompt-modal.tsx +9 -4
- package/src/index.client.ts +2 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
let formatterCache = /* @__PURE__ */ new Map();
|
|
7
|
+
class DateFormatter {
|
|
8
|
+
constructor(locale, options = {}) {
|
|
9
|
+
this.formatter = getCachedDateFormatter(locale, options);
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
/** Formats a date as a string according to the locale and format options passed to the constructor. */
|
|
13
|
+
format(value) {
|
|
14
|
+
return this.formatter.format(value);
|
|
15
|
+
}
|
|
16
|
+
/** Formats a date to an array of parts such as separators, numbers, punctuation, and more. */
|
|
17
|
+
formatToParts(value) {
|
|
18
|
+
return this.formatter.formatToParts(value);
|
|
19
|
+
}
|
|
20
|
+
/** Formats a date range as a string. */
|
|
21
|
+
formatRange(start, end) {
|
|
22
|
+
if (typeof this.formatter.formatRange === "function") {
|
|
23
|
+
return this.formatter.formatRange(start, end);
|
|
24
|
+
}
|
|
25
|
+
if (end < start) {
|
|
26
|
+
throw new RangeError("End date must be >= start date");
|
|
27
|
+
}
|
|
28
|
+
return `${this.formatter.format(start)} – ${this.formatter.format(end)}`;
|
|
29
|
+
}
|
|
30
|
+
/** Formats a date range as an array of parts. */
|
|
31
|
+
formatRangeToParts(start, end) {
|
|
32
|
+
if (typeof this.formatter.formatRangeToParts === "function") {
|
|
33
|
+
return this.formatter.formatRangeToParts(start, end);
|
|
34
|
+
}
|
|
35
|
+
if (end < start) {
|
|
36
|
+
throw new RangeError("End date must be >= start date");
|
|
37
|
+
}
|
|
38
|
+
let startParts = this.formatter.formatToParts(start);
|
|
39
|
+
let endParts = this.formatter.formatToParts(end);
|
|
40
|
+
return [
|
|
41
|
+
...startParts.map((p) => ({ ...p, source: "startRange" })),
|
|
42
|
+
{ type: "literal", value: " – ", source: "shared" },
|
|
43
|
+
...endParts.map((p) => ({ ...p, source: "endRange" }))
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
/** Returns the resolved formatting options based on the values passed to the constructor. */
|
|
47
|
+
resolvedOptions() {
|
|
48
|
+
let resolvedOptions = this.formatter.resolvedOptions();
|
|
49
|
+
if (hasBuggyResolvedHourCycle()) {
|
|
50
|
+
if (!this.resolvedHourCycle) {
|
|
51
|
+
this.resolvedHourCycle = getResolvedHourCycle(resolvedOptions.locale, this.options);
|
|
52
|
+
}
|
|
53
|
+
resolvedOptions.hourCycle = this.resolvedHourCycle;
|
|
54
|
+
resolvedOptions.hour12 = this.resolvedHourCycle === "h11" || this.resolvedHourCycle === "h12";
|
|
55
|
+
}
|
|
56
|
+
if (resolvedOptions.calendar === "ethiopic-amete-alem") {
|
|
57
|
+
resolvedOptions.calendar = "ethioaa";
|
|
58
|
+
}
|
|
59
|
+
return resolvedOptions;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const hour12Preferences = {
|
|
63
|
+
true: {
|
|
64
|
+
// Only Japanese uses the h11 style for 12 hour time. All others use h12.
|
|
65
|
+
ja: "h11"
|
|
66
|
+
},
|
|
67
|
+
false: {
|
|
68
|
+
// All locales use h23 for 24 hour time. None use h24.
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function getCachedDateFormatter(locale, options = {}) {
|
|
72
|
+
if (typeof options.hour12 === "boolean" && hasBuggyHour12Behavior()) {
|
|
73
|
+
options = { ...options };
|
|
74
|
+
let pref = hour12Preferences[String(options.hour12)][locale.split("-")[0]];
|
|
75
|
+
let defaultHourCycle = options.hour12 ? "h12" : "h23";
|
|
76
|
+
options.hourCycle = pref ?? defaultHourCycle;
|
|
77
|
+
delete options.hour12;
|
|
78
|
+
}
|
|
79
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : "");
|
|
80
|
+
if (formatterCache.has(cacheKey)) {
|
|
81
|
+
return formatterCache.get(cacheKey);
|
|
82
|
+
}
|
|
83
|
+
let numberFormatter = new Intl.DateTimeFormat(locale, options);
|
|
84
|
+
formatterCache.set(cacheKey, numberFormatter);
|
|
85
|
+
return numberFormatter;
|
|
86
|
+
}
|
|
87
|
+
let _hasBuggyHour12Behavior = null;
|
|
88
|
+
function hasBuggyHour12Behavior() {
|
|
89
|
+
if (_hasBuggyHour12Behavior == null) {
|
|
90
|
+
_hasBuggyHour12Behavior = new Intl.DateTimeFormat("en-US", {
|
|
91
|
+
hour: "numeric",
|
|
92
|
+
hour12: false
|
|
93
|
+
}).format(new Date(2020, 2, 3, 0)) === "24";
|
|
94
|
+
}
|
|
95
|
+
return _hasBuggyHour12Behavior;
|
|
96
|
+
}
|
|
97
|
+
let _hasBuggyResolvedHourCycle = null;
|
|
98
|
+
function hasBuggyResolvedHourCycle() {
|
|
99
|
+
if (_hasBuggyResolvedHourCycle == null) {
|
|
100
|
+
_hasBuggyResolvedHourCycle = new Intl.DateTimeFormat("fr", {
|
|
101
|
+
hour: "numeric",
|
|
102
|
+
hour12: false
|
|
103
|
+
}).resolvedOptions().hourCycle === "h12";
|
|
104
|
+
}
|
|
105
|
+
return _hasBuggyResolvedHourCycle;
|
|
106
|
+
}
|
|
107
|
+
function getResolvedHourCycle(locale, options) {
|
|
108
|
+
if (!options.timeStyle && !options.hour) {
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
locale = locale.replace(/(-u-)?-nu-[a-zA-Z0-9]+/, "");
|
|
112
|
+
locale += (locale.includes("-u-") ? "" : "-u") + "-nu-latn";
|
|
113
|
+
let formatter = getCachedDateFormatter(locale, {
|
|
114
|
+
...options,
|
|
115
|
+
timeZone: void 0
|
|
116
|
+
// use local timezone
|
|
117
|
+
});
|
|
118
|
+
let min = parseInt(formatter.formatToParts(new Date(2020, 2, 3, 0)).find((p) => p.type === "hour").value, 10);
|
|
119
|
+
let max = parseInt(formatter.formatToParts(new Date(2020, 2, 3, 23)).find((p) => p.type === "hour").value, 10);
|
|
120
|
+
if (min === 0 && max === 23) {
|
|
121
|
+
return "h23";
|
|
122
|
+
}
|
|
123
|
+
if (min === 24 && max === 23) {
|
|
124
|
+
return "h24";
|
|
125
|
+
}
|
|
126
|
+
if (min === 0 && max === 11) {
|
|
127
|
+
return "h11";
|
|
128
|
+
}
|
|
129
|
+
if (min === 12 && max === 11) {
|
|
130
|
+
return "h12";
|
|
131
|
+
}
|
|
132
|
+
throw new Error("Unexpected hour cycle result");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.DateFormatter = DateFormatter;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
let formatterCache = /* @__PURE__ */ new Map();
|
|
3
|
+
class DateFormatter {
|
|
4
|
+
constructor(locale, options = {}) {
|
|
5
|
+
this.formatter = getCachedDateFormatter(locale, options);
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
/** Formats a date as a string according to the locale and format options passed to the constructor. */
|
|
9
|
+
format(value) {
|
|
10
|
+
return this.formatter.format(value);
|
|
11
|
+
}
|
|
12
|
+
/** Formats a date to an array of parts such as separators, numbers, punctuation, and more. */
|
|
13
|
+
formatToParts(value) {
|
|
14
|
+
return this.formatter.formatToParts(value);
|
|
15
|
+
}
|
|
16
|
+
/** Formats a date range as a string. */
|
|
17
|
+
formatRange(start, end) {
|
|
18
|
+
if (typeof this.formatter.formatRange === "function") {
|
|
19
|
+
return this.formatter.formatRange(start, end);
|
|
20
|
+
}
|
|
21
|
+
if (end < start) {
|
|
22
|
+
throw new RangeError("End date must be >= start date");
|
|
23
|
+
}
|
|
24
|
+
return `${this.formatter.format(start)} – ${this.formatter.format(end)}`;
|
|
25
|
+
}
|
|
26
|
+
/** Formats a date range as an array of parts. */
|
|
27
|
+
formatRangeToParts(start, end) {
|
|
28
|
+
if (typeof this.formatter.formatRangeToParts === "function") {
|
|
29
|
+
return this.formatter.formatRangeToParts(start, end);
|
|
30
|
+
}
|
|
31
|
+
if (end < start) {
|
|
32
|
+
throw new RangeError("End date must be >= start date");
|
|
33
|
+
}
|
|
34
|
+
let startParts = this.formatter.formatToParts(start);
|
|
35
|
+
let endParts = this.formatter.formatToParts(end);
|
|
36
|
+
return [
|
|
37
|
+
...startParts.map((p) => ({ ...p, source: "startRange" })),
|
|
38
|
+
{ type: "literal", value: " – ", source: "shared" },
|
|
39
|
+
...endParts.map((p) => ({ ...p, source: "endRange" }))
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
/** Returns the resolved formatting options based on the values passed to the constructor. */
|
|
43
|
+
resolvedOptions() {
|
|
44
|
+
let resolvedOptions = this.formatter.resolvedOptions();
|
|
45
|
+
if (hasBuggyResolvedHourCycle()) {
|
|
46
|
+
if (!this.resolvedHourCycle) {
|
|
47
|
+
this.resolvedHourCycle = getResolvedHourCycle(resolvedOptions.locale, this.options);
|
|
48
|
+
}
|
|
49
|
+
resolvedOptions.hourCycle = this.resolvedHourCycle;
|
|
50
|
+
resolvedOptions.hour12 = this.resolvedHourCycle === "h11" || this.resolvedHourCycle === "h12";
|
|
51
|
+
}
|
|
52
|
+
if (resolvedOptions.calendar === "ethiopic-amete-alem") {
|
|
53
|
+
resolvedOptions.calendar = "ethioaa";
|
|
54
|
+
}
|
|
55
|
+
return resolvedOptions;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const hour12Preferences = {
|
|
59
|
+
true: {
|
|
60
|
+
// Only Japanese uses the h11 style for 12 hour time. All others use h12.
|
|
61
|
+
ja: "h11"
|
|
62
|
+
},
|
|
63
|
+
false: {
|
|
64
|
+
// All locales use h23 for 24 hour time. None use h24.
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
function getCachedDateFormatter(locale, options = {}) {
|
|
68
|
+
if (typeof options.hour12 === "boolean" && hasBuggyHour12Behavior()) {
|
|
69
|
+
options = { ...options };
|
|
70
|
+
let pref = hour12Preferences[String(options.hour12)][locale.split("-")[0]];
|
|
71
|
+
let defaultHourCycle = options.hour12 ? "h12" : "h23";
|
|
72
|
+
options.hourCycle = pref ?? defaultHourCycle;
|
|
73
|
+
delete options.hour12;
|
|
74
|
+
}
|
|
75
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : "");
|
|
76
|
+
if (formatterCache.has(cacheKey)) {
|
|
77
|
+
return formatterCache.get(cacheKey);
|
|
78
|
+
}
|
|
79
|
+
let numberFormatter = new Intl.DateTimeFormat(locale, options);
|
|
80
|
+
formatterCache.set(cacheKey, numberFormatter);
|
|
81
|
+
return numberFormatter;
|
|
82
|
+
}
|
|
83
|
+
let _hasBuggyHour12Behavior = null;
|
|
84
|
+
function hasBuggyHour12Behavior() {
|
|
85
|
+
if (_hasBuggyHour12Behavior == null) {
|
|
86
|
+
_hasBuggyHour12Behavior = new Intl.DateTimeFormat("en-US", {
|
|
87
|
+
hour: "numeric",
|
|
88
|
+
hour12: false
|
|
89
|
+
}).format(new Date(2020, 2, 3, 0)) === "24";
|
|
90
|
+
}
|
|
91
|
+
return _hasBuggyHour12Behavior;
|
|
92
|
+
}
|
|
93
|
+
let _hasBuggyResolvedHourCycle = null;
|
|
94
|
+
function hasBuggyResolvedHourCycle() {
|
|
95
|
+
if (_hasBuggyResolvedHourCycle == null) {
|
|
96
|
+
_hasBuggyResolvedHourCycle = new Intl.DateTimeFormat("fr", {
|
|
97
|
+
hour: "numeric",
|
|
98
|
+
hour12: false
|
|
99
|
+
}).resolvedOptions().hourCycle === "h12";
|
|
100
|
+
}
|
|
101
|
+
return _hasBuggyResolvedHourCycle;
|
|
102
|
+
}
|
|
103
|
+
function getResolvedHourCycle(locale, options) {
|
|
104
|
+
if (!options.timeStyle && !options.hour) {
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
locale = locale.replace(/(-u-)?-nu-[a-zA-Z0-9]+/, "");
|
|
108
|
+
locale += (locale.includes("-u-") ? "" : "-u") + "-nu-latn";
|
|
109
|
+
let formatter = getCachedDateFormatter(locale, {
|
|
110
|
+
...options,
|
|
111
|
+
timeZone: void 0
|
|
112
|
+
// use local timezone
|
|
113
|
+
});
|
|
114
|
+
let min = parseInt(formatter.formatToParts(new Date(2020, 2, 3, 0)).find((p) => p.type === "hour").value, 10);
|
|
115
|
+
let max = parseInt(formatter.formatToParts(new Date(2020, 2, 3, 23)).find((p) => p.type === "hour").value, 10);
|
|
116
|
+
if (min === 0 && max === 23) {
|
|
117
|
+
return "h23";
|
|
118
|
+
}
|
|
119
|
+
if (min === 24 && max === 23) {
|
|
120
|
+
return "h24";
|
|
121
|
+
}
|
|
122
|
+
if (min === 0 && max === 11) {
|
|
123
|
+
return "h11";
|
|
124
|
+
}
|
|
125
|
+
if (min === 12 && max === 11) {
|
|
126
|
+
return "h12";
|
|
127
|
+
}
|
|
128
|
+
throw new Error("Unexpected hour cycle result");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { DateFormatter };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const CalendarDate = require('../CalendarDate.cjs');
|
|
7
|
+
const utils = require('../utils.cjs');
|
|
8
|
+
|
|
9
|
+
const EPOCH = 1721426;
|
|
10
|
+
function gregorianToJulianDay(era, year, month, day) {
|
|
11
|
+
year = getExtendedYear(era, year);
|
|
12
|
+
let y1 = year - 1;
|
|
13
|
+
let monthOffset = -2;
|
|
14
|
+
if (month <= 2) {
|
|
15
|
+
monthOffset = 0;
|
|
16
|
+
} else if (isLeapYear(year)) {
|
|
17
|
+
monthOffset = -1;
|
|
18
|
+
}
|
|
19
|
+
return EPOCH - 1 + 365 * y1 + Math.floor(y1 / 4) - Math.floor(y1 / 100) + Math.floor(y1 / 400) + Math.floor((367 * month - 362) / 12 + monthOffset + day);
|
|
20
|
+
}
|
|
21
|
+
function isLeapYear(year) {
|
|
22
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
23
|
+
}
|
|
24
|
+
function getExtendedYear(era, year) {
|
|
25
|
+
return era === "BC" ? 1 - year : year;
|
|
26
|
+
}
|
|
27
|
+
function fromExtendedYear(year) {
|
|
28
|
+
let era = "AD";
|
|
29
|
+
if (year <= 0) {
|
|
30
|
+
era = "BC";
|
|
31
|
+
year = 1 - year;
|
|
32
|
+
}
|
|
33
|
+
return [era, year];
|
|
34
|
+
}
|
|
35
|
+
const daysInMonth = {
|
|
36
|
+
standard: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
|
|
37
|
+
leapyear: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
38
|
+
};
|
|
39
|
+
class GregorianCalendar {
|
|
40
|
+
constructor() {
|
|
41
|
+
this.identifier = "gregory";
|
|
42
|
+
}
|
|
43
|
+
fromJulianDay(jd) {
|
|
44
|
+
let jd0 = jd;
|
|
45
|
+
let depoch = jd0 - EPOCH;
|
|
46
|
+
let quadricent = Math.floor(depoch / 146097);
|
|
47
|
+
let dqc = utils.mod(depoch, 146097);
|
|
48
|
+
let cent = Math.floor(dqc / 36524);
|
|
49
|
+
let dcent = utils.mod(dqc, 36524);
|
|
50
|
+
let quad = Math.floor(dcent / 1461);
|
|
51
|
+
let dquad = utils.mod(dcent, 1461);
|
|
52
|
+
let yindex = Math.floor(dquad / 365);
|
|
53
|
+
let extendedYear = quadricent * 400 + cent * 100 + quad * 4 + yindex + (cent !== 4 && yindex !== 4 ? 1 : 0);
|
|
54
|
+
let [era, year] = fromExtendedYear(extendedYear);
|
|
55
|
+
let yearDay = jd0 - gregorianToJulianDay(era, year, 1, 1);
|
|
56
|
+
let leapAdj = 2;
|
|
57
|
+
if (jd0 < gregorianToJulianDay(era, year, 3, 1)) {
|
|
58
|
+
leapAdj = 0;
|
|
59
|
+
} else if (isLeapYear(year)) {
|
|
60
|
+
leapAdj = 1;
|
|
61
|
+
}
|
|
62
|
+
let month = Math.floor(((yearDay + leapAdj) * 12 + 373) / 367);
|
|
63
|
+
let day = jd0 - gregorianToJulianDay(era, year, month, 1) + 1;
|
|
64
|
+
return new CalendarDate.CalendarDate(era, year, month, day);
|
|
65
|
+
}
|
|
66
|
+
toJulianDay(date) {
|
|
67
|
+
return gregorianToJulianDay(date.era, date.year, date.month, date.day);
|
|
68
|
+
}
|
|
69
|
+
getDaysInMonth(date) {
|
|
70
|
+
return daysInMonth[isLeapYear(date.year) ? "leapyear" : "standard"][date.month - 1];
|
|
71
|
+
}
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
73
|
+
getMonthsInYear(date) {
|
|
74
|
+
return 12;
|
|
75
|
+
}
|
|
76
|
+
getDaysInYear(date) {
|
|
77
|
+
return isLeapYear(date.year) ? 366 : 365;
|
|
78
|
+
}
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
+
getYearsInEra(date) {
|
|
81
|
+
return 9999;
|
|
82
|
+
}
|
|
83
|
+
getEras() {
|
|
84
|
+
return ["BC", "AD"];
|
|
85
|
+
}
|
|
86
|
+
isInverseEra(date) {
|
|
87
|
+
return date.era === "BC";
|
|
88
|
+
}
|
|
89
|
+
balanceDate(date) {
|
|
90
|
+
if (date.year <= 0) {
|
|
91
|
+
date.era = date.era === "BC" ? "AD" : "BC";
|
|
92
|
+
date.year = 1 - date.year;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
exports.GregorianCalendar = GregorianCalendar;
|
|
98
|
+
exports.fromExtendedYear = fromExtendedYear;
|
|
99
|
+
exports.getExtendedYear = getExtendedYear;
|
|
100
|
+
exports.gregorianToJulianDay = gregorianToJulianDay;
|
|
101
|
+
exports.isLeapYear = isLeapYear;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { CalendarDate } from '../CalendarDate.js';
|
|
3
|
+
import { mod } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
const EPOCH = 1721426;
|
|
6
|
+
function gregorianToJulianDay(era, year, month, day) {
|
|
7
|
+
year = getExtendedYear(era, year);
|
|
8
|
+
let y1 = year - 1;
|
|
9
|
+
let monthOffset = -2;
|
|
10
|
+
if (month <= 2) {
|
|
11
|
+
monthOffset = 0;
|
|
12
|
+
} else if (isLeapYear(year)) {
|
|
13
|
+
monthOffset = -1;
|
|
14
|
+
}
|
|
15
|
+
return EPOCH - 1 + 365 * y1 + Math.floor(y1 / 4) - Math.floor(y1 / 100) + Math.floor(y1 / 400) + Math.floor((367 * month - 362) / 12 + monthOffset + day);
|
|
16
|
+
}
|
|
17
|
+
function isLeapYear(year) {
|
|
18
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
19
|
+
}
|
|
20
|
+
function getExtendedYear(era, year) {
|
|
21
|
+
return era === "BC" ? 1 - year : year;
|
|
22
|
+
}
|
|
23
|
+
function fromExtendedYear(year) {
|
|
24
|
+
let era = "AD";
|
|
25
|
+
if (year <= 0) {
|
|
26
|
+
era = "BC";
|
|
27
|
+
year = 1 - year;
|
|
28
|
+
}
|
|
29
|
+
return [era, year];
|
|
30
|
+
}
|
|
31
|
+
const daysInMonth = {
|
|
32
|
+
standard: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
|
|
33
|
+
leapyear: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
34
|
+
};
|
|
35
|
+
class GregorianCalendar {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.identifier = "gregory";
|
|
38
|
+
}
|
|
39
|
+
fromJulianDay(jd) {
|
|
40
|
+
let jd0 = jd;
|
|
41
|
+
let depoch = jd0 - EPOCH;
|
|
42
|
+
let quadricent = Math.floor(depoch / 146097);
|
|
43
|
+
let dqc = mod(depoch, 146097);
|
|
44
|
+
let cent = Math.floor(dqc / 36524);
|
|
45
|
+
let dcent = mod(dqc, 36524);
|
|
46
|
+
let quad = Math.floor(dcent / 1461);
|
|
47
|
+
let dquad = mod(dcent, 1461);
|
|
48
|
+
let yindex = Math.floor(dquad / 365);
|
|
49
|
+
let extendedYear = quadricent * 400 + cent * 100 + quad * 4 + yindex + (cent !== 4 && yindex !== 4 ? 1 : 0);
|
|
50
|
+
let [era, year] = fromExtendedYear(extendedYear);
|
|
51
|
+
let yearDay = jd0 - gregorianToJulianDay(era, year, 1, 1);
|
|
52
|
+
let leapAdj = 2;
|
|
53
|
+
if (jd0 < gregorianToJulianDay(era, year, 3, 1)) {
|
|
54
|
+
leapAdj = 0;
|
|
55
|
+
} else if (isLeapYear(year)) {
|
|
56
|
+
leapAdj = 1;
|
|
57
|
+
}
|
|
58
|
+
let month = Math.floor(((yearDay + leapAdj) * 12 + 373) / 367);
|
|
59
|
+
let day = jd0 - gregorianToJulianDay(era, year, month, 1) + 1;
|
|
60
|
+
return new CalendarDate(era, year, month, day);
|
|
61
|
+
}
|
|
62
|
+
toJulianDay(date) {
|
|
63
|
+
return gregorianToJulianDay(date.era, date.year, date.month, date.day);
|
|
64
|
+
}
|
|
65
|
+
getDaysInMonth(date) {
|
|
66
|
+
return daysInMonth[isLeapYear(date.year) ? "leapyear" : "standard"][date.month - 1];
|
|
67
|
+
}
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69
|
+
getMonthsInYear(date) {
|
|
70
|
+
return 12;
|
|
71
|
+
}
|
|
72
|
+
getDaysInYear(date) {
|
|
73
|
+
return isLeapYear(date.year) ? 366 : 365;
|
|
74
|
+
}
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
76
|
+
getYearsInEra(date) {
|
|
77
|
+
return 9999;
|
|
78
|
+
}
|
|
79
|
+
getEras() {
|
|
80
|
+
return ["BC", "AD"];
|
|
81
|
+
}
|
|
82
|
+
isInverseEra(date) {
|
|
83
|
+
return date.era === "BC";
|
|
84
|
+
}
|
|
85
|
+
balanceDate(date) {
|
|
86
|
+
if (date.year <= 0) {
|
|
87
|
+
date.era = date.era === "BC" ? "AD" : "BC";
|
|
88
|
+
date.year = 1 - date.year;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { GregorianCalendar, fromExtendedYear, getExtendedYear, gregorianToJulianDay, isLeapYear };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const CalendarDate = require('./CalendarDate.cjs');
|
|
7
|
+
const manipulation = require('./manipulation.cjs');
|
|
8
|
+
const GregorianCalendar = require('./calendars/GregorianCalendar.cjs');
|
|
9
|
+
const queries = require('./queries.cjs');
|
|
10
|
+
|
|
11
|
+
function epochFromDate(date) {
|
|
12
|
+
date = toCalendar(date, new GregorianCalendar.GregorianCalendar());
|
|
13
|
+
let year = GregorianCalendar.getExtendedYear(date.era, date.year);
|
|
14
|
+
return epochFromParts(year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond);
|
|
15
|
+
}
|
|
16
|
+
function epochFromParts(year, month, day, hour, minute, second, millisecond) {
|
|
17
|
+
let date = /* @__PURE__ */ new Date();
|
|
18
|
+
date.setUTCHours(hour, minute, second, millisecond);
|
|
19
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
20
|
+
return date.getTime();
|
|
21
|
+
}
|
|
22
|
+
function getTimeZoneOffset(ms, timeZone) {
|
|
23
|
+
if (timeZone === "UTC") {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
if (ms > 0 && timeZone === queries.getLocalTimeZone()) {
|
|
27
|
+
return new Date(ms).getTimezoneOffset() * -60 * 1e3;
|
|
28
|
+
}
|
|
29
|
+
let { year, month, day, hour, minute, second } = getTimeZoneParts(ms, timeZone);
|
|
30
|
+
let utc = epochFromParts(year, month, day, hour, minute, second, 0);
|
|
31
|
+
return utc - Math.floor(ms / 1e3) * 1e3;
|
|
32
|
+
}
|
|
33
|
+
const formattersByTimeZone = /* @__PURE__ */ new Map();
|
|
34
|
+
function getTimeZoneParts(ms, timeZone) {
|
|
35
|
+
let formatter = formattersByTimeZone.get(timeZone);
|
|
36
|
+
if (!formatter) {
|
|
37
|
+
formatter = new Intl.DateTimeFormat("en-US", {
|
|
38
|
+
timeZone,
|
|
39
|
+
hour12: false,
|
|
40
|
+
era: "short",
|
|
41
|
+
year: "numeric",
|
|
42
|
+
month: "numeric",
|
|
43
|
+
day: "numeric",
|
|
44
|
+
hour: "numeric",
|
|
45
|
+
minute: "numeric",
|
|
46
|
+
second: "numeric"
|
|
47
|
+
});
|
|
48
|
+
formattersByTimeZone.set(timeZone, formatter);
|
|
49
|
+
}
|
|
50
|
+
let parts = formatter.formatToParts(new Date(ms));
|
|
51
|
+
let namedParts = {};
|
|
52
|
+
for (let part of parts) {
|
|
53
|
+
if (part.type !== "literal") {
|
|
54
|
+
namedParts[part.type] = part.value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
// Firefox returns B instead of BC... https://bugzilla.mozilla.org/show_bug.cgi?id=1752253
|
|
59
|
+
year: namedParts.era === "BC" || namedParts.era === "B" ? -namedParts.year + 1 : +namedParts.year,
|
|
60
|
+
month: +namedParts.month,
|
|
61
|
+
day: +namedParts.day,
|
|
62
|
+
hour: namedParts.hour === "24" ? 0 : +namedParts.hour,
|
|
63
|
+
// bugs.chromium.org/p/chromium/issues/detail?id=1045791
|
|
64
|
+
minute: +namedParts.minute,
|
|
65
|
+
second: +namedParts.second
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const DAYMILLIS = 864e5;
|
|
69
|
+
function getValidWallTimes(date, timeZone, earlier, later) {
|
|
70
|
+
let found = earlier === later ? [earlier] : [earlier, later];
|
|
71
|
+
return found.filter((absolute) => isValidWallTime(date, timeZone, absolute));
|
|
72
|
+
}
|
|
73
|
+
function isValidWallTime(date, timeZone, absolute) {
|
|
74
|
+
let parts = getTimeZoneParts(absolute, timeZone);
|
|
75
|
+
return date.year === parts.year && date.month === parts.month && date.day === parts.day && date.hour === parts.hour && date.minute === parts.minute && date.second === parts.second;
|
|
76
|
+
}
|
|
77
|
+
function toAbsolute(date, timeZone, disambiguation = "compatible") {
|
|
78
|
+
let dateTime = toCalendarDateTime(date);
|
|
79
|
+
if (timeZone === "UTC") {
|
|
80
|
+
return epochFromDate(dateTime);
|
|
81
|
+
}
|
|
82
|
+
if (timeZone === queries.getLocalTimeZone() && disambiguation === "compatible") {
|
|
83
|
+
dateTime = toCalendar(dateTime, new GregorianCalendar.GregorianCalendar());
|
|
84
|
+
let date2 = /* @__PURE__ */ new Date();
|
|
85
|
+
let year = GregorianCalendar.getExtendedYear(dateTime.era, dateTime.year);
|
|
86
|
+
date2.setFullYear(year, dateTime.month - 1, dateTime.day);
|
|
87
|
+
date2.setHours(dateTime.hour, dateTime.minute, dateTime.second, dateTime.millisecond);
|
|
88
|
+
return date2.getTime();
|
|
89
|
+
}
|
|
90
|
+
let ms = epochFromDate(dateTime);
|
|
91
|
+
let offsetBefore = getTimeZoneOffset(ms - DAYMILLIS, timeZone);
|
|
92
|
+
let offsetAfter = getTimeZoneOffset(ms + DAYMILLIS, timeZone);
|
|
93
|
+
let valid = getValidWallTimes(dateTime, timeZone, ms - offsetBefore, ms - offsetAfter);
|
|
94
|
+
if (valid.length === 1) {
|
|
95
|
+
return valid[0];
|
|
96
|
+
}
|
|
97
|
+
if (valid.length > 1) {
|
|
98
|
+
switch (disambiguation) {
|
|
99
|
+
// 'compatible' means 'earlier' for "fall back" transitions
|
|
100
|
+
case "compatible":
|
|
101
|
+
case "earlier":
|
|
102
|
+
return valid[0];
|
|
103
|
+
case "later":
|
|
104
|
+
return valid[valid.length - 1];
|
|
105
|
+
case "reject":
|
|
106
|
+
throw new RangeError("Multiple possible absolute times found");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
switch (disambiguation) {
|
|
110
|
+
case "earlier":
|
|
111
|
+
return Math.min(ms - offsetBefore, ms - offsetAfter);
|
|
112
|
+
// 'compatible' means 'later' for "spring forward" transitions
|
|
113
|
+
case "compatible":
|
|
114
|
+
case "later":
|
|
115
|
+
return Math.max(ms - offsetBefore, ms - offsetAfter);
|
|
116
|
+
case "reject":
|
|
117
|
+
throw new RangeError("No such absolute time found");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function toDate(dateTime, timeZone, disambiguation = "compatible") {
|
|
121
|
+
return new Date(toAbsolute(dateTime, timeZone, disambiguation));
|
|
122
|
+
}
|
|
123
|
+
function fromAbsolute(ms, timeZone) {
|
|
124
|
+
let offset = getTimeZoneOffset(ms, timeZone);
|
|
125
|
+
let date = new Date(ms + offset);
|
|
126
|
+
let year = date.getUTCFullYear();
|
|
127
|
+
let month = date.getUTCMonth() + 1;
|
|
128
|
+
let day = date.getUTCDate();
|
|
129
|
+
let hour = date.getUTCHours();
|
|
130
|
+
let minute = date.getUTCMinutes();
|
|
131
|
+
let second = date.getUTCSeconds();
|
|
132
|
+
let millisecond = date.getUTCMilliseconds();
|
|
133
|
+
return new CalendarDate.ZonedDateTime(year < 1 ? "BC" : "AD", year < 1 ? -year + 1 : year, month, day, timeZone, offset, hour, minute, second, millisecond);
|
|
134
|
+
}
|
|
135
|
+
function toCalendarDate(dateTime) {
|
|
136
|
+
return new CalendarDate.CalendarDate(dateTime.calendar, dateTime.era, dateTime.year, dateTime.month, dateTime.day);
|
|
137
|
+
}
|
|
138
|
+
function toCalendarDateTime(date, time) {
|
|
139
|
+
let hour = 0, minute = 0, second = 0, millisecond = 0;
|
|
140
|
+
if ("timeZone" in date) {
|
|
141
|
+
({ hour, minute, second, millisecond } = date);
|
|
142
|
+
} else if ("hour" in date && true) {
|
|
143
|
+
return date;
|
|
144
|
+
}
|
|
145
|
+
return new CalendarDate.CalendarDateTime(
|
|
146
|
+
date.calendar,
|
|
147
|
+
date.era,
|
|
148
|
+
date.year,
|
|
149
|
+
date.month,
|
|
150
|
+
date.day,
|
|
151
|
+
hour,
|
|
152
|
+
minute,
|
|
153
|
+
second,
|
|
154
|
+
millisecond
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function toCalendar(date, calendar) {
|
|
158
|
+
if (queries.isEqualCalendar(date.calendar, calendar)) {
|
|
159
|
+
return date;
|
|
160
|
+
}
|
|
161
|
+
let calendarDate = calendar.fromJulianDay(date.calendar.toJulianDay(date));
|
|
162
|
+
let copy = date.copy();
|
|
163
|
+
copy.calendar = calendar;
|
|
164
|
+
copy.era = calendarDate.era;
|
|
165
|
+
copy.year = calendarDate.year;
|
|
166
|
+
copy.month = calendarDate.month;
|
|
167
|
+
copy.day = calendarDate.day;
|
|
168
|
+
manipulation.constrain(copy);
|
|
169
|
+
return copy;
|
|
170
|
+
}
|
|
171
|
+
function toZoned(date, timeZone, disambiguation) {
|
|
172
|
+
if (date instanceof CalendarDate.ZonedDateTime) {
|
|
173
|
+
if (date.timeZone === timeZone) {
|
|
174
|
+
return date;
|
|
175
|
+
}
|
|
176
|
+
return toTimeZone(date, timeZone);
|
|
177
|
+
}
|
|
178
|
+
let ms = toAbsolute(date, timeZone, disambiguation);
|
|
179
|
+
return fromAbsolute(ms, timeZone);
|
|
180
|
+
}
|
|
181
|
+
function zonedToDate(date) {
|
|
182
|
+
let ms = epochFromDate(date) - date.offset;
|
|
183
|
+
return new Date(ms);
|
|
184
|
+
}
|
|
185
|
+
function toTimeZone(date, timeZone) {
|
|
186
|
+
let ms = epochFromDate(date) - date.offset;
|
|
187
|
+
return toCalendar(fromAbsolute(ms, timeZone), date.calendar);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
exports.epochFromDate = epochFromDate;
|
|
191
|
+
exports.fromAbsolute = fromAbsolute;
|
|
192
|
+
exports.getTimeZoneOffset = getTimeZoneOffset;
|
|
193
|
+
exports.toAbsolute = toAbsolute;
|
|
194
|
+
exports.toCalendar = toCalendar;
|
|
195
|
+
exports.toCalendarDate = toCalendarDate;
|
|
196
|
+
exports.toCalendarDateTime = toCalendarDateTime;
|
|
197
|
+
exports.toDate = toDate;
|
|
198
|
+
exports.toTimeZone = toTimeZone;
|
|
199
|
+
exports.toZoned = toZoned;
|
|
200
|
+
exports.zonedToDate = zonedToDate;
|