@formatjs/intl-datetimeformat 6.1.1 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/abstract/BasicFormatMatcher.d.ts.map +1 -1
- package/lib/src/abstract/BasicFormatMatcher.js +50 -1
- package/lib/src/abstract/FormatDateTimePattern.d.ts.map +1 -1
- package/lib/src/abstract/FormatDateTimePattern.js +19 -13
- package/lib/src/abstract/InitializeDateTimeFormat.d.ts +3 -3
- package/lib/src/abstract/InitializeDateTimeFormat.d.ts.map +1 -1
- package/lib/src/abstract/InitializeDateTimeFormat.js +9 -2
- package/lib/src/abstract/utils.d.ts +1 -0
- package/lib/src/abstract/utils.d.ts.map +1 -1
- package/lib/src/abstract/utils.js +3 -0
- package/package.json +4 -4
- package/polyfill.iife.js +58 -10
- package/src/abstract/BasicFormatMatcher.d.ts.map +1 -1
- package/src/abstract/BasicFormatMatcher.js +49 -0
- package/src/abstract/FormatDateTimePattern.d.ts.map +1 -1
- package/src/abstract/FormatDateTimePattern.js +19 -13
- package/src/abstract/InitializeDateTimeFormat.d.ts +3 -3
- package/src/abstract/InitializeDateTimeFormat.d.ts.map +1 -1
- package/src/abstract/InitializeDateTimeFormat.js +9 -2
- package/src/abstract/utils.d.ts +1 -0
- package/src/abstract/utils.d.ts.map +1 -1
- package/src/abstract/utils.js +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicFormatMatcher.d.ts","sourceRoot":"","sources":["../../../src/abstract/BasicFormatMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAY,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"BasicFormatMatcher.d.ts","sourceRoot":"","sources":["../../../src/abstract/BasicFormatMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAY,MAAM,4BAA4B,CAAA;AAY7D;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,IAAI,CAAC,qBAAqB,EACnC,OAAO,EAAE,OAAO,EAAE,GACjB,OAAO,CAuFT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { invariant } from '@formatjs/ecma402-abstract';
|
|
3
|
-
import { DATE_TIME_PROPS, additionPenalty, removalPenalty, longMorePenalty, shortMorePenalty, shortLessPenalty, longLessPenalty, } from './utils';
|
|
3
|
+
import { DATE_TIME_PROPS, additionPenalty, removalPenalty, longMorePenalty, shortMorePenalty, shortLessPenalty, longLessPenalty, offsetPenalty, } from './utils';
|
|
4
4
|
/**
|
|
5
5
|
* https://tc39.es/ecma402/#sec-basicformatmatcher
|
|
6
6
|
* @param options
|
|
@@ -23,6 +23,55 @@ export function BasicFormatMatcher(options, formats) {
|
|
|
23
23
|
else if (optionsProp !== undefined && formatProp === undefined) {
|
|
24
24
|
score -= removalPenalty;
|
|
25
25
|
}
|
|
26
|
+
else if (prop === 'timeZoneName') {
|
|
27
|
+
if (optionsProp === 'short' || optionsProp === 'shortGeneric') {
|
|
28
|
+
if (formatProp === 'shortOffset') {
|
|
29
|
+
score -= offsetPenalty;
|
|
30
|
+
}
|
|
31
|
+
else if (formatProp === 'longOffset') {
|
|
32
|
+
score -= offsetPenalty + shortMorePenalty;
|
|
33
|
+
}
|
|
34
|
+
else if (optionsProp === 'short' && formatProp === 'long') {
|
|
35
|
+
score -= shortMorePenalty;
|
|
36
|
+
}
|
|
37
|
+
else if (optionsProp === 'shortGeneric' &&
|
|
38
|
+
formatProp === 'longGeneric') {
|
|
39
|
+
score -= shortMorePenalty;
|
|
40
|
+
}
|
|
41
|
+
else if (optionsProp !== formatProp) {
|
|
42
|
+
score -= removalPenalty;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (optionsProp === 'shortOffset' &&
|
|
46
|
+
formatProp === 'longOffset') {
|
|
47
|
+
score -= shortMorePenalty;
|
|
48
|
+
}
|
|
49
|
+
else if (optionsProp === 'long' || optionsProp === 'longGeneric') {
|
|
50
|
+
if (formatProp === 'longOffset') {
|
|
51
|
+
score -= offsetPenalty;
|
|
52
|
+
}
|
|
53
|
+
else if (formatProp === 'shortOffset') {
|
|
54
|
+
score -= offsetPenalty + longLessPenalty;
|
|
55
|
+
}
|
|
56
|
+
else if (optionsProp === 'long' && formatProp === 'short') {
|
|
57
|
+
score -= longLessPenalty;
|
|
58
|
+
}
|
|
59
|
+
else if (optionsProp === 'longGeneric' &&
|
|
60
|
+
formatProp === 'shortGeneric') {
|
|
61
|
+
score -= longLessPenalty;
|
|
62
|
+
}
|
|
63
|
+
else if (optionsProp !== formatProp) {
|
|
64
|
+
score -= removalPenalty;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (optionsProp === 'longOffset' &&
|
|
68
|
+
formatProp === 'shortOffset') {
|
|
69
|
+
score -= longLessPenalty;
|
|
70
|
+
}
|
|
71
|
+
else if (optionsProp !== formatProp) {
|
|
72
|
+
score -= removalPenalty;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
26
75
|
else if (optionsProp !== formatProp) {
|
|
27
76
|
var values = void 0;
|
|
28
77
|
if (prop === 'fractionalSecondDigits') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatDateTimePattern.d.ts","sourceRoot":"","sources":["../../../src/abstract/FormatDateTimePattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EAEvB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAc,sBAAsB,EAAC,MAAM,eAAe,CAAA;AAsCjE,MAAM,WAAW,gCAAgC;IAC/C,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,GAAG,0BAA0B,CAAA;IACtE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAA;IAC5D,kBAAkB,IAAI,MAAM,CAAA;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,YAAY,EAAE,sBAAsB,EAAE,EACtC,CAAC,EAAE,MAAM,EACT,EACE,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,MAAM,GACP,EAAE,gCAAgC,GAAG,sBAAsB,GAC3D,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"FormatDateTimePattern.d.ts","sourceRoot":"","sources":["../../../src/abstract/FormatDateTimePattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EAEvB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAc,sBAAsB,EAAC,MAAM,eAAe,CAAA;AAsCjE,MAAM,WAAW,gCAAgC;IAC/C,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,GAAG,0BAA0B,CAAA;IACtE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAA;IAC5D,kBAAkB,IAAI,MAAM,CAAA;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,YAAY,EAAE,sBAAsB,EAAE,EACtC,CAAC,EAAE,MAAM,EACT,EACE,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,MAAM,GACP,EAAE,gCAAgC,GAAG,sBAAsB,GAC3D,sBAAsB,EAAE,CA0J1B"}
|
|
@@ -80,7 +80,25 @@ export function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
else if (p === 'dayPeriod') {
|
|
83
|
-
|
|
83
|
+
var f = internalSlots.dayPeriod;
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
var fv = tm[f];
|
|
86
|
+
result.push({ type: p, value: fv });
|
|
87
|
+
}
|
|
88
|
+
else if (p === 'timeZoneName') {
|
|
89
|
+
var f = internalSlots.timeZoneName;
|
|
90
|
+
var fv = void 0;
|
|
91
|
+
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
|
|
92
|
+
var timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
93
|
+
var timeZoneData = timeZoneName[timeZone];
|
|
94
|
+
if (timeZoneData && timeZoneData[f]) {
|
|
95
|
+
fv = timeZoneData[f][+tm.inDST];
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// Fallback to gmtFormat
|
|
99
|
+
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
100
|
+
}
|
|
101
|
+
result.push({ type: p, value: fv });
|
|
84
102
|
}
|
|
85
103
|
else if (DATE_TIME_PROPS.indexOf(p) > -1) {
|
|
86
104
|
var fv = '';
|
|
@@ -118,18 +136,6 @@ export function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
|
118
136
|
if (p === 'era') {
|
|
119
137
|
fv = dataLocaleData[p][f][v];
|
|
120
138
|
}
|
|
121
|
-
else if (p === 'timeZoneName') {
|
|
122
|
-
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
|
|
123
|
-
var timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
124
|
-
var timeZoneData = timeZoneName[timeZone];
|
|
125
|
-
if (timeZoneData && timeZoneData[f]) {
|
|
126
|
-
fv = timeZoneData[f][+tm.inDST];
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
// Fallback to gmtFormat
|
|
130
|
-
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
139
|
else if (p === 'month') {
|
|
134
140
|
fv = dataLocaleData.month[f][v - 1];
|
|
135
141
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { IntlDateTimeFormatInternal, DateTimeFormatLocaleInternalData } from '@formatjs/ecma402-abstract';
|
|
1
|
+
import { IntlDateTimeFormatInternal, DateTimeFormatLocaleInternalData, DateTimeFormat as DateTimeFormat } from '@formatjs/ecma402-abstract';
|
|
2
2
|
/**
|
|
3
3
|
* https://tc39.es/ecma402/#sec-initializedatetimeformat
|
|
4
4
|
* @param dtf DateTimeFormat
|
|
5
5
|
* @param locales locales
|
|
6
6
|
* @param opts options
|
|
7
7
|
*/
|
|
8
|
-
export declare function InitializeDateTimeFormat(dtf:
|
|
9
|
-
getInternalSlots(dtf:
|
|
8
|
+
export declare function InitializeDateTimeFormat(dtf: DateTimeFormat, locales: string | string[] | undefined, opts: Intl.DateTimeFormatOptions | undefined, { getInternalSlots, availableLocales, localeData, getDefaultLocale, getDefaultTimeZone, relevantExtensionKeys, tzData, uppercaseLinks, }: {
|
|
9
|
+
getInternalSlots(dtf: DateTimeFormat): IntlDateTimeFormatInternal;
|
|
10
10
|
availableLocales: Set<string>;
|
|
11
11
|
getDefaultLocale(): string;
|
|
12
12
|
getDefaultTimeZone(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InitializeDateTimeFormat.d.ts","sourceRoot":"","sources":["../../../src/abstract/InitializeDateTimeFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAC1B,gCAAgC,
|
|
1
|
+
{"version":3,"file":"InitializeDateTimeFormat.d.ts","sourceRoot":"","sources":["../../../src/abstract/InitializeDateTimeFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAC1B,gCAAgC,EAOhC,cAAc,IAAI,cAAc,EACjC,MAAM,4BAA4B,CAAA;AAkDnC;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EACtC,IAAI,EAAE,IAAI,CAAC,qBAAqB,GAAG,SAAS,EAC5C,EACE,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,MAAM,EACN,cAAc,GACf,EAAE;IACD,gBAAgB,CAAC,GAAG,EAAE,cAAc,GAAG,0BAA0B,CAAA;IACjE,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC7B,gBAAgB,IAAI,MAAM,CAAA;IAC1B,kBAAkB,IAAI,MAAM,CAAA;IAC5B,qBAAqB,EAAE,MAAM,EAAE,CAAA;IAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gCAAgC,GAAG,SAAS,CAAC,CAAA;IACxE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACvC,GACA,IAAI,CAAC,cAAc,CA2PrB"}
|
|
@@ -102,7 +102,14 @@ export function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
102
102
|
opt.hour = GetOption(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
|
|
103
103
|
opt.minute = GetOption(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
|
|
104
104
|
opt.second = GetOption(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
|
|
105
|
-
opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', [
|
|
105
|
+
opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', [
|
|
106
|
+
'long',
|
|
107
|
+
'short',
|
|
108
|
+
'longOffset',
|
|
109
|
+
'shortOffset',
|
|
110
|
+
'longGeneric',
|
|
111
|
+
'shortGeneric',
|
|
112
|
+
], undefined);
|
|
106
113
|
opt.fractionalSecondDigits = GetNumberOption(options, 'fractionalSecondDigits', 1, 3,
|
|
107
114
|
// @ts-expect-error
|
|
108
115
|
undefined);
|
|
@@ -175,5 +182,5 @@ export function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
175
182
|
}
|
|
176
183
|
internalSlots.pattern = pattern;
|
|
177
184
|
internalSlots.rangePatterns = rangePatterns;
|
|
178
|
-
return dtf;
|
|
185
|
+
return dtf; // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged
|
|
179
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/abstract/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAE,OAAO,EAAC,MAAM,4BAA4B,CAAA;AAE9E,eAAO,MAAM,eAAe,EAAE,KAAK,CACjC,MAAM,IAAI,CAAC,0BAA0B,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/abstract/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAE,OAAO,EAAC,MAAM,4BAA4B,CAAA;AAE9E,eAAO,MAAM,eAAe,EAAE,KAAK,CACjC,MAAM,IAAI,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAahD,CAAA;AAED,eAAO,MAAM,cAAc,MAAM,CAAA;AACjC,eAAO,MAAM,eAAe,KAAK,CAAA;AACjC,eAAO,MAAM,2BAA2B,KAAK,CAAA;AAC7C,eAAO,MAAM,eAAe,IAAI,CAAA;AAChC,eAAO,MAAM,eAAe,IAAI,CAAA;AAChC,eAAO,MAAM,gBAAgB,IAAI,CAAA;AACjC,eAAO,MAAM,gBAAgB,IAAI,CAAA;AACjC,eAAO,MAAM,aAAa,IAAI,CAAA"}
|
|
@@ -4,9 +4,11 @@ export var DATE_TIME_PROPS = [
|
|
|
4
4
|
'year',
|
|
5
5
|
'month',
|
|
6
6
|
'day',
|
|
7
|
+
'dayPeriod',
|
|
7
8
|
'hour',
|
|
8
9
|
'minute',
|
|
9
10
|
'second',
|
|
11
|
+
'fractionalSecondDigits',
|
|
10
12
|
'timeZoneName',
|
|
11
13
|
];
|
|
12
14
|
export var removalPenalty = 120;
|
|
@@ -16,3 +18,4 @@ export var longLessPenalty = 8;
|
|
|
16
18
|
export var longMorePenalty = 6;
|
|
17
19
|
export var shortLessPenalty = 6;
|
|
18
20
|
export var shortMorePenalty = 3;
|
|
21
|
+
export var offsetPenalty = 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-datetimeformat",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Intl.DateTimeFormat polyfill",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/formatjs/formatjs#readme",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@formatjs/ecma402-abstract": "1.
|
|
26
|
-
"@formatjs/intl-localematcher": "0.2.
|
|
25
|
+
"@formatjs/ecma402-abstract": "1.13.0",
|
|
26
|
+
"@formatjs/intl-localematcher": "0.2.31",
|
|
27
27
|
"tslib": "2.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@formatjs/intl-getcanonicallocales": "2.0.4",
|
|
31
|
-
"@formatjs/intl-locale": "3.0.
|
|
31
|
+
"@formatjs/intl-locale": "3.0.7"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/polyfill.iife.js
CHANGED
|
@@ -920,9 +920,11 @@
|
|
|
920
920
|
"year",
|
|
921
921
|
"month",
|
|
922
922
|
"day",
|
|
923
|
+
"dayPeriod",
|
|
923
924
|
"hour",
|
|
924
925
|
"minute",
|
|
925
926
|
"second",
|
|
927
|
+
"fractionalSecondDigits",
|
|
926
928
|
"timeZoneName"
|
|
927
929
|
];
|
|
928
930
|
var removalPenalty = 120;
|
|
@@ -932,6 +934,7 @@
|
|
|
932
934
|
var longMorePenalty = 6;
|
|
933
935
|
var shortLessPenalty = 6;
|
|
934
936
|
var shortMorePenalty = 3;
|
|
937
|
+
var offsetPenalty = 1;
|
|
935
938
|
|
|
936
939
|
// ../../../../../../../../execroot/formatjs/bazel-out/darwin-fastbuild/bin/packages/intl-datetimeformat/lib/src/abstract/ToLocalTime.js
|
|
937
940
|
function getApplicableZoneData(t, timeZone, tzData) {
|
|
@@ -1044,6 +1047,21 @@
|
|
|
1044
1047
|
value: nf3.format(v)
|
|
1045
1048
|
});
|
|
1046
1049
|
} else if (p === "dayPeriod") {
|
|
1050
|
+
var f = internalSlots.dayPeriod;
|
|
1051
|
+
var fv = tm[f];
|
|
1052
|
+
result.push({ type: p, value: fv });
|
|
1053
|
+
} else if (p === "timeZoneName") {
|
|
1054
|
+
var f = internalSlots.timeZoneName;
|
|
1055
|
+
var fv = void 0;
|
|
1056
|
+
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
|
|
1057
|
+
var timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
1058
|
+
var timeZoneData = timeZoneName[timeZone];
|
|
1059
|
+
if (timeZoneData && timeZoneData[f]) {
|
|
1060
|
+
fv = timeZoneData[f][+tm.inDST];
|
|
1061
|
+
} else {
|
|
1062
|
+
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
1063
|
+
}
|
|
1064
|
+
result.push({ type: p, value: fv });
|
|
1047
1065
|
} else if (DATE_TIME_PROPS.indexOf(p) > -1) {
|
|
1048
1066
|
var fv = "";
|
|
1049
1067
|
var f = internalSlots[p];
|
|
@@ -1076,15 +1094,6 @@
|
|
|
1076
1094
|
} else if (f === "narrow" || f === "short" || f === "long") {
|
|
1077
1095
|
if (p === "era") {
|
|
1078
1096
|
fv = dataLocaleData[p][f][v];
|
|
1079
|
-
} else if (p === "timeZoneName") {
|
|
1080
|
-
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
|
|
1081
|
-
var timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
1082
|
-
var timeZoneData = timeZoneName[timeZone];
|
|
1083
|
-
if (timeZoneData && timeZoneData[f]) {
|
|
1084
|
-
fv = timeZoneData[f][+tm.inDST];
|
|
1085
|
-
} else {
|
|
1086
|
-
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
1087
|
-
}
|
|
1088
1097
|
} else if (p === "month") {
|
|
1089
1098
|
fv = dataLocaleData.month[f][v - 1];
|
|
1090
1099
|
} else {
|
|
@@ -1165,6 +1174,38 @@
|
|
|
1165
1174
|
score -= additionPenalty;
|
|
1166
1175
|
} else if (optionsProp !== void 0 && formatProp === void 0) {
|
|
1167
1176
|
score -= removalPenalty;
|
|
1177
|
+
} else if (prop === "timeZoneName") {
|
|
1178
|
+
if (optionsProp === "short" || optionsProp === "shortGeneric") {
|
|
1179
|
+
if (formatProp === "shortOffset") {
|
|
1180
|
+
score -= offsetPenalty;
|
|
1181
|
+
} else if (formatProp === "longOffset") {
|
|
1182
|
+
score -= offsetPenalty + shortMorePenalty;
|
|
1183
|
+
} else if (optionsProp === "short" && formatProp === "long") {
|
|
1184
|
+
score -= shortMorePenalty;
|
|
1185
|
+
} else if (optionsProp === "shortGeneric" && formatProp === "longGeneric") {
|
|
1186
|
+
score -= shortMorePenalty;
|
|
1187
|
+
} else if (optionsProp !== formatProp) {
|
|
1188
|
+
score -= removalPenalty;
|
|
1189
|
+
}
|
|
1190
|
+
} else if (optionsProp === "shortOffset" && formatProp === "longOffset") {
|
|
1191
|
+
score -= shortMorePenalty;
|
|
1192
|
+
} else if (optionsProp === "long" || optionsProp === "longGeneric") {
|
|
1193
|
+
if (formatProp === "longOffset") {
|
|
1194
|
+
score -= offsetPenalty;
|
|
1195
|
+
} else if (formatProp === "shortOffset") {
|
|
1196
|
+
score -= offsetPenalty + longLessPenalty;
|
|
1197
|
+
} else if (optionsProp === "long" && formatProp === "short") {
|
|
1198
|
+
score -= longLessPenalty;
|
|
1199
|
+
} else if (optionsProp === "longGeneric" && formatProp === "shortGeneric") {
|
|
1200
|
+
score -= longLessPenalty;
|
|
1201
|
+
} else if (optionsProp !== formatProp) {
|
|
1202
|
+
score -= removalPenalty;
|
|
1203
|
+
}
|
|
1204
|
+
} else if (optionsProp === "longOffset" && formatProp === "shortOffset") {
|
|
1205
|
+
score -= longLessPenalty;
|
|
1206
|
+
} else if (optionsProp !== formatProp) {
|
|
1207
|
+
score -= removalPenalty;
|
|
1208
|
+
}
|
|
1168
1209
|
} else if (optionsProp !== formatProp) {
|
|
1169
1210
|
var values = void 0;
|
|
1170
1211
|
if (prop === "fractionalSecondDigits") {
|
|
@@ -1711,7 +1752,14 @@
|
|
|
1711
1752
|
opt.hour = GetOption(options, "hour", "string", ["2-digit", "numeric"], void 0);
|
|
1712
1753
|
opt.minute = GetOption(options, "minute", "string", ["2-digit", "numeric"], void 0);
|
|
1713
1754
|
opt.second = GetOption(options, "second", "string", ["2-digit", "numeric"], void 0);
|
|
1714
|
-
opt.timeZoneName = GetOption(options, "timeZoneName", "string", [
|
|
1755
|
+
opt.timeZoneName = GetOption(options, "timeZoneName", "string", [
|
|
1756
|
+
"long",
|
|
1757
|
+
"short",
|
|
1758
|
+
"longOffset",
|
|
1759
|
+
"shortOffset",
|
|
1760
|
+
"longGeneric",
|
|
1761
|
+
"shortGeneric"
|
|
1762
|
+
], void 0);
|
|
1715
1763
|
opt.fractionalSecondDigits = GetNumberOption(
|
|
1716
1764
|
options,
|
|
1717
1765
|
"fractionalSecondDigits",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicFormatMatcher.d.ts","sourceRoot":"","sources":["BasicFormatMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAY,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"BasicFormatMatcher.d.ts","sourceRoot":"","sources":["BasicFormatMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAY,MAAM,4BAA4B,CAAA;AAY7D;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,IAAI,CAAC,qBAAqB,EACnC,OAAO,EAAE,OAAO,EAAE,GACjB,OAAO,CAuFT"}
|
|
@@ -26,6 +26,55 @@ function BasicFormatMatcher(options, formats) {
|
|
|
26
26
|
else if (optionsProp !== undefined && formatProp === undefined) {
|
|
27
27
|
score -= utils_1.removalPenalty;
|
|
28
28
|
}
|
|
29
|
+
else if (prop === 'timeZoneName') {
|
|
30
|
+
if (optionsProp === 'short' || optionsProp === 'shortGeneric') {
|
|
31
|
+
if (formatProp === 'shortOffset') {
|
|
32
|
+
score -= utils_1.offsetPenalty;
|
|
33
|
+
}
|
|
34
|
+
else if (formatProp === 'longOffset') {
|
|
35
|
+
score -= utils_1.offsetPenalty + utils_1.shortMorePenalty;
|
|
36
|
+
}
|
|
37
|
+
else if (optionsProp === 'short' && formatProp === 'long') {
|
|
38
|
+
score -= utils_1.shortMorePenalty;
|
|
39
|
+
}
|
|
40
|
+
else if (optionsProp === 'shortGeneric' &&
|
|
41
|
+
formatProp === 'longGeneric') {
|
|
42
|
+
score -= utils_1.shortMorePenalty;
|
|
43
|
+
}
|
|
44
|
+
else if (optionsProp !== formatProp) {
|
|
45
|
+
score -= utils_1.removalPenalty;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (optionsProp === 'shortOffset' &&
|
|
49
|
+
formatProp === 'longOffset') {
|
|
50
|
+
score -= utils_1.shortMorePenalty;
|
|
51
|
+
}
|
|
52
|
+
else if (optionsProp === 'long' || optionsProp === 'longGeneric') {
|
|
53
|
+
if (formatProp === 'longOffset') {
|
|
54
|
+
score -= utils_1.offsetPenalty;
|
|
55
|
+
}
|
|
56
|
+
else if (formatProp === 'shortOffset') {
|
|
57
|
+
score -= utils_1.offsetPenalty + utils_1.longLessPenalty;
|
|
58
|
+
}
|
|
59
|
+
else if (optionsProp === 'long' && formatProp === 'short') {
|
|
60
|
+
score -= utils_1.longLessPenalty;
|
|
61
|
+
}
|
|
62
|
+
else if (optionsProp === 'longGeneric' &&
|
|
63
|
+
formatProp === 'shortGeneric') {
|
|
64
|
+
score -= utils_1.longLessPenalty;
|
|
65
|
+
}
|
|
66
|
+
else if (optionsProp !== formatProp) {
|
|
67
|
+
score -= utils_1.removalPenalty;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (optionsProp === 'longOffset' &&
|
|
71
|
+
formatProp === 'shortOffset') {
|
|
72
|
+
score -= utils_1.longLessPenalty;
|
|
73
|
+
}
|
|
74
|
+
else if (optionsProp !== formatProp) {
|
|
75
|
+
score -= utils_1.removalPenalty;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
29
78
|
else if (optionsProp !== formatProp) {
|
|
30
79
|
var values = void 0;
|
|
31
80
|
if (prop === 'fractionalSecondDigits') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatDateTimePattern.d.ts","sourceRoot":"","sources":["FormatDateTimePattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EAEvB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAc,sBAAsB,EAAC,MAAM,eAAe,CAAA;AAsCjE,MAAM,WAAW,gCAAgC;IAC/C,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,GAAG,0BAA0B,CAAA;IACtE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAA;IAC5D,kBAAkB,IAAI,MAAM,CAAA;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,YAAY,EAAE,sBAAsB,EAAE,EACtC,CAAC,EAAE,MAAM,EACT,EACE,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,MAAM,GACP,EAAE,gCAAgC,GAAG,sBAAsB,GAC3D,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"FormatDateTimePattern.d.ts","sourceRoot":"","sources":["FormatDateTimePattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EAEvB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAc,sBAAsB,EAAC,MAAM,eAAe,CAAA;AAsCjE,MAAM,WAAW,gCAAgC;IAC/C,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,GAAG,0BAA0B,CAAA;IACtE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAA;IAC5D,kBAAkB,IAAI,MAAM,CAAA;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,YAAY,EAAE,sBAAsB,EAAE,EACtC,CAAC,EAAE,MAAM,EACT,EACE,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,MAAM,GACP,EAAE,gCAAgC,GAAG,sBAAsB,GAC3D,sBAAsB,EAAE,CA0J1B"}
|
|
@@ -83,7 +83,25 @@ function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
else if (p === 'dayPeriod') {
|
|
86
|
-
|
|
86
|
+
var f = internalSlots.dayPeriod;
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
var fv = tm[f];
|
|
89
|
+
result.push({ type: p, value: fv });
|
|
90
|
+
}
|
|
91
|
+
else if (p === 'timeZoneName') {
|
|
92
|
+
var f = internalSlots.timeZoneName;
|
|
93
|
+
var fv = void 0;
|
|
94
|
+
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
|
|
95
|
+
var timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
96
|
+
var timeZoneData = timeZoneName[timeZone];
|
|
97
|
+
if (timeZoneData && timeZoneData[f]) {
|
|
98
|
+
fv = timeZoneData[f][+tm.inDST];
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// Fallback to gmtFormat
|
|
102
|
+
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
103
|
+
}
|
|
104
|
+
result.push({ type: p, value: fv });
|
|
87
105
|
}
|
|
88
106
|
else if (utils_1.DATE_TIME_PROPS.indexOf(p) > -1) {
|
|
89
107
|
var fv = '';
|
|
@@ -121,18 +139,6 @@ function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
|
121
139
|
if (p === 'era') {
|
|
122
140
|
fv = dataLocaleData[p][f][v];
|
|
123
141
|
}
|
|
124
|
-
else if (p === 'timeZoneName') {
|
|
125
|
-
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
|
|
126
|
-
var timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
127
|
-
var timeZoneData = timeZoneName[timeZone];
|
|
128
|
-
if (timeZoneData && timeZoneData[f]) {
|
|
129
|
-
fv = timeZoneData[f][+tm.inDST];
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
// Fallback to gmtFormat
|
|
133
|
-
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
142
|
else if (p === 'month') {
|
|
137
143
|
fv = dataLocaleData.month[f][v - 1];
|
|
138
144
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { IntlDateTimeFormatInternal, DateTimeFormatLocaleInternalData } from '@formatjs/ecma402-abstract';
|
|
1
|
+
import { IntlDateTimeFormatInternal, DateTimeFormatLocaleInternalData, DateTimeFormat as DateTimeFormat } from '@formatjs/ecma402-abstract';
|
|
2
2
|
/**
|
|
3
3
|
* https://tc39.es/ecma402/#sec-initializedatetimeformat
|
|
4
4
|
* @param dtf DateTimeFormat
|
|
5
5
|
* @param locales locales
|
|
6
6
|
* @param opts options
|
|
7
7
|
*/
|
|
8
|
-
export declare function InitializeDateTimeFormat(dtf:
|
|
9
|
-
getInternalSlots(dtf:
|
|
8
|
+
export declare function InitializeDateTimeFormat(dtf: DateTimeFormat, locales: string | string[] | undefined, opts: Intl.DateTimeFormatOptions | undefined, { getInternalSlots, availableLocales, localeData, getDefaultLocale, getDefaultTimeZone, relevantExtensionKeys, tzData, uppercaseLinks, }: {
|
|
9
|
+
getInternalSlots(dtf: DateTimeFormat): IntlDateTimeFormatInternal;
|
|
10
10
|
availableLocales: Set<string>;
|
|
11
11
|
getDefaultLocale(): string;
|
|
12
12
|
getDefaultTimeZone(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InitializeDateTimeFormat.d.ts","sourceRoot":"","sources":["InitializeDateTimeFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAC1B,gCAAgC,
|
|
1
|
+
{"version":3,"file":"InitializeDateTimeFormat.d.ts","sourceRoot":"","sources":["InitializeDateTimeFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAC1B,gCAAgC,EAOhC,cAAc,IAAI,cAAc,EACjC,MAAM,4BAA4B,CAAA;AAkDnC;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EACtC,IAAI,EAAE,IAAI,CAAC,qBAAqB,GAAG,SAAS,EAC5C,EACE,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,MAAM,EACN,cAAc,GACf,EAAE;IACD,gBAAgB,CAAC,GAAG,EAAE,cAAc,GAAG,0BAA0B,CAAA;IACjE,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC7B,gBAAgB,IAAI,MAAM,CAAA;IAC1B,kBAAkB,IAAI,MAAM,CAAA;IAC5B,qBAAqB,EAAE,MAAM,EAAE,CAAA;IAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gCAAgC,GAAG,SAAS,CAAC,CAAA;IACxE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACvC,GACA,IAAI,CAAC,cAAc,CA2PrB"}
|
|
@@ -105,7 +105,14 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
105
105
|
opt.hour = (0, ecma402_abstract_1.GetOption)(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
|
|
106
106
|
opt.minute = (0, ecma402_abstract_1.GetOption)(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
|
|
107
107
|
opt.second = (0, ecma402_abstract_1.GetOption)(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
|
|
108
|
-
opt.timeZoneName = (0, ecma402_abstract_1.GetOption)(options, 'timeZoneName', 'string', [
|
|
108
|
+
opt.timeZoneName = (0, ecma402_abstract_1.GetOption)(options, 'timeZoneName', 'string', [
|
|
109
|
+
'long',
|
|
110
|
+
'short',
|
|
111
|
+
'longOffset',
|
|
112
|
+
'shortOffset',
|
|
113
|
+
'longGeneric',
|
|
114
|
+
'shortGeneric',
|
|
115
|
+
], undefined);
|
|
109
116
|
opt.fractionalSecondDigits = (0, ecma402_abstract_1.GetNumberOption)(options, 'fractionalSecondDigits', 1, 3,
|
|
110
117
|
// @ts-expect-error
|
|
111
118
|
undefined);
|
|
@@ -178,6 +185,6 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
178
185
|
}
|
|
179
186
|
internalSlots.pattern = pattern;
|
|
180
187
|
internalSlots.rangePatterns = rangePatterns;
|
|
181
|
-
return dtf;
|
|
188
|
+
return dtf; // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged
|
|
182
189
|
}
|
|
183
190
|
exports.InitializeDateTimeFormat = InitializeDateTimeFormat;
|
package/src/abstract/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAE,OAAO,EAAC,MAAM,4BAA4B,CAAA;AAE9E,eAAO,MAAM,eAAe,EAAE,KAAK,CACjC,MAAM,IAAI,CAAC,0BAA0B,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAE,OAAO,EAAC,MAAM,4BAA4B,CAAA;AAE9E,eAAO,MAAM,eAAe,EAAE,KAAK,CACjC,MAAM,IAAI,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAahD,CAAA;AAED,eAAO,MAAM,cAAc,MAAM,CAAA;AACjC,eAAO,MAAM,eAAe,KAAK,CAAA;AACjC,eAAO,MAAM,2BAA2B,KAAK,CAAA;AAC7C,eAAO,MAAM,eAAe,IAAI,CAAA;AAChC,eAAO,MAAM,eAAe,IAAI,CAAA;AAChC,eAAO,MAAM,gBAAgB,IAAI,CAAA;AACjC,eAAO,MAAM,gBAAgB,IAAI,CAAA;AACjC,eAAO,MAAM,aAAa,IAAI,CAAA"}
|
package/src/abstract/utils.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shortMorePenalty = exports.shortLessPenalty = exports.longMorePenalty = exports.longLessPenalty = exports.differentNumericTypePenalty = exports.additionPenalty = exports.removalPenalty = exports.DATE_TIME_PROPS = void 0;
|
|
3
|
+
exports.offsetPenalty = exports.shortMorePenalty = exports.shortLessPenalty = exports.longMorePenalty = exports.longLessPenalty = exports.differentNumericTypePenalty = exports.additionPenalty = exports.removalPenalty = exports.DATE_TIME_PROPS = void 0;
|
|
4
4
|
exports.DATE_TIME_PROPS = [
|
|
5
5
|
'weekday',
|
|
6
6
|
'era',
|
|
7
7
|
'year',
|
|
8
8
|
'month',
|
|
9
9
|
'day',
|
|
10
|
+
'dayPeriod',
|
|
10
11
|
'hour',
|
|
11
12
|
'minute',
|
|
12
13
|
'second',
|
|
14
|
+
'fractionalSecondDigits',
|
|
13
15
|
'timeZoneName',
|
|
14
16
|
];
|
|
15
17
|
exports.removalPenalty = 120;
|
|
@@ -19,3 +21,4 @@ exports.longLessPenalty = 8;
|
|
|
19
21
|
exports.longMorePenalty = 6;
|
|
20
22
|
exports.shortLessPenalty = 6;
|
|
21
23
|
exports.shortMorePenalty = 3;
|
|
24
|
+
exports.offsetPenalty = 1;
|