@formatjs/intl-datetimeformat 6.11.2 → 6.12.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/LICENSE.md +1 -1
- package/lib/index.js +1 -4
- package/lib/polyfill-force.js +10 -12
- package/lib/polyfill.js +12 -14
- package/lib/should-polyfill.js +4 -8
- package/lib/src/abstract/BasicFormatMatcher.js +26 -30
- package/lib/src/abstract/BestFitFormatMatcher.js +19 -24
- package/lib/src/abstract/DateTimeStyleFormat.js +5 -9
- package/lib/src/abstract/FormatDateTime.js +3 -7
- package/lib/src/abstract/FormatDateTimePattern.js +7 -11
- package/lib/src/abstract/FormatDateTimeRange.js +3 -7
- package/lib/src/abstract/FormatDateTimeRangeToParts.js +3 -7
- package/lib/src/abstract/FormatDateTimeToParts.js +5 -9
- package/lib/src/abstract/InitializeDateTimeFormat.d.ts +1 -1
- package/lib/src/abstract/InitializeDateTimeFormat.js +37 -43
- package/lib/src/abstract/PartitionDateTimePattern.js +5 -9
- package/lib/src/abstract/PartitionDateTimeRangePattern.js +16 -20
- package/lib/src/abstract/ToDateTimeOptions.js +3 -7
- package/lib/src/abstract/ToLocalTime.js +12 -16
- package/lib/src/abstract/skeleton.js +15 -22
- package/lib/src/abstract/utils.js +9 -12
- package/lib/src/core.js +106 -109
- package/lib/src/data/all-tz.js +1 -3
- package/lib/src/data/links.js +1 -3
- package/lib/src/get_internal_slots.js +1 -4
- package/lib/src/packer.js +5 -10
- package/lib/src/to_locale_string.js +8 -14
- package/lib/src/types.js +1 -2
- package/lib/supported-locales.generated.js +1 -4
- package/lib/test262-main.js +3 -6
- package/package.json +4 -4
- package/polyfill.iife.js +6302 -9407
- package/src/abstract/InitializeDateTimeFormat.d.ts +1 -1
- package/src/abstract/InitializeDateTimeFormat.js +3 -5
- package/src/abstract/skeleton.js +1 -1
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var DateTimeStyleFormat_1 = require("./DateTimeStyleFormat");
|
|
9
|
-
var ToDateTimeOptions_1 = require("./ToDateTimeOptions");
|
|
10
|
-
var intl_localematcher_1 = require("@formatjs/intl-localematcher");
|
|
1
|
+
import { CanonicalizeLocaleList, CanonicalizeTimeZoneName, GetNumberOption, GetOption, IsValidTimeZoneName, invariant, } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import { ResolveLocale } from '@formatjs/intl-localematcher';
|
|
3
|
+
import { BasicFormatMatcher } from './BasicFormatMatcher';
|
|
4
|
+
import { BestFitFormatMatcher } from './BestFitFormatMatcher';
|
|
5
|
+
import { DateTimeStyleFormat } from './DateTimeStyleFormat';
|
|
6
|
+
import { ToDateTimeOptions } from './ToDateTimeOptions';
|
|
7
|
+
import { DATE_TIME_PROPS } from './utils';
|
|
11
8
|
function isTimeRelated(opt) {
|
|
12
9
|
for (var _i = 0, _a = ['hour', 'minute', 'second']; _i < _a.length; _i++) {
|
|
13
10
|
var prop = _a[_i];
|
|
@@ -32,7 +29,7 @@ function resolveHourCycle(hc, hcDefault, hour12) {
|
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
else {
|
|
35
|
-
|
|
32
|
+
invariant(!hour12, 'hour12 must not be set');
|
|
36
33
|
if (hcDefault === 'h11' || hcDefault === 'h23') {
|
|
37
34
|
hc = 'h23';
|
|
38
35
|
}
|
|
@@ -50,33 +47,33 @@ var TYPE_REGEX = /^[a-z0-9]{3,8}$/i;
|
|
|
50
47
|
* @param locales locales
|
|
51
48
|
* @param opts options
|
|
52
49
|
*/
|
|
53
|
-
function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
50
|
+
export function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
54
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;
|
|
55
52
|
// @ts-ignore
|
|
56
|
-
var requestedLocales =
|
|
57
|
-
var options =
|
|
53
|
+
var requestedLocales = CanonicalizeLocaleList(locales);
|
|
54
|
+
var options = ToDateTimeOptions(opts, 'any', 'date');
|
|
58
55
|
var opt = Object.create(null);
|
|
59
|
-
var matcher =
|
|
56
|
+
var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
|
|
60
57
|
opt.localeMatcher = matcher;
|
|
61
|
-
var calendar =
|
|
58
|
+
var calendar = GetOption(options, 'calendar', 'string', undefined, undefined);
|
|
62
59
|
if (calendar !== undefined && !TYPE_REGEX.test(calendar)) {
|
|
63
60
|
throw new RangeError('Malformed calendar');
|
|
64
61
|
}
|
|
65
62
|
var internalSlots = getInternalSlots(dtf);
|
|
66
63
|
opt.ca = calendar;
|
|
67
|
-
var numberingSystem =
|
|
64
|
+
var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
|
|
68
65
|
if (numberingSystem !== undefined && !TYPE_REGEX.test(numberingSystem)) {
|
|
69
66
|
throw new RangeError('Malformed numbering system');
|
|
70
67
|
}
|
|
71
68
|
opt.nu = numberingSystem;
|
|
72
|
-
var hour12 =
|
|
73
|
-
var hourCycle =
|
|
69
|
+
var hour12 = GetOption(options, 'hour12', 'boolean', undefined, undefined);
|
|
70
|
+
var hourCycle = GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
|
|
74
71
|
if (hour12 !== undefined) {
|
|
75
72
|
// @ts-ignore
|
|
76
73
|
hourCycle = null;
|
|
77
74
|
}
|
|
78
75
|
opt.hc = hourCycle;
|
|
79
|
-
var r =
|
|
76
|
+
var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
|
|
80
77
|
internalSlots.locale = r.locale;
|
|
81
78
|
calendar = r.ca;
|
|
82
79
|
internalSlots.calendar = calendar;
|
|
@@ -87,25 +84,25 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
87
84
|
var timeZone = options.timeZone;
|
|
88
85
|
if (timeZone !== undefined) {
|
|
89
86
|
timeZone = String(timeZone);
|
|
90
|
-
if (!
|
|
87
|
+
if (!IsValidTimeZoneName(timeZone, { tzData: tzData, uppercaseLinks: uppercaseLinks })) {
|
|
91
88
|
throw new RangeError('Invalid timeZoneName');
|
|
92
89
|
}
|
|
93
|
-
timeZone =
|
|
90
|
+
timeZone = CanonicalizeTimeZoneName(timeZone, { tzData: tzData, uppercaseLinks: uppercaseLinks });
|
|
94
91
|
}
|
|
95
92
|
else {
|
|
96
93
|
timeZone = getDefaultTimeZone();
|
|
97
94
|
}
|
|
98
95
|
internalSlots.timeZone = timeZone;
|
|
99
96
|
opt = Object.create(null);
|
|
100
|
-
opt.weekday =
|
|
101
|
-
opt.era =
|
|
102
|
-
opt.year =
|
|
103
|
-
opt.month =
|
|
104
|
-
opt.day =
|
|
105
|
-
opt.hour =
|
|
106
|
-
opt.minute =
|
|
107
|
-
opt.second =
|
|
108
|
-
opt.timeZoneName =
|
|
97
|
+
opt.weekday = GetOption(options, 'weekday', 'string', ['narrow', 'short', 'long'], undefined);
|
|
98
|
+
opt.era = GetOption(options, 'era', 'string', ['narrow', 'short', 'long'], undefined);
|
|
99
|
+
opt.year = GetOption(options, 'year', 'string', ['2-digit', 'numeric'], undefined);
|
|
100
|
+
opt.month = GetOption(options, 'month', 'string', ['2-digit', 'numeric', 'narrow', 'short', 'long'], undefined);
|
|
101
|
+
opt.day = GetOption(options, 'day', 'string', ['2-digit', 'numeric'], undefined);
|
|
102
|
+
opt.hour = GetOption(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
|
|
103
|
+
opt.minute = GetOption(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
|
|
104
|
+
opt.second = GetOption(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
|
|
105
|
+
opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', [
|
|
109
106
|
'long',
|
|
110
107
|
'short',
|
|
111
108
|
'longOffset',
|
|
@@ -113,25 +110,23 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
113
110
|
'longGeneric',
|
|
114
111
|
'shortGeneric',
|
|
115
112
|
], undefined);
|
|
116
|
-
opt.fractionalSecondDigits =
|
|
117
|
-
// @ts-expect-error
|
|
118
|
-
undefined);
|
|
113
|
+
opt.fractionalSecondDigits = GetNumberOption(options, 'fractionalSecondDigits', 1, 3, undefined);
|
|
119
114
|
var dataLocaleData = localeData[dataLocale];
|
|
120
|
-
|
|
115
|
+
invariant(!!dataLocaleData, "Missing locale data for ".concat(dataLocale));
|
|
121
116
|
var formats = dataLocaleData.formats[calendar];
|
|
122
117
|
// UNSPECCED: IMPLEMENTATION DETAILS
|
|
123
118
|
if (!formats) {
|
|
124
119
|
throw new RangeError("Calendar \"".concat(calendar, "\" is not supported. Try setting \"calendar\" to 1 of the following: ").concat(Object.keys(dataLocaleData.formats).join(', ')));
|
|
125
120
|
}
|
|
126
|
-
var formatMatcher =
|
|
127
|
-
var dateStyle =
|
|
121
|
+
var formatMatcher = GetOption(options, 'formatMatcher', 'string', ['basic', 'best fit'], 'best fit');
|
|
122
|
+
var dateStyle = GetOption(options, 'dateStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
|
|
128
123
|
internalSlots.dateStyle = dateStyle;
|
|
129
|
-
var timeStyle =
|
|
124
|
+
var timeStyle = GetOption(options, 'timeStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
|
|
130
125
|
internalSlots.timeStyle = timeStyle;
|
|
131
126
|
var bestFormat;
|
|
132
127
|
if (dateStyle === undefined && timeStyle === undefined) {
|
|
133
128
|
if (formatMatcher === 'basic') {
|
|
134
|
-
bestFormat =
|
|
129
|
+
bestFormat = BasicFormatMatcher(opt, formats);
|
|
135
130
|
}
|
|
136
131
|
else {
|
|
137
132
|
// IMPL DETAILS START
|
|
@@ -140,18 +135,18 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
140
135
|
opt.hour12 = hc === 'h11' || hc === 'h12';
|
|
141
136
|
}
|
|
142
137
|
// IMPL DETAILS END
|
|
143
|
-
bestFormat =
|
|
138
|
+
bestFormat = BestFitFormatMatcher(opt, formats);
|
|
144
139
|
}
|
|
145
140
|
}
|
|
146
141
|
else {
|
|
147
|
-
for (var _i = 0, DATE_TIME_PROPS_1 =
|
|
142
|
+
for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
|
|
148
143
|
var prop = DATE_TIME_PROPS_1[_i];
|
|
149
144
|
var p = opt[prop];
|
|
150
145
|
if (p !== undefined) {
|
|
151
146
|
throw new TypeError("Intl.DateTimeFormat can't set option ".concat(prop, " when ").concat(dateStyle ? 'dateStyle' : 'timeStyle', " is used"));
|
|
152
147
|
}
|
|
153
148
|
}
|
|
154
|
-
bestFormat =
|
|
149
|
+
bestFormat = DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData);
|
|
155
150
|
}
|
|
156
151
|
// IMPL DETAIL START
|
|
157
152
|
// For debugging
|
|
@@ -187,4 +182,3 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
187
182
|
internalSlots.rangePatterns = rangePatterns;
|
|
188
183
|
return dtf; // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged
|
|
189
184
|
}
|
|
190
|
-
exports.InitializeDateTimeFormat = InitializeDateTimeFormat;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.PartitionDateTimePattern = void 0;
|
|
4
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
5
|
-
var FormatDateTimePattern_1 = require("./FormatDateTimePattern");
|
|
1
|
+
import { PartitionPattern, TimeClip, } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import { FormatDateTimePattern, } from './FormatDateTimePattern';
|
|
6
3
|
/**
|
|
7
4
|
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
8
5
|
* @param dtf
|
|
9
6
|
* @param x
|
|
10
7
|
*/
|
|
11
|
-
function PartitionDateTimePattern(dtf, x, implDetails) {
|
|
12
|
-
x =
|
|
8
|
+
export function PartitionDateTimePattern(dtf, x, implDetails) {
|
|
9
|
+
x = TimeClip(x);
|
|
13
10
|
if (isNaN(x)) {
|
|
14
11
|
throw new RangeError('invalid time');
|
|
15
12
|
}
|
|
@@ -18,6 +15,5 @@ function PartitionDateTimePattern(dtf, x, implDetails) {
|
|
|
18
15
|
var internalSlots = getInternalSlots(dtf);
|
|
19
16
|
/** IMPL END */
|
|
20
17
|
var pattern = internalSlots.pattern;
|
|
21
|
-
return
|
|
18
|
+
return FormatDateTimePattern(dtf, PartitionPattern(pattern), x, implDetails);
|
|
22
19
|
}
|
|
23
|
-
exports.PartitionDateTimePattern = PartitionDateTimePattern;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
5
|
-
var ToLocalTime_1 = require("./ToLocalTime");
|
|
6
|
-
var FormatDateTimePattern_1 = require("./FormatDateTimePattern");
|
|
1
|
+
import { RangePatternType, PartitionPattern, SameValue, TimeClip, } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import { ToLocalTime } from './ToLocalTime';
|
|
3
|
+
import { FormatDateTimePattern, } from './FormatDateTimePattern';
|
|
7
4
|
var TABLE_2_FIELDS = [
|
|
8
5
|
'era',
|
|
9
6
|
'year',
|
|
@@ -16,12 +13,12 @@ var TABLE_2_FIELDS = [
|
|
|
16
13
|
'second',
|
|
17
14
|
'fractionalSecondDigits',
|
|
18
15
|
];
|
|
19
|
-
function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
|
|
20
|
-
x =
|
|
16
|
+
export function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
|
|
17
|
+
x = TimeClip(x);
|
|
21
18
|
if (isNaN(x)) {
|
|
22
19
|
throw new RangeError('Invalid start time');
|
|
23
20
|
}
|
|
24
|
-
y =
|
|
21
|
+
y = TimeClip(y);
|
|
25
22
|
if (isNaN(y)) {
|
|
26
23
|
throw new RangeError('Invalid end time');
|
|
27
24
|
}
|
|
@@ -29,10 +26,10 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
|
|
|
29
26
|
var getInternalSlots = implDetails.getInternalSlots, tzData = implDetails.tzData;
|
|
30
27
|
var internalSlots = getInternalSlots(dtf);
|
|
31
28
|
/** IMPL END */
|
|
32
|
-
var tm1 =
|
|
29
|
+
var tm1 = ToLocalTime(x,
|
|
33
30
|
// @ts-ignore
|
|
34
31
|
internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
|
|
35
|
-
var tm2 =
|
|
32
|
+
var tm2 = ToLocalTime(y,
|
|
36
33
|
// @ts-ignore
|
|
37
34
|
internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
|
|
38
35
|
var pattern = internalSlots.pattern, rangePatterns = internalSlots.rangePatterns;
|
|
@@ -65,14 +62,14 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
|
|
|
65
62
|
}
|
|
66
63
|
var v1 = Math.floor(tm1.millisecond * Math.pow(10, (fractionalSecondDigits - 3)));
|
|
67
64
|
var v2 = Math.floor(tm2.millisecond * Math.pow(10, (fractionalSecondDigits - 3)));
|
|
68
|
-
if (!
|
|
65
|
+
if (!SameValue(v1, v2)) {
|
|
69
66
|
dateFieldsPracticallyEqual = false;
|
|
70
67
|
}
|
|
71
68
|
}
|
|
72
69
|
else {
|
|
73
70
|
var v1 = tm1[fieldName];
|
|
74
71
|
var v2 = tm2[fieldName];
|
|
75
|
-
if (!
|
|
72
|
+
if (!SameValue(v1, v2)) {
|
|
76
73
|
dateFieldsPracticallyEqual = false;
|
|
77
74
|
}
|
|
78
75
|
}
|
|
@@ -80,10 +77,10 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
|
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
if (dateFieldsPracticallyEqual) {
|
|
83
|
-
var result_2 =
|
|
80
|
+
var result_2 = FormatDateTimePattern(dtf, PartitionPattern(pattern), x, implDetails);
|
|
84
81
|
for (var _a = 0, result_1 = result_2; _a < result_1.length; _a++) {
|
|
85
82
|
var r = result_1[_a];
|
|
86
|
-
r.source =
|
|
83
|
+
r.source = RangePatternType.shared;
|
|
87
84
|
}
|
|
88
85
|
return result_2;
|
|
89
86
|
}
|
|
@@ -103,15 +100,15 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
|
|
|
103
100
|
var rangePatternPart = _e[_d];
|
|
104
101
|
var source = rangePatternPart.source, pattern_1 = rangePatternPart.pattern;
|
|
105
102
|
var z = void 0;
|
|
106
|
-
if (source ===
|
|
107
|
-
source ===
|
|
103
|
+
if (source === RangePatternType.startRange ||
|
|
104
|
+
source === RangePatternType.shared) {
|
|
108
105
|
z = x;
|
|
109
106
|
}
|
|
110
107
|
else {
|
|
111
108
|
z = y;
|
|
112
109
|
}
|
|
113
|
-
var patternParts =
|
|
114
|
-
var partResult =
|
|
110
|
+
var patternParts = PartitionPattern(pattern_1);
|
|
111
|
+
var partResult = FormatDateTimePattern(dtf, patternParts, z, implDetails);
|
|
115
112
|
for (var _f = 0, partResult_1 = partResult; _f < partResult_1.length; _f++) {
|
|
116
113
|
var r = partResult_1[_f];
|
|
117
114
|
r.source = source;
|
|
@@ -120,4 +117,3 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
|
|
|
120
117
|
}
|
|
121
118
|
return result;
|
|
122
119
|
}
|
|
123
|
-
exports.PartitionDateTimeRangePattern = PartitionDateTimeRangePattern;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ToDateTimeOptions = void 0;
|
|
4
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
1
|
+
import { ToObject } from '@formatjs/ecma402-abstract';
|
|
5
2
|
/**
|
|
6
3
|
* https://tc39.es/ecma402/#sec-todatetimeoptions
|
|
7
4
|
* @param options
|
|
8
5
|
* @param required
|
|
9
6
|
* @param defaults
|
|
10
7
|
*/
|
|
11
|
-
function ToDateTimeOptions(options, required, defaults) {
|
|
8
|
+
export function ToDateTimeOptions(options, required, defaults) {
|
|
12
9
|
if (options === undefined) {
|
|
13
10
|
options = null;
|
|
14
11
|
}
|
|
15
12
|
else {
|
|
16
|
-
options =
|
|
13
|
+
options = ToObject(options);
|
|
17
14
|
}
|
|
18
15
|
options = Object.create(options);
|
|
19
16
|
var needDefaults = true;
|
|
@@ -64,4 +61,3 @@ function ToDateTimeOptions(options, required, defaults) {
|
|
|
64
61
|
}
|
|
65
62
|
return options;
|
|
66
63
|
}
|
|
67
|
-
exports.ToDateTimeOptions = ToDateTimeOptions;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ToLocalTime = void 0;
|
|
4
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
1
|
+
import { Type, YearFromTime, WeekDay, MonthFromTime, DateFromTime, HourFromTime, MinFromTime, SecFromTime, msFromTime, invariant, } from '@formatjs/ecma402-abstract';
|
|
5
2
|
function getApplicableZoneData(t, timeZone, tzData) {
|
|
6
3
|
var _a;
|
|
7
4
|
var zoneData = tzData[timeZone];
|
|
@@ -27,28 +24,27 @@ function getApplicableZoneData(t, timeZone, tzData) {
|
|
|
27
24
|
* @param calendar
|
|
28
25
|
* @param timeZone
|
|
29
26
|
*/
|
|
30
|
-
function ToLocalTime(t, calendar, timeZone, _a) {
|
|
27
|
+
export function ToLocalTime(t, calendar, timeZone, _a) {
|
|
31
28
|
var tzData = _a.tzData;
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
invariant(Type(t) === 'Number', 'invalid time');
|
|
30
|
+
invariant(calendar === 'gregory', 'We only support Gregory calendar right now');
|
|
34
31
|
var _b = getApplicableZoneData(t, timeZone, tzData), timeZoneOffset = _b[0], inDST = _b[1];
|
|
35
32
|
var tz = t + timeZoneOffset;
|
|
36
|
-
var year =
|
|
33
|
+
var year = YearFromTime(tz);
|
|
37
34
|
return {
|
|
38
|
-
weekday:
|
|
35
|
+
weekday: WeekDay(tz),
|
|
39
36
|
era: year < 0 ? 'BC' : 'AD',
|
|
40
37
|
year: year,
|
|
41
38
|
relatedYear: undefined,
|
|
42
39
|
yearName: undefined,
|
|
43
|
-
month:
|
|
44
|
-
day:
|
|
45
|
-
hour:
|
|
46
|
-
minute:
|
|
47
|
-
second:
|
|
48
|
-
millisecond:
|
|
40
|
+
month: MonthFromTime(tz),
|
|
41
|
+
day: DateFromTime(tz),
|
|
42
|
+
hour: HourFromTime(tz),
|
|
43
|
+
minute: MinFromTime(tz),
|
|
44
|
+
second: SecFromTime(tz),
|
|
45
|
+
millisecond: msFromTime(tz),
|
|
49
46
|
inDST: inDST,
|
|
50
47
|
// IMPORTANT: Not in spec
|
|
51
48
|
timeZoneOffset: timeZoneOffset,
|
|
52
49
|
};
|
|
53
50
|
}
|
|
54
|
-
exports.ToLocalTime = ToLocalTime;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.splitRangePattern = exports.splitFallbackRangePattern = exports.parseDateTimeSkeleton = exports.processDateTimePattern = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { RangePatternType, } from '@formatjs/ecma402-abstract';
|
|
6
3
|
/**
|
|
7
4
|
* https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
8
5
|
* Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
|
|
@@ -111,7 +108,7 @@ function matchSkeletonPattern(match, result) {
|
|
|
111
108
|
// Zone
|
|
112
109
|
case 'z': // 1..3, 4: specific non-location format
|
|
113
110
|
case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
|
|
114
|
-
case 'O': // 1, 4:
|
|
111
|
+
case 'O': // 1, 4: milliseconds in day short, long
|
|
115
112
|
case 'v': // 1, 4: generic non-location format
|
|
116
113
|
case 'V': // 1, 2, 3, 4: time zone ID or city
|
|
117
114
|
case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
|
|
@@ -166,7 +163,7 @@ function skeletonTokenToTable2(c) {
|
|
|
166
163
|
throw new RangeError('Invalid range pattern token');
|
|
167
164
|
}
|
|
168
165
|
}
|
|
169
|
-
function processDateTimePattern(pattern, result) {
|
|
166
|
+
export function processDateTimePattern(pattern, result) {
|
|
170
167
|
var literals = [];
|
|
171
168
|
// Use skeleton to populate result, but use mapped pattern to populate pattern
|
|
172
169
|
var pattern12 = pattern
|
|
@@ -195,14 +192,13 @@ function processDateTimePattern(pattern, result) {
|
|
|
195
192
|
pattern12,
|
|
196
193
|
];
|
|
197
194
|
}
|
|
198
|
-
exports.processDateTimePattern = processDateTimePattern;
|
|
199
195
|
/**
|
|
200
196
|
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
201
197
|
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
202
198
|
* @public
|
|
203
199
|
* @param skeleton skeleton string
|
|
204
200
|
*/
|
|
205
|
-
function parseDateTimeSkeleton(skeleton, rawPattern, rangePatterns, intervalFormatFallback) {
|
|
201
|
+
export function parseDateTimeSkeleton(skeleton, rawPattern, rangePatterns, intervalFormatFallback) {
|
|
206
202
|
if (rawPattern === void 0) { rawPattern = skeleton; }
|
|
207
203
|
var result = {
|
|
208
204
|
pattern: '',
|
|
@@ -220,8 +216,8 @@ function parseDateTimeSkeleton(skeleton, rawPattern, rangePatterns, intervalForm
|
|
|
220
216
|
patternParts: [],
|
|
221
217
|
};
|
|
222
218
|
var _a = processDateTimePattern(rawPattern_1, intervalResult), pattern_1 = _a[0], pattern12_1 = _a[1];
|
|
223
|
-
result.rangePatterns[key] =
|
|
224
|
-
result.rangePatterns12[key] =
|
|
219
|
+
result.rangePatterns[key] = __assign(__assign({}, intervalResult), { patternParts: splitRangePattern(pattern_1) });
|
|
220
|
+
result.rangePatterns12[key] = __assign(__assign({}, intervalResult), { patternParts: splitRangePattern(pattern12_1) });
|
|
225
221
|
}
|
|
226
222
|
}
|
|
227
223
|
if (intervalFormatFallback) {
|
|
@@ -240,31 +236,29 @@ function parseDateTimeSkeleton(skeleton, rawPattern, rangePatterns, intervalForm
|
|
|
240
236
|
result.pattern12 = pattern12;
|
|
241
237
|
return result;
|
|
242
238
|
}
|
|
243
|
-
|
|
244
|
-
function splitFallbackRangePattern(pattern) {
|
|
239
|
+
export function splitFallbackRangePattern(pattern) {
|
|
245
240
|
var parts = pattern.split(/(\{[0|1]\})/g).filter(Boolean);
|
|
246
241
|
return parts.map(function (pattern) {
|
|
247
242
|
switch (pattern) {
|
|
248
243
|
case '{0}':
|
|
249
244
|
return {
|
|
250
|
-
source:
|
|
245
|
+
source: RangePatternType.startRange,
|
|
251
246
|
pattern: pattern,
|
|
252
247
|
};
|
|
253
248
|
case '{1}':
|
|
254
249
|
return {
|
|
255
|
-
source:
|
|
250
|
+
source: RangePatternType.endRange,
|
|
256
251
|
pattern: pattern,
|
|
257
252
|
};
|
|
258
253
|
default:
|
|
259
254
|
return {
|
|
260
|
-
source:
|
|
255
|
+
source: RangePatternType.shared,
|
|
261
256
|
pattern: pattern,
|
|
262
257
|
};
|
|
263
258
|
}
|
|
264
259
|
});
|
|
265
260
|
}
|
|
266
|
-
|
|
267
|
-
function splitRangePattern(pattern) {
|
|
261
|
+
export function splitRangePattern(pattern) {
|
|
268
262
|
var PART_REGEX = /\{(.*?)\}/g;
|
|
269
263
|
// Map of part and index within the string
|
|
270
264
|
var parts = {};
|
|
@@ -282,20 +276,19 @@ function splitRangePattern(pattern) {
|
|
|
282
276
|
if (!splitIndex) {
|
|
283
277
|
return [
|
|
284
278
|
{
|
|
285
|
-
source:
|
|
279
|
+
source: RangePatternType.startRange,
|
|
286
280
|
pattern: pattern,
|
|
287
281
|
},
|
|
288
282
|
];
|
|
289
283
|
}
|
|
290
284
|
return [
|
|
291
285
|
{
|
|
292
|
-
source:
|
|
286
|
+
source: RangePatternType.startRange,
|
|
293
287
|
pattern: pattern.slice(0, splitIndex),
|
|
294
288
|
},
|
|
295
289
|
{
|
|
296
|
-
source:
|
|
290
|
+
source: RangePatternType.endRange,
|
|
297
291
|
pattern: pattern.slice(splitIndex),
|
|
298
292
|
},
|
|
299
293
|
];
|
|
300
294
|
}
|
|
301
|
-
exports.splitRangePattern = splitRangePattern;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.offsetPenalty = exports.shortMorePenalty = exports.shortLessPenalty = exports.longMorePenalty = exports.longLessPenalty = exports.differentNumericTypePenalty = exports.additionPenalty = exports.removalPenalty = exports.DATE_TIME_PROPS = void 0;
|
|
4
|
-
exports.DATE_TIME_PROPS = [
|
|
1
|
+
export var DATE_TIME_PROPS = [
|
|
5
2
|
'weekday',
|
|
6
3
|
'era',
|
|
7
4
|
'year',
|
|
@@ -14,11 +11,11 @@ exports.DATE_TIME_PROPS = [
|
|
|
14
11
|
'fractionalSecondDigits',
|
|
15
12
|
'timeZoneName',
|
|
16
13
|
];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
export var removalPenalty = 120;
|
|
15
|
+
export var additionPenalty = 20;
|
|
16
|
+
export var differentNumericTypePenalty = 15;
|
|
17
|
+
export var longLessPenalty = 8;
|
|
18
|
+
export var longMorePenalty = 6;
|
|
19
|
+
export var shortLessPenalty = 6;
|
|
20
|
+
export var shortMorePenalty = 3;
|
|
21
|
+
export var offsetPenalty = 1;
|