@formatjs/intl-datetimeformat 7.1.0 → 7.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/add-all-tz.js +319 -318
  2. package/add-golden-tz.js +1 -1
  3. package/index.d.ts +1 -1
  4. package/index.js +1 -1
  5. package/package.json +5 -5
  6. package/polyfill-force.js +28 -44
  7. package/polyfill.iife.js +2803 -3046
  8. package/polyfill.js +29 -45
  9. package/should-polyfill.js +38 -50
  10. package/src/abstract/BasicFormatMatcher.d.ts +5 -5
  11. package/src/abstract/BasicFormatMatcher.js +87 -103
  12. package/src/abstract/BestFitFormatMatcher.d.ts +12 -12
  13. package/src/abstract/BestFitFormatMatcher.js +102 -108
  14. package/src/abstract/DateTimeStyleFormat.d.ts +2 -2
  15. package/src/abstract/DateTimeStyleFormat.js +47 -62
  16. package/src/abstract/FormatDateTime.d.ts +7 -7
  17. package/src/abstract/FormatDateTime.js +12 -12
  18. package/src/abstract/FormatDateTimePattern.d.ts +11 -11
  19. package/src/abstract/FormatDateTimePattern.js +185 -198
  20. package/src/abstract/FormatDateTimeRange.d.ts +3 -3
  21. package/src/abstract/FormatDateTimeRange.js +9 -8
  22. package/src/abstract/FormatDateTimeRangeToParts.d.ts +4 -4
  23. package/src/abstract/FormatDateTimeRangeToParts.js +14 -12
  24. package/src/abstract/FormatDateTimeToParts.d.ts +9 -9
  25. package/src/abstract/FormatDateTimeToParts.js +17 -18
  26. package/src/abstract/InitializeDateTimeFormat.d.ts +15 -15
  27. package/src/abstract/InitializeDateTimeFormat.js +206 -184
  28. package/src/abstract/PartitionDateTimePattern.d.ts +8 -8
  29. package/src/abstract/PartitionDateTimePattern.js +15 -14
  30. package/src/abstract/PartitionDateTimeRangePattern.d.ts +4 -4
  31. package/src/abstract/PartitionDateTimeRangePattern.js +168 -161
  32. package/src/abstract/ToDateTimeOptions.d.ts +5 -5
  33. package/src/abstract/ToDateTimeOptions.js +68 -60
  34. package/src/abstract/ToLocalTime.d.ts +21 -21
  35. package/src/abstract/ToLocalTime.js +116 -45
  36. package/src/abstract/skeleton.d.ts +8 -8
  37. package/src/abstract/skeleton.js +231 -280
  38. package/src/abstract/utils.d.ts +1 -1
  39. package/src/abstract/utils.js +21 -20
  40. package/src/core.d.ts +17 -17
  41. package/src/core.js +250 -286
  42. package/src/data/all-tz.generated.d.ts +8 -0
  43. package/src/data/all-tz.generated.js +462 -0
  44. package/src/data/links.generated.d.ts +261 -0
  45. package/src/data/links.generated.js +260 -0
  46. package/src/get_internal_slots.d.ts +3 -1
  47. package/src/get_internal_slots.js +8 -7
  48. package/src/packer.d.ts +2 -2
  49. package/src/packer.js +23 -35
  50. package/src/to_locale_string.d.ts +3 -3
  51. package/src/to_locale_string.js +11 -11
  52. package/src/types.d.ts +34 -39
  53. package/src/types.js +1 -1
  54. package/supported-locales.generated.js +573 -1
  55. package/test262-main.d.ts +4 -1
  56. package/test262-main.js +24600 -44193
  57. package/src/data/all-tz.d.ts +0 -6
  58. package/src/data/all-tz.js +0 -461
  59. package/src/data/links.d.ts +0 -259
  60. package/src/data/links.js +0 -260
