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