@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.
- package/add-all-tz.js +319 -318
- package/add-golden-tz.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +5 -5
- package/polyfill-force.js +28 -44
- package/polyfill.iife.js +2803 -3046
- package/polyfill.js +29 -45
- package/should-polyfill.js +38 -50
- package/src/abstract/BasicFormatMatcher.d.ts +5 -5
- package/src/abstract/BasicFormatMatcher.js +87 -103
- package/src/abstract/BestFitFormatMatcher.d.ts +12 -12
- package/src/abstract/BestFitFormatMatcher.js +102 -108
- package/src/abstract/DateTimeStyleFormat.d.ts +2 -2
- package/src/abstract/DateTimeStyleFormat.js +47 -62
- package/src/abstract/FormatDateTime.d.ts +7 -7
- package/src/abstract/FormatDateTime.js +12 -12
- package/src/abstract/FormatDateTimePattern.d.ts +11 -11
- package/src/abstract/FormatDateTimePattern.js +185 -198
- package/src/abstract/FormatDateTimeRange.d.ts +3 -3
- package/src/abstract/FormatDateTimeRange.js +9 -8
- package/src/abstract/FormatDateTimeRangeToParts.d.ts +4 -4
- package/src/abstract/FormatDateTimeRangeToParts.js +14 -12
- package/src/abstract/FormatDateTimeToParts.d.ts +9 -9
- package/src/abstract/FormatDateTimeToParts.js +17 -18
- package/src/abstract/InitializeDateTimeFormat.d.ts +15 -15
- package/src/abstract/InitializeDateTimeFormat.js +206 -184
- package/src/abstract/PartitionDateTimePattern.d.ts +8 -8
- package/src/abstract/PartitionDateTimePattern.js +15 -14
- package/src/abstract/PartitionDateTimeRangePattern.d.ts +4 -4
- package/src/abstract/PartitionDateTimeRangePattern.js +168 -161
- package/src/abstract/ToDateTimeOptions.d.ts +5 -5
- package/src/abstract/ToDateTimeOptions.js +68 -60
- package/src/abstract/ToLocalTime.d.ts +21 -21
- package/src/abstract/ToLocalTime.js +116 -45
- package/src/abstract/skeleton.d.ts +8 -8
- package/src/abstract/skeleton.js +231 -280
- package/src/abstract/utils.d.ts +1 -1
- package/src/abstract/utils.js +21 -20
- package/src/core.d.ts +17 -17
- package/src/core.js +250 -286
- package/src/data/all-tz.generated.d.ts +8 -0
- package/src/data/all-tz.generated.js +462 -0
- package/src/data/links.generated.d.ts +261 -0
- package/src/data/links.generated.js +260 -0
- package/src/get_internal_slots.d.ts +3 -1
- package/src/get_internal_slots.js +8 -7
- package/src/packer.d.ts +2 -2
- package/src/packer.js +23 -35
- package/src/to_locale_string.d.ts +3 -3
- package/src/to_locale_string.js +11 -11
- package/src/types.d.ts +34 -39
- package/src/types.js +1 -1
- package/supported-locales.generated.js +573 -1
- package/test262-main.d.ts +4 -1
- package/test262-main.js +24600 -44193
- package/src/data/all-tz.d.ts +0 -6
- package/src/data/all-tz.js +0 -461
- package/src/data/links.d.ts +0 -259
- package/src/data/links.js +0 -260
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
2
|
-
import Decimal from
|
|
3
|
-
import { PartitionDateTimePattern } from
|
|
1
|
+
import { type IntlDateTimeFormatPart } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import type Decimal from "decimal.js";
|
|
3
|
+
import { PartitionDateTimePattern } from "./PartitionDateTimePattern.js";
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
2
|
-
import { PartitionDateTimePattern } from
|
|
1
|
+
import { ArrayCreate } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import { PartitionDateTimePattern } from "./PartitionDateTimePattern.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
1
|
+
import { type DateTimeFormat, type DateTimeFormatLocaleInternalData, type IntlDateTimeFormatInternal } from "@formatjs/ecma402-abstract";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
2
|
-
import { ResolveLocale } from
|
|
3
|
-
import { BasicFormatMatcher } from
|
|
4
|
-
import { BestFitFormatMatcher } from
|
|
5
|
-
import { DateTimeStyleFormat } from
|
|
6
|
-
import { ToDateTimeOptions } from
|
|
7
|
-
import { DATE_TIME_PROPS } from
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
43
|
+
const TYPE_REGEX = /^[a-z0-9]{3,8}$/i;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export function InitializeDateTimeFormat(dtf, locales, opts,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
|
2
|
-
import Decimal from
|
|
3
|
-
import { FormatDateTimePatternImplDetails } from
|
|
4
|
-
import { ToLocalTimeImplDetails } from
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
2
|
-
import { FormatDateTimePattern
|
|
1
|
+
import { invariant, PartitionPattern, TimeClip } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import { FormatDateTimePattern } from "./FormatDateTimePattern.js";
|
|
3
|
+
import "./ToLocalTime.js";
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
6
|
+
* @param dtf
|
|
7
|
+
* @param x
|
|
8
|
+
*/
|
|
8
9
|
export function PartitionDateTimePattern(dtf, x, implDetails) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
2
|
-
import Decimal from
|
|
3
|
-
import { FormatDateTimePatternImplDetails } from
|
|
4
|
-
import { ToLocalTimeImplDetails } from
|
|
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[];
|