@@ -1,14 +1,16 @@
1
- import { PartitionDateTimeRangePattern } from './PartitionDateTimeRangePattern.js';
1
+ import "@formatjs/ecma402-abstract";
2
+ import "./FormatDateTimePattern.js";
3
+ import { PartitionDateTimeRangePattern } from "./PartitionDateTimeRangePattern.js";
4
+ import "./ToLocalTime.js";
2
5
  export function FormatDateTimeRangeToParts(dtf, x, y, implDetails) {
3
- var parts = PartitionDateTimeRangePattern(dtf, x, y, implDetails);
4
- var result = [];
5
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
6
- var part = parts_1[_i];
7
- result.push({
8
- type: part.type,
9
- value: part.value,
10
- source: part.source,
11
- });
12
- }
13
- return result;
6
+ const parts = PartitionDateTimeRangePattern(dtf, x, y, implDetails);
7
+ const result = [];
8
+ for (const part of parts) {
9
+ result.push({
10
+ type: part.type,
11
+ value: part.value,
12
+ source: part.source
13
+ });
14
+ }
15
+ return result;
14
16
  }
@@ -1,11 +1,11 @@
1
- import { IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
2
- import Decimal from 'decimal.js';
3
- import { PartitionDateTimePattern } from './PartitionDateTimePattern.js';
1
+ import { type IntlDateTimeFormatPart } from "@formatjs/ecma402-abstract";
2
+ import type Decimal from "decimal.js";
3
+ import { PartitionDateTimePattern } from "./PartitionDateTimePattern.js";
4
4
  /**
5
- * https://tc39.es/ecma402/#sec-formatdatetimetoparts
6
- *
7
- * @param dtf
8
- * @param x
9
- * @param implDetails
10
- */
5
+ * https://tc39.es/ecma402/#sec-formatdatetimetoparts
6
+ *
7
+ * @param dtf
8
+ * @param x
9
+ * @param implDetails
10
+ */
11
11
  export declare function FormatDateTimeToParts(dtf: Intl.DateTimeFormat, x: Decimal, implDetails: Parameters<typeof PartitionDateTimePattern>[2]): IntlDateTimeFormatPart[];
@@ -1,21 +1,20 @@
1
- import { ArrayCreate } from '@formatjs/ecma402-abstract';
2
- import { PartitionDateTimePattern } from './PartitionDateTimePattern.js';
1
+ import { ArrayCreate } from "@formatjs/ecma402-abstract";
2
+ import { PartitionDateTimePattern } from "./PartitionDateTimePattern.js";
3
3
  /**
4
- * https://tc39.es/ecma402/#sec-formatdatetimetoparts
5
- *
6
- * @param dtf
7
- * @param x
8
- * @param implDetails
9
- */
4
+ * https://tc39.es/ecma402/#sec-formatdatetimetoparts
5
+ *
6
+ * @param dtf
7
+ * @param x
8
+ * @param implDetails
9
+ */
10
10
  export function FormatDateTimeToParts(dtf, x, implDetails) {
11
- var parts = PartitionDateTimePattern(dtf, x, implDetails);
12
- var result = ArrayCreate(0);
13
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
14
- var part = parts_1[_i];
15
- result.push({
16
- type: part.type,
17
- value: part.value,
18
- });
19
- }
20
- return result;
11
+ const parts = PartitionDateTimePattern(dtf, x, implDetails);
12
+ const result = ArrayCreate(0);
13
+ for (const part of parts) {
14
+ result.push({
15
+ type: part.type,
16
+ value: part.value
17
+ });
18
+ }
19
+ return result;
21
20
  }
