@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,2 +1,2 @@
|
|
|
1
|
-
import { DateTimeFormatLocaleInternalData, Formats } from
|
|
2
|
-
export declare function DateTimeStyleFormat(dateStyle: Intl.DateTimeFormatOptions[
|
|
1
|
+
import { type DateTimeFormatLocaleInternalData, type Formats } from "@formatjs/ecma402-abstract";
|
|
2
|
+
export declare function DateTimeStyleFormat(dateStyle: Intl.DateTimeFormatOptions["dateStyle"], timeStyle: Intl.DateTimeFormatOptions["timeStyle"], dataLocaleData: DateTimeFormatLocaleInternalData): Formats;
|
|
@@ -1,64 +1,49 @@
|
|
|
1
|
-
import { invariant
|
|
1
|
+
import { invariant } from "@formatjs/ecma402-abstract";
|
|
2
2
|
export function DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// This is needed for formatRange to work with dateStyle/timeStyle
|
|
50
|
-
// See: https://github.com/formatjs/formatjs/issues/4168
|
|
51
|
-
if (timeFormat.rangePatterns) {
|
|
52
|
-
format.rangePatterns = timeFormat.rangePatterns;
|
|
53
|
-
}
|
|
54
|
-
if (timeFormat.rangePatterns12) {
|
|
55
|
-
format.rangePatterns12 = timeFormat.rangePatterns12;
|
|
56
|
-
}
|
|
57
|
-
return format;
|
|
58
|
-
}
|
|
59
|
-
if (timeStyle !== undefined) {
|
|
60
|
-
return timeFormat;
|
|
61
|
-
}
|
|
62
|
-
invariant(dateStyle !== undefined, 'dateStyle should not be undefined');
|
|
63
|
-
return dateFormat;
|
|
3
|
+
let dateFormat, timeFormat;
|
|
4
|
+
if (timeStyle !== undefined) {
|
|
5
|
+
invariant(timeStyle === "full" || timeStyle === "long" || timeStyle === "medium" || timeStyle === "short", "invalid timeStyle");
|
|
6
|
+
timeFormat = dataLocaleData.timeFormat[timeStyle];
|
|
7
|
+
}
|
|
8
|
+
if (dateStyle !== undefined) {
|
|
9
|
+
invariant(dateStyle === "full" || dateStyle === "long" || dateStyle === "medium" || dateStyle === "short", "invalid dateStyle");
|
|
10
|
+
dateFormat = dataLocaleData.dateFormat[dateStyle];
|
|
11
|
+
}
|
|
12
|
+
if (dateStyle !== undefined && timeStyle !== undefined) {
|
|
13
|
+
const format = {};
|
|
14
|
+
for (const field in dateFormat) {
|
|
15
|
+
if (field !== "pattern" && field !== "rangePatterns" && field !== "rangePatterns12") {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
format[field] = dateFormat[field];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (const field in timeFormat) {
|
|
21
|
+
if (field !== "pattern" && field !== "pattern12" && field !== "rangePatterns" && field !== "rangePatterns12") {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
format[field] = timeFormat[field];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const connector = dataLocaleData.dateTimeFormat[dateStyle];
|
|
27
|
+
const pattern = connector.replace("{0}", timeFormat.pattern).replace("{1}", dateFormat.pattern);
|
|
28
|
+
format.pattern = pattern;
|
|
29
|
+
if ("pattern12" in timeFormat) {
|
|
30
|
+
const pattern12 = connector.replace("{0}", timeFormat.pattern12).replace("{1}", dateFormat.pattern);
|
|
31
|
+
format.pattern12 = pattern12;
|
|
32
|
+
}
|
|
33
|
+
// Merge rangePatterns from timeFormat (for time-related differences)
|
|
34
|
+
// This is needed for formatRange to work with dateStyle/timeStyle
|
|
35
|
+
// See: https://github.com/formatjs/formatjs/issues/4168
|
|
36
|
+
if (timeFormat.rangePatterns) {
|
|
37
|
+
format.rangePatterns = timeFormat.rangePatterns;
|
|
38
|
+
}
|
|
39
|
+
if (timeFormat.rangePatterns12) {
|
|
40
|
+
format.rangePatterns12 = timeFormat.rangePatterns12;
|
|
41
|
+
}
|
|
42
|
+
return format;
|
|
43
|
+
}
|
|
44
|
+
if (timeStyle !== undefined) {
|
|
45
|
+
return timeFormat;
|
|
46
|
+
}
|
|
47
|
+
invariant(dateStyle !== undefined, "dateStyle should not be undefined");
|
|
48
|
+
return dateFormat;
|
|
64
49
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DateTimeFormat } from
|
|
2
|
-
import Decimal from
|
|
3
|
-
import { PartitionDateTimePattern } from
|
|
1
|
+
import { type DateTimeFormat } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import type Decimal from "decimal.js";
|
|
3
|
+
import { PartitionDateTimePattern } from "./PartitionDateTimePattern.js";
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
* https://tc39.es/ecma402/#sec-formatdatetime
|
|
6
|
+
* @param dtf DateTimeFormat
|
|
7
|
+
* @param x
|
|
8
|
+
*/
|
|
9
9
|
export declare function FormatDateTime(dtf: Intl.DateTimeFormat | DateTimeFormat, x: Decimal, implDetails: Parameters<typeof PartitionDateTimePattern>[2]): string;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@formatjs/ecma402-abstract";
|
|
2
|
+
import { PartitionDateTimePattern } from "./PartitionDateTimePattern.js";
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
* https://tc39.es/ecma402/#sec-formatdatetime
|
|
5
|
+
* @param dtf DateTimeFormat
|
|
6
|
+
* @param x
|
|
7
|
+
*/
|
|
7
8
|
export function FormatDateTime(dtf, x, implDetails) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return result;
|
|
9
|
+
const parts = PartitionDateTimePattern(dtf, x, implDetails);
|
|
10
|
+
let result = "";
|
|
11
|
+
for (const part of parts) {
|
|
12
|
+
result += part.value;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
15
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DateTimeFormat, DateTimeFormatLocaleInternalData, IntlDateTimeFormatInternal, IntlDateTimeFormatPart } from
|
|
2
|
-
import Decimal from
|
|
3
|
-
import { ToLocalTimeImplDetails } from
|
|
1
|
+
import { type DateTimeFormat, type DateTimeFormatLocaleInternalData, type IntlDateTimeFormatInternal, type IntlDateTimeFormatPart } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
import { type ToLocalTimeImplDetails } from "./ToLocalTime.js";
|
|
4
4
|
export interface FormatDateTimePatternImplDetails {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
getInternalSlots(dtf: Intl.DateTimeFormat | DateTimeFormat): IntlDateTimeFormatInternal;
|
|
6
|
+
localeData: Record<string, DateTimeFormatLocaleInternalData>;
|
|
7
|
+
getDefaultTimeZone(): string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export declare function FormatDateTimePattern(dtf: Intl.DateTimeFormat | DateTimeFormat, patternParts: IntlDateTimeFormatPart[], x: Decimal, { getInternalSlots, localeData, getDefaultTimeZone, tzData
|
|
10
|
+
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
11
|
+
* @param dtf
|
|
12
|
+
* @param x
|
|
13
|
+
*/
|
|
14
|
+
export declare function FormatDateTimePattern(dtf: Intl.DateTimeFormat | DateTimeFormat, patternParts: IntlDateTimeFormatPart[], x: Decimal, { getInternalSlots, localeData, getDefaultTimeZone, tzData }: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): IntlDateTimeFormatPart[];
|
|
@@ -1,204 +1,191 @@
|
|
|
1
|
-
import { TimeClip, createMemoizedNumberFormat
|
|
2
|
-
import Decimal from
|
|
3
|
-
import { ToLocalTime } from
|
|
4
|
-
import { DATE_TIME_PROPS } from
|
|
1
|
+
import { TimeClip, createMemoizedNumberFormat } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
import { ToLocalTime } from "./ToLocalTime.js";
|
|
4
|
+
import { DATE_TIME_PROPS } from "./utils.js";
|
|
5
5
|
function pad(n) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
if (n < 10) {
|
|
7
|
+
return `0${n}`;
|
|
8
|
+
}
|
|
9
|
+
return String(n);
|
|
10
10
|
}
|
|
11
11
|
function offsetToGmtString(gmtFormat, hourFormat, offsetInMs, style) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
pattern = pattern.replace(/:?m+/, '');
|
|
28
|
-
}
|
|
29
|
-
offsetStr = pattern.replace(/H+/, String(hours)).replace(/m+/, String(mins));
|
|
30
|
-
}
|
|
31
|
-
return gmtFormat.replace('{0}', offsetStr);
|
|
12
|
+
const offsetInMinutes = Math.floor(offsetInMs / 6e4);
|
|
13
|
+
const mins = Math.abs(offsetInMinutes) % 60;
|
|
14
|
+
const hours = Math.floor(Math.abs(offsetInMinutes) / 60);
|
|
15
|
+
const [positivePattern, negativePattern] = hourFormat.split(";");
|
|
16
|
+
let offsetStr = "";
|
|
17
|
+
let pattern = offsetInMs < 0 ? negativePattern : positivePattern;
|
|
18
|
+
if (style === "long") {
|
|
19
|
+
offsetStr = pattern.replace("HH", pad(hours)).replace("H", String(hours)).replace("mm", pad(mins)).replace("m", String(mins));
|
|
20
|
+
} else if (mins || hours) {
|
|
21
|
+
if (!mins) {
|
|
22
|
+
pattern = pattern.replace(/:?m+/, "");
|
|
23
|
+
}
|
|
24
|
+
offsetStr = pattern.replace(/H+/, String(hours)).replace(/m+/, String(mins));
|
|
25
|
+
}
|
|
26
|
+
return gmtFormat.replace("{0}", offsetStr);
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export function FormatDateTimePattern(dtf, patternParts, x,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
result.push({
|
|
197
|
-
// @ts-ignore TODO: Fix TS type
|
|
198
|
-
type: 'yearName',
|
|
199
|
-
value: fv,
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return result;
|
|
29
|
+
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
30
|
+
* @param dtf
|
|
31
|
+
* @param x
|
|
32
|
+
*/
|
|
33
|
+
export function FormatDateTimePattern(dtf, patternParts, x, { getInternalSlots, localeData, getDefaultTimeZone, tzData }) {
|
|
34
|
+
x = TimeClip(x);
|
|
35
|
+
/** IMPL START */
|
|
36
|
+
const internalSlots = getInternalSlots(dtf);
|
|
37
|
+
const dataLocale = internalSlots.dataLocale;
|
|
38
|
+
const dataLocaleData = localeData[dataLocale];
|
|
39
|
+
/** IMPL END */
|
|
40
|
+
const locale = internalSlots.locale;
|
|
41
|
+
const nfOptions = Object.create(null);
|
|
42
|
+
nfOptions.useGrouping = false;
|
|
43
|
+
const nf = createMemoizedNumberFormat(locale, nfOptions);
|
|
44
|
+
const nf2Options = Object.create(null);
|
|
45
|
+
nf2Options.minimumIntegerDigits = 2;
|
|
46
|
+
nf2Options.useGrouping = false;
|
|
47
|
+
const nf2 = createMemoizedNumberFormat(locale, nf2Options);
|
|
48
|
+
const fractionalSecondDigits = internalSlots.fractionalSecondDigits;
|
|
49
|
+
let nf3;
|
|
50
|
+
if (fractionalSecondDigits !== undefined) {
|
|
51
|
+
const nf3Options = Object.create(null);
|
|
52
|
+
nf3Options.minimumIntegerDigits = fractionalSecondDigits;
|
|
53
|
+
nf3Options.useGrouping = false;
|
|
54
|
+
nf3 = createMemoizedNumberFormat(locale, nf3Options);
|
|
55
|
+
}
|
|
56
|
+
const tm = ToLocalTime(
|
|
57
|
+
x,
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
internalSlots.calendar,
|
|
60
|
+
internalSlots.timeZone,
|
|
61
|
+
{ tzData }
|
|
62
|
+
);
|
|
63
|
+
const result = [];
|
|
64
|
+
// Check if month is stand-alone (no other date fields like day, year, weekday)
|
|
65
|
+
const hasMonth = patternParts.some((part) => part.type === "month");
|
|
66
|
+
const hasOtherDateFields = patternParts.some((part) => part.type === "day" || part.type === "year" || part.type === "weekday" || part.type === "era");
|
|
67
|
+
const isMonthStandalone = hasMonth && !hasOtherDateFields;
|
|
68
|
+
for (const patternPart of patternParts) {
|
|
69
|
+
const p = patternPart.type;
|
|
70
|
+
if (p === "literal") {
|
|
71
|
+
result.push({
|
|
72
|
+
type: "literal",
|
|
73
|
+
value: patternPart.value
|
|
74
|
+
});
|
|
75
|
+
} else if (p === "fractionalSecondDigits") {
|
|
76
|
+
const v = new Decimal(tm.millisecond).times(10).pow((fractionalSecondDigits || 0) - 3).floor().toNumber();
|
|
77
|
+
result.push({
|
|
78
|
+
type: "fractionalSecond",
|
|
79
|
+
value: nf3.format(v)
|
|
80
|
+
});
|
|
81
|
+
} else if (p === "dayPeriod") {
|
|
82
|
+
const f = internalSlots.dayPeriod;
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
const fv = tm[f];
|
|
85
|
+
result.push({
|
|
86
|
+
type: p,
|
|
87
|
+
value: fv
|
|
88
|
+
});
|
|
89
|
+
} else if (p === "timeZoneName") {
|
|
90
|
+
const f = internalSlots.timeZoneName;
|
|
91
|
+
let fv;
|
|
92
|
+
const { timeZoneName, gmtFormat, hourFormat } = dataLocaleData;
|
|
93
|
+
const timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
94
|
+
const timeZoneData = timeZoneName[timeZone];
|
|
95
|
+
if (timeZoneData && timeZoneData[f]) {
|
|
96
|
+
const names = timeZoneData[f];
|
|
97
|
+
// GH #5114: If in DST and both standard/daylight names are the same,
|
|
98
|
+
// fall back to GMT offset format (matches native browser behavior).
|
|
99
|
+
// This handles locales where CLDR doesn't provide a daylight name.
|
|
100
|
+
// NOTE: This is a formatjs implementation detail - ECMA-402 doesn't
|
|
101
|
+
// explicitly specify behavior for missing DST names in locale data.
|
|
102
|
+
if (tm.inDST && names.length >= 2 && names[0] === names[1]) {
|
|
103
|
+
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
104
|
+
} else {
|
|
105
|
+
fv = names[+tm.inDST];
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
// Fallback to gmtFormat
|
|
109
|
+
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
110
|
+
}
|
|
111
|
+
result.push({
|
|
112
|
+
type: p,
|
|
113
|
+
value: fv
|
|
114
|
+
});
|
|
115
|
+
} else if (DATE_TIME_PROPS.indexOf(p) > -1) {
|
|
116
|
+
let fv = "";
|
|
117
|
+
const f = internalSlots[p];
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
let v = tm[p];
|
|
120
|
+
if (p === "year" && v <= 0) {
|
|
121
|
+
v = 1 - v;
|
|
122
|
+
}
|
|
123
|
+
if (p === "month") {
|
|
124
|
+
v++;
|
|
125
|
+
}
|
|
126
|
+
const hourCycle = internalSlots.hourCycle;
|
|
127
|
+
if (p === "hour" && (hourCycle === "h11" || hourCycle === "h12")) {
|
|
128
|
+
v = v % 12;
|
|
129
|
+
if (v === 0 && hourCycle === "h12") {
|
|
130
|
+
v = 12;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (p === "hour" && hourCycle === "h24") {
|
|
134
|
+
if (v === 0) {
|
|
135
|
+
v = 24;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (f === "numeric") {
|
|
139
|
+
fv = nf.format(v);
|
|
140
|
+
} else if (f === "2-digit") {
|
|
141
|
+
fv = nf2.format(v);
|
|
142
|
+
if (fv.length > 2) {
|
|
143
|
+
fv = fv.slice(fv.length - 2, fv.length);
|
|
144
|
+
}
|
|
145
|
+
} else if (f === "narrow" || f === "short" || f === "long") {
|
|
146
|
+
if (p === "era") {
|
|
147
|
+
fv = dataLocaleData[p][f][v];
|
|
148
|
+
} else if (p === "month") {
|
|
149
|
+
// Use stand-alone month form if available and month is displayed alone
|
|
150
|
+
const monthData = isMonthStandalone && dataLocaleData.monthStandalone ? dataLocaleData.monthStandalone : dataLocaleData.month;
|
|
151
|
+
fv = monthData[f][v - 1];
|
|
152
|
+
} else {
|
|
153
|
+
fv = dataLocaleData[p][f][v];
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
result.push({
|
|
157
|
+
type: p,
|
|
158
|
+
value: fv
|
|
159
|
+
});
|
|
160
|
+
} else if (p === "ampm") {
|
|
161
|
+
const v = tm.hour;
|
|
162
|
+
let fv;
|
|
163
|
+
if (v > 11) {
|
|
164
|
+
fv = dataLocaleData.pm;
|
|
165
|
+
} else {
|
|
166
|
+
fv = dataLocaleData.am;
|
|
167
|
+
}
|
|
168
|
+
result.push({
|
|
169
|
+
type: "dayPeriod",
|
|
170
|
+
value: fv
|
|
171
|
+
});
|
|
172
|
+
} else if (p === "relatedYear") {
|
|
173
|
+
const v = tm.relatedYear;
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
const fv = nf.format(v);
|
|
176
|
+
result.push({
|
|
177
|
+
type: "relatedYear",
|
|
178
|
+
value: fv
|
|
179
|
+
});
|
|
180
|
+
} else if (p === "yearName") {
|
|
181
|
+
const v = tm.yearName;
|
|
182
|
+
// @ts-ignore
|
|
183
|
+
const fv = nf.format(v);
|
|
184
|
+
result.push({
|
|
185
|
+
type: "yearName",
|
|
186
|
+
value: fv
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
204
191
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Decimal from
|
|
2
|
-
import { FormatDateTimePatternImplDetails } from
|
|
3
|
-
import { ToLocalTimeImplDetails } from
|
|
1
|
+
import type Decimal from "decimal.js";
|
|
2
|
+
import { type FormatDateTimePatternImplDetails } from "./FormatDateTimePattern.js";
|
|
3
|
+
import { type ToLocalTimeImplDetails } from "./ToLocalTime.js";
|
|
4
4
|
export declare function FormatDateTimeRange(dtf: Intl.DateTimeFormat, x: Decimal, y: Decimal, implDetails: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./FormatDateTimePattern.js";
|
|
2
|
+
import { PartitionDateTimeRangePattern } from "./PartitionDateTimeRangePattern.js";
|
|
3
|
+
import "./ToLocalTime.js";
|
|
2
4
|
export function FormatDateTimeRange(dtf, x, y, implDetails) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return result;
|
|
5
|
+
const parts = PartitionDateTimeRangePattern(dtf, x, y, implDetails);
|
|
6
|
+
let result = "";
|
|
7
|
+
for (const part of parts) {
|
|
8
|
+
result += part.value;
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
10
11
|
}
|
|
@@ -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 FormatDateTimeRangeToParts(dtf: Intl.DateTimeFormat, x: Decimal, y: Decimal, implDetails: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): IntlDateTimeFormatPart[];
|