@@ -1,17 +1,17 @@
1
- import { DateTimeFormat, DateTimeFormatLocaleInternalData, IntlDateTimeFormatInternal } from '@formatjs/ecma402-abstract';
1
+ import { type DateTimeFormat, type DateTimeFormatLocaleInternalData, type IntlDateTimeFormatInternal } from "@formatjs/ecma402-abstract";
2
2
  /**
3
- * https://tc39.es/ecma402/#sec-initializedatetimeformat
4
- * @param dtf DateTimeFormat
5
- * @param locales locales
6
- * @param opts options
7
- */
8
- export declare function InitializeDateTimeFormat(dtf: Intl.DateTimeFormat | DateTimeFormat, locales: string | string[] | undefined, opts: Intl.DateTimeFormatOptions | undefined, { getInternalSlots, availableLocales, localeData, getDefaultLocale, getDefaultTimeZone, relevantExtensionKeys, tzData, uppercaseLinks, }: {
9
- getInternalSlots(dtf: DateTimeFormat | Intl.DateTimeFormat): IntlDateTimeFormatInternal;
10
- availableLocales: Set<string>;
11
- getDefaultLocale(): string;
12
- getDefaultTimeZone(): string;
13
- relevantExtensionKeys: string[];
14
- localeData: Record<string, DateTimeFormatLocaleInternalData | undefined>;
15
- tzData: Record<string, unknown>;
16
- uppercaseLinks: Record<string, string>;
3
+ * https://tc39.es/ecma402/#sec-initializedatetimeformat
4
+ * @param dtf DateTimeFormat
5
+ * @param locales locales
6
+ * @param opts options
7
+ */
8
+ export declare function InitializeDateTimeFormat(dtf: Intl.DateTimeFormat | DateTimeFormat, locales: string | string[] | undefined, opts: Intl.DateTimeFormatOptions | undefined, { getInternalSlots, availableLocales, localeData, getDefaultLocale, getDefaultTimeZone, relevantExtensionKeys, tzData, uppercaseLinks }: {
9
+ getInternalSlots(dtf: DateTimeFormat | Intl.DateTimeFormat): IntlDateTimeFormatInternal;
10
+ availableLocales: Set<string>;
11
+ getDefaultLocale(): string;
12
+ getDefaultTimeZone(): string;
13
+ relevantExtensionKeys: string[];
14
+ localeData: Record<string, DateTimeFormatLocaleInternalData | undefined>;
15
+ tzData: Record<string, unknown>;
16
+ uppercaseLinks: Record<string, string>;
17
17
  }): Intl.DateTimeFormat;
@@ -1,190 +1,212 @@
1
- import { CanonicalizeLocaleList, CanonicalizeTimeZoneName, GetNumberOption, GetOption, IsValidTimeZoneName, invariant, } from '@formatjs/ecma402-abstract';
2
- import { ResolveLocale } from '@formatjs/intl-localematcher';
3
- import { BasicFormatMatcher } from './BasicFormatMatcher.js';
4
- import { BestFitFormatMatcher } from './BestFitFormatMatcher.js';
5
- import { DateTimeStyleFormat } from './DateTimeStyleFormat.js';
6
- import { ToDateTimeOptions } from './ToDateTimeOptions.js';
7
- import { DATE_TIME_PROPS } from './utils.js';
1
+ import { CanonicalizeLocaleList, CanonicalizeTimeZoneName, GetNumberOption, GetOption, IsValidTimeZoneName, invariant } from "@formatjs/ecma402-abstract";
2
+ import { ResolveLocale } from "@formatjs/intl-localematcher";
3
+ import { BasicFormatMatcher } from "./BasicFormatMatcher.js";
4
+ import { BestFitFormatMatcher } from "./BestFitFormatMatcher.js";
5
+ import { DateTimeStyleFormat } from "./DateTimeStyleFormat.js";
6
+ import { ToDateTimeOptions } from "./ToDateTimeOptions.js";
7
+ import { DATE_TIME_PROPS } from "./utils.js";
8
8
  function isTimeRelated(opt) {
9
- for (var _i = 0, _a = ['hour', 'minute', 'second']; _i < _a.length; _i++) {
10
- var prop = _a[_i];
11
- var value = opt[prop];
12
- if (value !== undefined) {
13
- return true;
14
- }
15
- }
16
- return false;
9
+ for (const prop of [
10
+ "hour",
11
+ "minute",
12
+ "second"
13
+ ]) {
14
+ const value = opt[prop];
15
+ if (value !== undefined) {
16
+ return true;
17
+ }
18
+ }
19
+ return false;
17
20
  }
18
21
  function resolveHourCycle(hc, hcDefault, hour12) {
19
- if (hc == null) {
20
- hc = hcDefault;
21
- }
22
- if (hour12 !== undefined) {
23
- if (hour12) {
24
- if (hcDefault === 'h11' || hcDefault === 'h23') {
25
- hc = 'h11';
26
- }
27
- else {
28
- hc = 'h12';
29
- }
30
- }
31
- else {
32
- invariant(!hour12, 'hour12 must not be set');
33
- if (hcDefault === 'h11' || hcDefault === 'h23') {
34
- hc = 'h23';
35
- }
36
- else {
37
- hc = 'h24';
38
- }
39
- }
40
- }
41
- return hc;
22
+ if (hc == null) {
23
+ hc = hcDefault;
24
+ }
25
+ if (hour12 !== undefined) {
26
+ if (hour12) {
27
+ if (hcDefault === "h11" || hcDefault === "h23") {
28
+ hc = "h11";
29
+ } else {
30
+ hc = "h12";
31
+ }
32
+ } else {
33
+ invariant(!hour12, "hour12 must not be set");
34
+ if (hcDefault === "h11" || hcDefault === "h23") {
35
+ hc = "h23";
36
+ } else {
37
+ hc = "h24";
38
+ }
39
+ }
40
+ }
41
+ return hc;
42
42
  }
43
- var TYPE_REGEX = /^[a-z0-9]{3,8}$/i;
43
+ const TYPE_REGEX = /^[a-z0-9]{3,8}$/i;
44
44
  /**
45
- * https://tc39.es/ecma402/#sec-initializedatetimeformat
46
- * @param dtf DateTimeFormat
47
- * @param locales locales
48
- * @param opts options
49
- */
50
- export function InitializeDateTimeFormat(dtf, locales, opts, _a) {
51
- var getInternalSlots = _a.getInternalSlots, availableLocales = _a.availableLocales, localeData = _a.localeData, getDefaultLocale = _a.getDefaultLocale, getDefaultTimeZone = _a.getDefaultTimeZone, relevantExtensionKeys = _a.relevantExtensionKeys, tzData = _a.tzData, uppercaseLinks = _a.uppercaseLinks;
52
- // @ts-ignore
53
- var requestedLocales = CanonicalizeLocaleList(locales);
54
- var options = ToDateTimeOptions(opts, 'any', 'date');
55
- var opt = Object.create(null);
56
- var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
57
- opt.localeMatcher = matcher;
58
- var calendar = GetOption(options, 'calendar', 'string', undefined, undefined);
59
- if (calendar !== undefined && !TYPE_REGEX.test(calendar)) {
60
- throw new RangeError('Malformed calendar');
61
- }
62
- var internalSlots = getInternalSlots(dtf);
63
- opt.ca = calendar;
64
- var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
65
- if (numberingSystem !== undefined && !TYPE_REGEX.test(numberingSystem)) {
66
- throw new RangeError('Malformed numbering system');
67
- }
68
- opt.nu = numberingSystem;
69
- var hour12 = GetOption(options, 'hour12', 'boolean', undefined, undefined);
70
- var hourCycle = GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
71
- if (hour12 !== undefined) {
72
- // @ts-ignore
73
- hourCycle = null;
74
- }
75
- opt.hc = hourCycle;
76
- var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
77
- internalSlots.locale = r.locale;
78
- calendar = r.ca;
79
- internalSlots.calendar = calendar;
80
- internalSlots.hourCycle = r.hc;
81
- internalSlots.numberingSystem = r.nu;
82
- var dataLocale = r.dataLocale;
83
- internalSlots.dataLocale = dataLocale;
84
- var timeZone = options.timeZone;
85
- if (timeZone !== undefined) {
86
- timeZone = String(timeZone);
87
- if (!IsValidTimeZoneName(timeZone, {
88
- zoneNamesFromData: Object.keys(tzData),
89
- uppercaseLinks: uppercaseLinks,
90
- })) {
91
- throw new RangeError('Invalid timeZoneName');
92
- }
93
- timeZone = CanonicalizeTimeZoneName(timeZone, {
94
- zoneNames: Object.keys(tzData),
95
- uppercaseLinks: uppercaseLinks,
96
- });
97
- }
98
- else {
99
- timeZone = getDefaultTimeZone();
100
- }
101
- internalSlots.timeZone = timeZone;
102
- opt = Object.create(null);
103
- opt.weekday = GetOption(options, 'weekday', 'string', ['narrow', 'short', 'long'], undefined);
104
- opt.era = GetOption(options, 'era', 'string', ['narrow', 'short', 'long'], undefined);
105
- opt.year = GetOption(options, 'year', 'string', ['2-digit', 'numeric'], undefined);
106
- opt.month = GetOption(options, 'month', 'string', ['2-digit', 'numeric', 'narrow', 'short', 'long'], undefined);
107
- opt.day = GetOption(options, 'day', 'string', ['2-digit', 'numeric'], undefined);
108
- opt.hour = GetOption(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
109
- opt.minute = GetOption(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
110
- opt.second = GetOption(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
111
- opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', [
112
- 'long',
113
- 'short',
114
- 'longOffset',
115
- 'shortOffset',
116
- 'longGeneric',
117
- 'shortGeneric',
118
- ], undefined);
119
- opt.fractionalSecondDigits = GetNumberOption(options, 'fractionalSecondDigits', 1, 3, undefined);
120
- var dataLocaleData = localeData[dataLocale];
121
- invariant(!!dataLocaleData, "Missing locale data for ".concat(dataLocale));
122
- var formats = dataLocaleData.formats[calendar];
123
- // UNSPECCED: IMPLEMENTATION DETAILS
124
- if (!formats) {
125
- throw new RangeError("Calendar \"".concat(calendar, "\" is not supported. Try setting \"calendar\" to 1 of the following: ").concat(Object.keys(dataLocaleData.formats).join(', ')));
126
- }
127
- var formatMatcher = GetOption(options, 'formatMatcher', 'string', ['basic', 'best fit'], 'best fit');
128
- var dateStyle = GetOption(options, 'dateStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
129
- internalSlots.dateStyle = dateStyle;
130
- var timeStyle = GetOption(options, 'timeStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
131
- internalSlots.timeStyle = timeStyle;
132
- var bestFormat;
133
- if (dateStyle === undefined && timeStyle === undefined) {
134
- if (formatMatcher === 'basic') {
135
- bestFormat = BasicFormatMatcher(opt, formats);
136
- }
137
- else {
138
- // IMPL DETAILS START
139
- if (isTimeRelated(opt)) {
140
- var hc = resolveHourCycle(internalSlots.hourCycle, dataLocaleData.hourCycle, hour12);
141
- opt.hour12 = hc === 'h11' || hc === 'h12';
142
- }
143
- // IMPL DETAILS END
144
- bestFormat = BestFitFormatMatcher(opt, formats);
145
- }
146
- }
147
- else {
148
- for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
149
- var prop = DATE_TIME_PROPS_1[_i];
150
- var p = opt[prop];
151
- if (p !== undefined) {
152
- throw new TypeError("Intl.DateTimeFormat can't set option ".concat(prop, " when ").concat(dateStyle ? 'dateStyle' : 'timeStyle', " is used"));
153
- }
154
- }
155
- bestFormat = DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData);
156
- }
157
- // IMPL DETAIL START
158
- // For debugging
159
- internalSlots.format = bestFormat;
160
- // IMPL DETAIL END
161
- for (var prop in opt) {
162
- var p = bestFormat[prop];
163
- if (p !== undefined) {
164
- internalSlots[prop] = p;
165
- }
166
- }
167
- var pattern;
168
- var rangePatterns;
169
- if (internalSlots.hour !== undefined) {
170
- var hc = resolveHourCycle(internalSlots.hourCycle, dataLocaleData.hourCycle, hour12);
171
- internalSlots.hourCycle = hc;
172
- if (hc === 'h11' || hc === 'h12') {
173
- pattern = bestFormat.pattern12;
174
- rangePatterns = bestFormat.rangePatterns12;
175
- }
176
- else {
177
- pattern = bestFormat.pattern;
178
- rangePatterns = bestFormat.rangePatterns;
179
- }
180
- }
181
- else {
182
- // @ts-ignore
183
- internalSlots.hourCycle = undefined;
184
- pattern = bestFormat.pattern;
185
- rangePatterns = bestFormat.rangePatterns;
186
- }
187
- internalSlots.pattern = pattern;
188
- internalSlots.rangePatterns = rangePatterns;
189
- return dtf; // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged
45
+ * https://tc39.es/ecma402/#sec-initializedatetimeformat
46
+ * @param dtf DateTimeFormat
47
+ * @param locales locales
48
+ * @param opts options
49
+ */
50
+ export function InitializeDateTimeFormat(dtf, locales, opts, { getInternalSlots, availableLocales, localeData, getDefaultLocale, getDefaultTimeZone, relevantExtensionKeys, tzData, uppercaseLinks }) {
51
+ // @ts-ignore
52
+ const requestedLocales = CanonicalizeLocaleList(locales);
53
+ const options = ToDateTimeOptions(opts, "any", "date");
54
+ let opt = Object.create(null);
55
+ let matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
56
+ opt.localeMatcher = matcher;
57
+ let calendar = GetOption(options, "calendar", "string", undefined, undefined);
58
+ if (calendar !== undefined && !TYPE_REGEX.test(calendar)) {
59
+ throw new RangeError("Malformed calendar");
60
+ }
61
+ const internalSlots = getInternalSlots(dtf);
62
+ opt.ca = calendar;
63
+ const numberingSystem = GetOption(options, "numberingSystem", "string", undefined, undefined);
64
+ if (numberingSystem !== undefined && !TYPE_REGEX.test(numberingSystem)) {
65
+ throw new RangeError("Malformed numbering system");
66
+ }
67
+ opt.nu = numberingSystem;
68
+ const hour12 = GetOption(options, "hour12", "boolean", undefined, undefined);
69
+ let hourCycle = GetOption(options, "hourCycle", "string", [
70
+ "h11",
71
+ "h12",
72
+ "h23",
73
+ "h24"
74
+ ], undefined);
75
+ if (hour12 !== undefined) {
76
+ // @ts-ignore
77
+ hourCycle = null;
78
+ }
79
+ opt.hc = hourCycle;
80
+ const r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
81
+ internalSlots.locale = r.locale;
82
+ calendar = r.ca;
83
+ internalSlots.calendar = calendar;
84
+ internalSlots.hourCycle = r.hc;
85
+ internalSlots.numberingSystem = r.nu;
86
+ const { dataLocale } = r;
87
+ internalSlots.dataLocale = dataLocale;
88
+ let { timeZone } = options;
89
+ if (timeZone !== undefined) {
90
+ timeZone = String(timeZone);
91
+ if (!IsValidTimeZoneName(timeZone, {
92
+ zoneNamesFromData: Object.keys(tzData),
93
+ uppercaseLinks
94
+ })) {
95
+ throw new RangeError("Invalid timeZoneName");
96
+ }
97
+ timeZone = CanonicalizeTimeZoneName(timeZone, {
98
+ zoneNames: Object.keys(tzData),
99
+ uppercaseLinks
100
+ });
101
+ } else {
102
+ timeZone = getDefaultTimeZone();
103
+ }
104
+ internalSlots.timeZone = timeZone;
105
+ opt = Object.create(null);
106
+ opt.weekday = GetOption(options, "weekday", "string", [
107
+ "narrow",
108
+ "short",
109
+ "long"
110
+ ], undefined);
111
+ opt.era = GetOption(options, "era", "string", [
112
+ "narrow",
113
+ "short",
114
+ "long"
115
+ ], undefined);
116
+ opt.year = GetOption(options, "year", "string", ["2-digit", "numeric"], undefined);
117
+ opt.month = GetOption(options, "month", "string", [
118
+ "2-digit",
119
+ "numeric",
120
+ "narrow",
121
+ "short",
122
+ "long"
123
+ ], undefined);
124
+ opt.day = GetOption(options, "day", "string", ["2-digit", "numeric"], undefined);
125
+ opt.hour = GetOption(options, "hour", "string", ["2-digit", "numeric"], undefined);
126
+ opt.minute = GetOption(options, "minute", "string", ["2-digit", "numeric"], undefined);
127
+ opt.second = GetOption(options, "second", "string", ["2-digit", "numeric"], undefined);
128
+ opt.timeZoneName = GetOption(options, "timeZoneName", "string", [
129
+ "long",
130
+ "short",
131
+ "longOffset",
132
+ "shortOffset",
133
+ "longGeneric",
134
+ "shortGeneric"
135
+ ], undefined);
136
+ opt.fractionalSecondDigits = GetNumberOption(options, "fractionalSecondDigits", 1, 3, undefined);
137
+ const dataLocaleData = localeData[dataLocale];
138
+ invariant(!!dataLocaleData, `Missing locale data for ${dataLocale}`);
139
+ const formats = dataLocaleData.formats[calendar];
140
+ // UNSPECCED: IMPLEMENTATION DETAILS
141
+ if (!formats) {
142
+ throw new RangeError(`Calendar "${calendar}" is not supported. Try setting "calendar" to 1 of the following: ${Object.keys(dataLocaleData.formats).join(", ")}`);
143
+ }
144
+ const formatMatcher = GetOption(options, "formatMatcher", "string", ["basic", "best fit"], "best fit");
145
+ const dateStyle = GetOption(options, "dateStyle", "string", [
146
+ "full",
147
+ "long",
148
+ "medium",
149
+ "short"
150
+ ], undefined);
151
+ internalSlots.dateStyle = dateStyle;
152
+ const timeStyle = GetOption(options, "timeStyle", "string", [
153
+ "full",
154
+ "long",
155
+ "medium",
156
+ "short"
157
+ ], undefined);
158
+ internalSlots.timeStyle = timeStyle;
159
+ let bestFormat;
160
+ if (dateStyle === undefined && timeStyle === undefined) {
161
+ if (formatMatcher === "basic") {
162
+ bestFormat = BasicFormatMatcher(opt, formats);
163
+ } else {
164
+ // IMPL DETAILS START
165
+ if (isTimeRelated(opt)) {
166
+ const hc = resolveHourCycle(internalSlots.hourCycle, dataLocaleData.hourCycle, hour12);
167
+ opt.hour12 = hc === "h11" || hc === "h12";
168
+ }
169
+ // IMPL DETAILS END
170
+ bestFormat = BestFitFormatMatcher(opt, formats);
171
+ }
172
+ } else {
173
+ for (const prop of DATE_TIME_PROPS) {
174
+ const p = opt[prop];
175
+ if (p !== undefined) {
176
+ throw new TypeError(`Intl.DateTimeFormat can't set option ${prop} when ${dateStyle ? "dateStyle" : "timeStyle"} is used`);
177
+ }
178
+ }
179
+ bestFormat = DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData);
180
+ }
181
+ // IMPL DETAIL START
182
+ // For debugging
183
+ internalSlots.format = bestFormat;
184
+ // IMPL DETAIL END
185
+ for (const prop in opt) {
186
+ const p = bestFormat[prop];
187
+ if (p !== undefined) {
188
+ internalSlots[prop] = p;
189
+ }
190
+ }
191
+ let pattern;
192
+ let rangePatterns;
193
+ if (internalSlots.hour !== undefined) {
194
+ const hc = resolveHourCycle(internalSlots.hourCycle, dataLocaleData.hourCycle, hour12);
195
+ internalSlots.hourCycle = hc;
196
+ if (hc === "h11" || hc === "h12") {
197
+ pattern = bestFormat.pattern12;
198
+ rangePatterns = bestFormat.rangePatterns12;
199
+ } else {
200
+ pattern = bestFormat.pattern;
201
+ rangePatterns = bestFormat.rangePatterns;
202
+ }
203
+ } else {
204
+ // @ts-ignore
205
+ internalSlots.hourCycle = undefined;
206
+ pattern = bestFormat.pattern;
207
+ rangePatterns = bestFormat.rangePatterns;
208
+ }
209
+ internalSlots.pattern = pattern;
210
+ internalSlots.rangePatterns = rangePatterns;
211
+ return dtf;
190
212
  }
@@ -1,10 +1,10 @@
1
- import { DateTimeFormat, IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
2
- import Decimal from 'decimal.js';
3
- import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern.js';
4
- import { ToLocalTimeImplDetails } from './ToLocalTime.js';
1
+ import { type DateTimeFormat, type IntlDateTimeFormatPart } from "@formatjs/ecma402-abstract";
2
+ import type Decimal from "decimal.js";
3
+ import { type FormatDateTimePatternImplDetails } from "./FormatDateTimePattern.js";
4
+ import { type ToLocalTimeImplDetails } from "./ToLocalTime.js";
5
5
  /**
6
- * https://tc39.es/ecma402/#sec-partitiondatetimepattern
7
- * @param dtf
8
- * @param x
9
- */
6
+ * https://tc39.es/ecma402/#sec-partitiondatetimepattern
7
+ * @param dtf
8
+ * @param x
9
+ */
10
10
  export declare function PartitionDateTimePattern(dtf: Intl.DateTimeFormat | DateTimeFormat, x: Decimal, implDetails: ToLocalTimeImplDetails & FormatDateTimePatternImplDetails): IntlDateTimeFormatPart[];
@@ -1,17 +1,18 @@
1
- import { invariant, PartitionPattern, TimeClip, } from '@formatjs/ecma402-abstract';
2
- import { FormatDateTimePattern, } from './FormatDateTimePattern.js';
1
+ import { invariant, PartitionPattern, TimeClip } from "@formatjs/ecma402-abstract";
2
+ import { FormatDateTimePattern } from "./FormatDateTimePattern.js";
3
+ import "./ToLocalTime.js";
3
4
  /**
4
- * https://tc39.es/ecma402/#sec-partitiondatetimepattern
5
- * @param dtf
6
- * @param x
7
- */
5
+ * https://tc39.es/ecma402/#sec-partitiondatetimepattern
6
+ * @param dtf
7
+ * @param x
8
+ */
8
9
  export function PartitionDateTimePattern(dtf, x, implDetails) {
9
- x = TimeClip(x);
10
- invariant(!x.isNaN(), 'Invalid time', RangeError);
11
- /** IMPL START */
12
- var getInternalSlots = implDetails.getInternalSlots;
13
- var internalSlots = getInternalSlots(dtf);
14
- /** IMPL END */
15
- var pattern = internalSlots.pattern;
16
- return FormatDateTimePattern(dtf, PartitionPattern(pattern), x, implDetails);
10
+ x = TimeClip(x);
11
+ invariant(!x.isNaN(), "Invalid time", RangeError);
12
+ /** IMPL START */
13
+ const { getInternalSlots } = implDetails;
14
+ const internalSlots = getInternalSlots(dtf);
15
+ /** IMPL END */
16
+ const { pattern } = internalSlots;
17
+ return FormatDateTimePattern(dtf, PartitionPattern(pattern), x, implDetails);
17
18
  }
@@ -1,5 +1,5 @@
1
- import { IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
2
- import Decimal from 'decimal.js';
3
- import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern.js';
4
- import { ToLocalTimeImplDetails } from './ToLocalTime.js';
1
+ import { type IntlDateTimeFormatPart } from "@formatjs/ecma402-abstract";
2
+ import type Decimal from "decimal.js";
3
+ import { type FormatDateTimePatternImplDetails } from "./FormatDateTimePattern.js";
4
+ import { type ToLocalTimeImplDetails } from "./ToLocalTime.js";
5
5
  export declare function PartitionDateTimeRangePattern(dtf: Intl.DateTimeFormat, x: Decimal, y: Decimal, implDetails: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): IntlDateTimeFormatPart[];