@formatjs/intl-datetimeformat 6.18.2 → 7.0.1
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/index.d.ts +1 -1
- package/index.js +1 -4
- package/package.json +14 -6
- package/polyfill-force.js +13 -15
- package/polyfill.iife.js +44 -44
- package/polyfill.js +15 -17
- package/should-polyfill.js +7 -10
- package/src/abstract/BasicFormatMatcher.js +26 -29
- package/src/abstract/BestFitFormatMatcher.js +19 -23
- package/src/abstract/DateTimeStyleFormat.js +5 -8
- package/src/abstract/FormatDateTime.d.ts +1 -1
- package/src/abstract/FormatDateTime.js +3 -6
- package/src/abstract/FormatDateTimePattern.d.ts +1 -1
- package/src/abstract/FormatDateTimePattern.js +12 -16
- package/src/abstract/FormatDateTimeRange.d.ts +2 -2
- package/src/abstract/FormatDateTimeRange.js +3 -6
- package/src/abstract/FormatDateTimeRangeToParts.d.ts +2 -2
- package/src/abstract/FormatDateTimeRangeToParts.js +4 -7
- package/src/abstract/FormatDateTimeToParts.d.ts +1 -1
- package/src/abstract/FormatDateTimeToParts.js +5 -8
- package/src/abstract/InitializeDateTimeFormat.js +37 -40
- package/src/abstract/PartitionDateTimePattern.d.ts +2 -2
- package/src/abstract/PartitionDateTimePattern.js +6 -9
- package/src/abstract/PartitionDateTimeRangePattern.d.ts +2 -2
- package/src/abstract/PartitionDateTimeRangePattern.js +16 -19
- package/src/abstract/ToDateTimeOptions.js +3 -6
- package/src/abstract/ToLocalTime.js +11 -14
- package/src/abstract/skeleton.js +14 -20
- package/src/abstract/utils.js +9 -12
- package/src/core.d.ts +1 -1
- package/src/core.js +115 -116
- package/src/data/all-tz.js +1 -3
- package/src/data/links.js +1 -3
- package/src/get_internal_slots.js +1 -4
- package/src/packer.d.ts +1 -1
- package/src/packer.js +5 -9
- package/src/to_locale_string.js +8 -13
- package/src/types.d.ts +1 -1
- package/src/types.js +1 -2
- package/supported-locales.generated.js +1 -4
- package/test262-main.d.ts +1 -1
- package/test262-main.js +3 -6
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/polyfill-force.d.ts +0 -1
- package/lib/polyfill-force.js +0 -44
- package/lib/polyfill.d.ts +0 -1
- package/lib/polyfill.js +0 -47
- package/lib/should-polyfill.d.ts +0 -1
- package/lib/should-polyfill.js +0 -61
- package/lib/src/abstract/BasicFormatMatcher.d.ts +0 -7
- package/lib/src/abstract/BasicFormatMatcher.js +0 -106
- package/lib/src/abstract/BestFitFormatMatcher.d.ts +0 -16
- package/lib/src/abstract/BestFitFormatMatcher.js +0 -116
- package/lib/src/abstract/DateTimeStyleFormat.d.ts +0 -2
- package/lib/src/abstract/DateTimeStyleFormat.js +0 -50
- package/lib/src/abstract/FormatDateTime.d.ts +0 -9
- package/lib/src/abstract/FormatDateTime.js +0 -15
- package/lib/src/abstract/FormatDateTimePattern.d.ts +0 -14
- package/lib/src/abstract/FormatDateTimePattern.js +0 -191
- package/lib/src/abstract/FormatDateTimeRange.d.ts +0 -4
- package/lib/src/abstract/FormatDateTimeRange.js +0 -10
- package/lib/src/abstract/FormatDateTimeRangeToParts.d.ts +0 -5
- package/lib/src/abstract/FormatDateTimeRangeToParts.js +0 -14
- package/lib/src/abstract/FormatDateTimeToParts.d.ts +0 -11
- package/lib/src/abstract/FormatDateTimeToParts.js +0 -21
- package/lib/src/abstract/InitializeDateTimeFormat.d.ts +0 -17
- package/lib/src/abstract/InitializeDateTimeFormat.js +0 -190
- package/lib/src/abstract/PartitionDateTimePattern.d.ts +0 -10
- package/lib/src/abstract/PartitionDateTimePattern.js +0 -17
- package/lib/src/abstract/PartitionDateTimeRangePattern.d.ts +0 -5
- package/lib/src/abstract/PartitionDateTimeRangePattern.js +0 -119
- package/lib/src/abstract/ToDateTimeOptions.d.ts +0 -7
- package/lib/src/abstract/ToDateTimeOptions.js +0 -63
- package/lib/src/abstract/ToLocalTime.d.ts +0 -26
- package/lib/src/abstract/ToLocalTime.js +0 -49
- package/lib/src/abstract/skeleton.d.ts +0 -13
- package/lib/src/abstract/skeleton.js +0 -294
- package/lib/src/abstract/utils.d.ts +0 -10
- package/lib/src/abstract/utils.js +0 -21
- package/lib/src/core.d.ts +0 -20
- package/lib/src/core.js +0 -300
- package/lib/src/data/all-tz.d.ts +0 -6
- package/lib/src/data/all-tz.js +0 -461
- package/lib/src/data/links.d.ts +0 -259
- package/lib/src/data/links.js +0 -260
- package/lib/src/get_internal_slots.d.ts +0 -2
- package/lib/src/get_internal_slots.js +0 -11
- package/lib/src/packer.d.ts +0 -4
- package/lib/src/packer.js +0 -39
- package/lib/src/to_locale_string.d.ts +0 -7
- package/lib/src/to_locale_string.js +0 -19
- package/lib/src/types.d.ts +0 -47
- package/lib/src/types.js +0 -1
- package/lib/supported-locales.generated.d.ts +0 -1
- package/lib/supported-locales.generated.js +0 -1
- package/lib/test262-main.d.ts +0 -1
- package/lib/test262-main.js +0 -23786
|
@@ -1,78 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
6
|
-
var utils_1 = require("./utils");
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { invariant } from '@formatjs/ecma402-abstract';
|
|
3
|
+
import { DATE_TIME_PROPS, additionPenalty, removalPenalty, longMorePenalty, shortMorePenalty, shortLessPenalty, longLessPenalty, offsetPenalty, } from './utils.js';
|
|
7
4
|
/**
|
|
8
5
|
* https://tc39.es/ecma402/#sec-basicformatmatcher
|
|
9
6
|
* @param options
|
|
10
7
|
* @param formats
|
|
11
8
|
*/
|
|
12
|
-
function BasicFormatMatcher(options, formats) {
|
|
9
|
+
export function BasicFormatMatcher(options, formats) {
|
|
13
10
|
var bestScore = -Infinity;
|
|
14
11
|
var bestFormat = formats[0];
|
|
15
|
-
|
|
12
|
+
invariant(Array.isArray(formats), 'formats should be a list of things');
|
|
16
13
|
for (var _i = 0, formats_1 = formats; _i < formats_1.length; _i++) {
|
|
17
14
|
var format = formats_1[_i];
|
|
18
15
|
var score = 0;
|
|
19
|
-
for (var _a = 0, DATE_TIME_PROPS_1 =
|
|
16
|
+
for (var _a = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _a < DATE_TIME_PROPS_1.length; _a++) {
|
|
20
17
|
var prop = DATE_TIME_PROPS_1[_a];
|
|
21
18
|
var optionsProp = options[prop];
|
|
22
19
|
var formatProp = format[prop];
|
|
23
20
|
if (optionsProp === undefined && formatProp !== undefined) {
|
|
24
|
-
score -=
|
|
21
|
+
score -= additionPenalty;
|
|
25
22
|
}
|
|
26
23
|
else if (optionsProp !== undefined && formatProp === undefined) {
|
|
27
|
-
score -=
|
|
24
|
+
score -= removalPenalty;
|
|
28
25
|
}
|
|
29
26
|
else if (prop === 'timeZoneName') {
|
|
30
27
|
if (optionsProp === 'short' || optionsProp === 'shortGeneric') {
|
|
31
28
|
if (formatProp === 'shortOffset') {
|
|
32
|
-
score -=
|
|
29
|
+
score -= offsetPenalty;
|
|
33
30
|
}
|
|
34
31
|
else if (formatProp === 'longOffset') {
|
|
35
|
-
score -=
|
|
32
|
+
score -= offsetPenalty + shortMorePenalty;
|
|
36
33
|
}
|
|
37
34
|
else if (optionsProp === 'short' && formatProp === 'long') {
|
|
38
|
-
score -=
|
|
35
|
+
score -= shortMorePenalty;
|
|
39
36
|
}
|
|
40
37
|
else if (optionsProp === 'shortGeneric' &&
|
|
41
38
|
formatProp === 'longGeneric') {
|
|
42
|
-
score -=
|
|
39
|
+
score -= shortMorePenalty;
|
|
43
40
|
}
|
|
44
41
|
else if (optionsProp !== formatProp) {
|
|
45
|
-
score -=
|
|
42
|
+
score -= removalPenalty;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
else if (optionsProp === 'shortOffset' &&
|
|
49
46
|
formatProp === 'longOffset') {
|
|
50
|
-
score -=
|
|
47
|
+
score -= shortMorePenalty;
|
|
51
48
|
}
|
|
52
49
|
else if (optionsProp === 'long' || optionsProp === 'longGeneric') {
|
|
53
50
|
if (formatProp === 'longOffset') {
|
|
54
|
-
score -=
|
|
51
|
+
score -= offsetPenalty;
|
|
55
52
|
}
|
|
56
53
|
else if (formatProp === 'shortOffset') {
|
|
57
|
-
score -=
|
|
54
|
+
score -= offsetPenalty + longLessPenalty;
|
|
58
55
|
}
|
|
59
56
|
else if (optionsProp === 'long' && formatProp === 'short') {
|
|
60
|
-
score -=
|
|
57
|
+
score -= longLessPenalty;
|
|
61
58
|
}
|
|
62
59
|
else if (optionsProp === 'longGeneric' &&
|
|
63
60
|
formatProp === 'shortGeneric') {
|
|
64
|
-
score -=
|
|
61
|
+
score -= longLessPenalty;
|
|
65
62
|
}
|
|
66
63
|
else if (optionsProp !== formatProp) {
|
|
67
|
-
score -=
|
|
64
|
+
score -= removalPenalty;
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
else if (optionsProp === 'longOffset' &&
|
|
71
68
|
formatProp === 'shortOffset') {
|
|
72
|
-
score -=
|
|
69
|
+
score -= longLessPenalty;
|
|
73
70
|
}
|
|
74
71
|
else if (optionsProp !== formatProp) {
|
|
75
|
-
score -=
|
|
72
|
+
score -= removalPenalty;
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
else if (optionsProp !== formatProp) {
|
|
@@ -87,16 +84,16 @@ function BasicFormatMatcher(options, formats) {
|
|
|
87
84
|
var formatPropIndex = values.indexOf(formatProp);
|
|
88
85
|
var delta = Math.max(-2, Math.min(formatPropIndex - optionsPropIndex, 2));
|
|
89
86
|
if (delta === 2) {
|
|
90
|
-
score -=
|
|
87
|
+
score -= longMorePenalty;
|
|
91
88
|
}
|
|
92
89
|
else if (delta === 1) {
|
|
93
|
-
score -=
|
|
90
|
+
score -= shortMorePenalty;
|
|
94
91
|
}
|
|
95
92
|
else if (delta === -1) {
|
|
96
|
-
score -=
|
|
93
|
+
score -= shortLessPenalty;
|
|
97
94
|
}
|
|
98
95
|
else if (delta === -2) {
|
|
99
|
-
score -=
|
|
96
|
+
score -= longLessPenalty;
|
|
100
97
|
}
|
|
101
98
|
}
|
|
102
99
|
}
|
|
@@ -105,5 +102,5 @@ function BasicFormatMatcher(options, formats) {
|
|
|
105
102
|
bestFormat = format;
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
|
-
return
|
|
105
|
+
return __assign({}, bestFormat);
|
|
109
106
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var tslib_1 = require("tslib");
|
|
6
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
7
|
-
var skeleton_1 = require("./skeleton");
|
|
8
|
-
var utils_1 = require("./utils");
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { invariant } from '@formatjs/ecma402-abstract';
|
|
3
|
+
import { processDateTimePattern } from './skeleton.js';
|
|
4
|
+
import { DATE_TIME_PROPS, additionPenalty, differentNumericTypePenalty, longLessPenalty, longMorePenalty, removalPenalty, shortLessPenalty, shortMorePenalty, } from './utils.js';
|
|
9
5
|
function isNumericType(t) {
|
|
10
6
|
return t === 'numeric' || t === '2-digit';
|
|
11
7
|
}
|
|
@@ -15,29 +11,29 @@ function isNumericType(t) {
|
|
|
15
11
|
* @param options
|
|
16
12
|
* @param format
|
|
17
13
|
*/
|
|
18
|
-
function bestFitFormatMatcherScore(options, format) {
|
|
14
|
+
export function bestFitFormatMatcherScore(options, format) {
|
|
19
15
|
var score = 0;
|
|
20
16
|
if (options.hour12 && !format.hour12) {
|
|
21
|
-
score -=
|
|
17
|
+
score -= removalPenalty;
|
|
22
18
|
}
|
|
23
19
|
else if (!options.hour12 && format.hour12) {
|
|
24
|
-
score -=
|
|
20
|
+
score -= additionPenalty;
|
|
25
21
|
}
|
|
26
|
-
for (var _i = 0, DATE_TIME_PROPS_1 =
|
|
22
|
+
for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
|
|
27
23
|
var prop = DATE_TIME_PROPS_1[_i];
|
|
28
24
|
var optionsProp = options[prop];
|
|
29
25
|
var formatProp = format[prop];
|
|
30
26
|
if (optionsProp === undefined && formatProp !== undefined) {
|
|
31
|
-
score -=
|
|
27
|
+
score -= additionPenalty;
|
|
32
28
|
}
|
|
33
29
|
else if (optionsProp !== undefined && formatProp === undefined) {
|
|
34
|
-
score -=
|
|
30
|
+
score -= removalPenalty;
|
|
35
31
|
}
|
|
36
32
|
else if (optionsProp !== formatProp) {
|
|
37
33
|
// extra penalty for numeric vs non-numeric
|
|
38
34
|
if (isNumericType(optionsProp) !==
|
|
39
35
|
isNumericType(formatProp)) {
|
|
40
|
-
score -=
|
|
36
|
+
score -= differentNumericTypePenalty;
|
|
41
37
|
}
|
|
42
38
|
else {
|
|
43
39
|
var values = ['2-digit', 'numeric', 'narrow', 'short', 'long'];
|
|
@@ -45,16 +41,16 @@ function bestFitFormatMatcherScore(options, format) {
|
|
|
45
41
|
var formatPropIndex = values.indexOf(formatProp);
|
|
46
42
|
var delta = Math.max(-2, Math.min(formatPropIndex - optionsPropIndex, 2));
|
|
47
43
|
if (delta === 2) {
|
|
48
|
-
score -=
|
|
44
|
+
score -= longMorePenalty;
|
|
49
45
|
}
|
|
50
46
|
else if (delta === 1) {
|
|
51
|
-
score -=
|
|
47
|
+
score -= shortMorePenalty;
|
|
52
48
|
}
|
|
53
49
|
else if (delta === -1) {
|
|
54
|
-
score -=
|
|
50
|
+
score -= shortLessPenalty;
|
|
55
51
|
}
|
|
56
52
|
else if (delta === -2) {
|
|
57
|
-
score -=
|
|
53
|
+
score -= longLessPenalty;
|
|
58
54
|
}
|
|
59
55
|
}
|
|
60
56
|
}
|
|
@@ -68,10 +64,10 @@ function bestFitFormatMatcherScore(options, format) {
|
|
|
68
64
|
* @param formats
|
|
69
65
|
* @param implDetails Implementation details
|
|
70
66
|
*/
|
|
71
|
-
function BestFitFormatMatcher(options, formats) {
|
|
67
|
+
export function BestFitFormatMatcher(options, formats) {
|
|
72
68
|
var bestScore = -Infinity;
|
|
73
69
|
var bestFormat = formats[0];
|
|
74
|
-
|
|
70
|
+
invariant(Array.isArray(formats), 'formats should be a list of things');
|
|
75
71
|
for (var _i = 0, formats_1 = formats; _i < formats_1.length; _i++) {
|
|
76
72
|
var format = formats_1[_i];
|
|
77
73
|
var score = bestFitFormatMatcherScore(options, format);
|
|
@@ -80,9 +76,9 @@ function BestFitFormatMatcher(options, formats) {
|
|
|
80
76
|
bestFormat = format;
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
|
-
var skeletonFormat =
|
|
79
|
+
var skeletonFormat = __assign({}, bestFormat);
|
|
84
80
|
var patternFormat = { rawPattern: bestFormat.rawPattern };
|
|
85
|
-
|
|
81
|
+
processDateTimePattern(bestFormat.rawPattern, patternFormat);
|
|
86
82
|
// Kinda following https://github.com/unicode-org/icu/blob/dd50e38f459d84e9bf1b0c618be8483d318458ad/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java
|
|
87
83
|
// Method adjustFieldTypes
|
|
88
84
|
for (var prop in skeletonFormat) {
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DateTimeStyleFormat = DateTimeStyleFormat;
|
|
4
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
5
|
-
function DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData) {
|
|
1
|
+
import { invariant, } from '@formatjs/ecma402-abstract';
|
|
2
|
+
export function DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData) {
|
|
6
3
|
var dateFormat, timeFormat;
|
|
7
4
|
if (timeStyle !== undefined) {
|
|
8
|
-
|
|
5
|
+
invariant(timeStyle === 'full' ||
|
|
9
6
|
timeStyle === 'long' ||
|
|
10
7
|
timeStyle === 'medium' ||
|
|
11
8
|
timeStyle === 'short', 'invalid timeStyle');
|
|
12
9
|
timeFormat = dataLocaleData.timeFormat[timeStyle];
|
|
13
10
|
}
|
|
14
11
|
if (dateStyle !== undefined) {
|
|
15
|
-
|
|
12
|
+
invariant(dateStyle === 'full' ||
|
|
16
13
|
dateStyle === 'long' ||
|
|
17
14
|
dateStyle === 'medium' ||
|
|
18
15
|
dateStyle === 'short', 'invalid dateStyle');
|
|
@@ -48,6 +45,6 @@ function DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData) {
|
|
|
48
45
|
if (timeStyle !== undefined) {
|
|
49
46
|
return timeFormat;
|
|
50
47
|
}
|
|
51
|
-
|
|
48
|
+
invariant(dateStyle !== undefined, 'dateStyle should not be undefined');
|
|
52
49
|
return dateFormat;
|
|
53
50
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DateTimeFormat } from '@formatjs/ecma402-abstract';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { PartitionDateTimePattern } from './PartitionDateTimePattern';
|
|
3
|
+
import { PartitionDateTimePattern } from './PartitionDateTimePattern.js';
|
|
4
4
|
/**
|
|
5
5
|
* https://tc39.es/ecma402/#sec-formatdatetime
|
|
6
6
|
* @param dtf DateTimeFormat
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormatDateTime = FormatDateTime;
|
|
4
|
-
var PartitionDateTimePattern_1 = require("./PartitionDateTimePattern");
|
|
1
|
+
import { PartitionDateTimePattern } from './PartitionDateTimePattern.js';
|
|
5
2
|
/**
|
|
6
3
|
* https://tc39.es/ecma402/#sec-formatdatetime
|
|
7
4
|
* @param dtf DateTimeFormat
|
|
8
5
|
* @param x
|
|
9
6
|
*/
|
|
10
|
-
function FormatDateTime(dtf, x, implDetails) {
|
|
11
|
-
var parts =
|
|
7
|
+
export function FormatDateTime(dtf, x, implDetails) {
|
|
8
|
+
var parts = PartitionDateTimePattern(dtf, x, implDetails);
|
|
12
9
|
var result = '';
|
|
13
10
|
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
14
11
|
var part = parts_1[_i];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DateTimeFormat, DateTimeFormatLocaleInternalData, IntlDateTimeFormatInternal, IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { ToLocalTimeImplDetails } from './ToLocalTime';
|
|
3
|
+
import { ToLocalTimeImplDetails } from './ToLocalTime.js';
|
|
4
4
|
export interface FormatDateTimePatternImplDetails {
|
|
5
5
|
getInternalSlots(dtf: Intl.DateTimeFormat | DateTimeFormat): IntlDateTimeFormatInternal;
|
|
6
6
|
localeData: Record<string, DateTimeFormatLocaleInternalData>;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
6
|
-
var decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
7
|
-
var ToLocalTime_1 = require("./ToLocalTime");
|
|
8
|
-
var utils_1 = require("./utils");
|
|
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';
|
|
9
5
|
function pad(n) {
|
|
10
6
|
if (n < 10) {
|
|
11
7
|
return "0".concat(n);
|
|
@@ -39,9 +35,9 @@ function offsetToGmtString(gmtFormat, hourFormat, offsetInMs, style) {
|
|
|
39
35
|
* @param dtf
|
|
40
36
|
* @param x
|
|
41
37
|
*/
|
|
42
|
-
function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
38
|
+
export function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
43
39
|
var getInternalSlots = _a.getInternalSlots, localeData = _a.localeData, getDefaultTimeZone = _a.getDefaultTimeZone, tzData = _a.tzData;
|
|
44
|
-
x =
|
|
40
|
+
x = TimeClip(x);
|
|
45
41
|
/** IMPL START */
|
|
46
42
|
var internalSlots = getInternalSlots(dtf);
|
|
47
43
|
var dataLocale = internalSlots.dataLocale;
|
|
@@ -50,20 +46,20 @@ function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
|
50
46
|
var locale = internalSlots.locale;
|
|
51
47
|
var nfOptions = Object.create(null);
|
|
52
48
|
nfOptions.useGrouping = false;
|
|
53
|
-
var nf =
|
|
49
|
+
var nf = createMemoizedNumberFormat(locale, nfOptions);
|
|
54
50
|
var nf2Options = Object.create(null);
|
|
55
51
|
nf2Options.minimumIntegerDigits = 2;
|
|
56
52
|
nf2Options.useGrouping = false;
|
|
57
|
-
var nf2 =
|
|
53
|
+
var nf2 = createMemoizedNumberFormat(locale, nf2Options);
|
|
58
54
|
var fractionalSecondDigits = internalSlots.fractionalSecondDigits;
|
|
59
55
|
var nf3;
|
|
60
56
|
if (fractionalSecondDigits !== undefined) {
|
|
61
57
|
var nf3Options = Object.create(null);
|
|
62
58
|
nf3Options.minimumIntegerDigits = fractionalSecondDigits;
|
|
63
59
|
nf3Options.useGrouping = false;
|
|
64
|
-
nf3 =
|
|
60
|
+
nf3 = createMemoizedNumberFormat(locale, nf3Options);
|
|
65
61
|
}
|
|
66
|
-
var tm =
|
|
62
|
+
var tm = ToLocalTime(x,
|
|
67
63
|
// @ts-ignore
|
|
68
64
|
internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
|
|
69
65
|
var result = [];
|
|
@@ -77,7 +73,7 @@ function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
|
77
73
|
});
|
|
78
74
|
}
|
|
79
75
|
else if (p === 'fractionalSecondDigits') {
|
|
80
|
-
var v = new
|
|
76
|
+
var v = new Decimal(tm.millisecond)
|
|
81
77
|
.times(10)
|
|
82
78
|
.pow((fractionalSecondDigits || 0) - 3)
|
|
83
79
|
.floor()
|
|
@@ -108,7 +104,7 @@ function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
|
108
104
|
}
|
|
109
105
|
result.push({ type: p, value: fv });
|
|
110
106
|
}
|
|
111
|
-
else if (
|
|
107
|
+
else if (DATE_TIME_PROPS.indexOf(p) > -1) {
|
|
112
108
|
var fv = '';
|
|
113
109
|
var f = internalSlots[p];
|
|
114
110
|
// @ts-ignore
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
|
-
import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern';
|
|
3
|
-
import { ToLocalTimeImplDetails } from './ToLocalTime';
|
|
2
|
+
import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern.js';
|
|
3
|
+
import { ToLocalTimeImplDetails } from './ToLocalTime.js';
|
|
4
4
|
export declare function FormatDateTimeRange(dtf: Intl.DateTimeFormat, x: Decimal, y: Decimal, implDetails: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): string;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var PartitionDateTimeRangePattern_1 = require("./PartitionDateTimeRangePattern");
|
|
5
|
-
function FormatDateTimeRange(dtf, x, y, implDetails) {
|
|
6
|
-
var parts = (0, PartitionDateTimeRangePattern_1.PartitionDateTimeRangePattern)(dtf, x, y, implDetails);
|
|
1
|
+
import { PartitionDateTimeRangePattern } from './PartitionDateTimeRangePattern.js';
|
|
2
|
+
export function FormatDateTimeRange(dtf, x, y, implDetails) {
|
|
3
|
+
var parts = PartitionDateTimeRangePattern(dtf, x, y, implDetails);
|
|
7
4
|
var result = '';
|
|
8
5
|
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
9
6
|
var part = parts_1[_i];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
|
|
2
2
|
import { Decimal } from 'decimal.js';
|
|
3
|
-
import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern';
|
|
4
|
-
import { ToLocalTimeImplDetails } from './ToLocalTime';
|
|
3
|
+
import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern.js';
|
|
4
|
+
import { ToLocalTimeImplDetails } from './ToLocalTime.js';
|
|
5
5
|
export declare function FormatDateTimeRangeToParts(dtf: Intl.DateTimeFormat, x: Decimal, y: Decimal, implDetails: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): IntlDateTimeFormatPart[];
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
function FormatDateTimeRangeToParts(dtf, x, y, implDetails) {
|
|
6
|
-
var parts = (0, PartitionDateTimeRangePattern_1.PartitionDateTimeRangePattern)(dtf, x, y, implDetails);
|
|
7
|
-
var result = new Array(0);
|
|
1
|
+
import { PartitionDateTimeRangePattern } from './PartitionDateTimeRangePattern.js';
|
|
2
|
+
export function FormatDateTimeRangeToParts(dtf, x, y, implDetails) {
|
|
3
|
+
var parts = PartitionDateTimeRangePattern(dtf, x, y, implDetails);
|
|
4
|
+
var result = [];
|
|
8
5
|
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
9
6
|
var part = parts_1[_i];
|
|
10
7
|
result.push({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { PartitionDateTimePattern } from './PartitionDateTimePattern';
|
|
3
|
+
import { PartitionDateTimePattern } from './PartitionDateTimePattern.js';
|
|
4
4
|
/**
|
|
5
5
|
* https://tc39.es/ecma402/#sec-formatdatetimetoparts
|
|
6
6
|
*
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FormatDateTimeToParts = FormatDateTimeToParts;
|
|
4
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
5
|
-
var PartitionDateTimePattern_1 = require("./PartitionDateTimePattern");
|
|
1
|
+
import { ArrayCreate } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import { PartitionDateTimePattern } from './PartitionDateTimePattern.js';
|
|
6
3
|
/**
|
|
7
4
|
* https://tc39.es/ecma402/#sec-formatdatetimetoparts
|
|
8
5
|
*
|
|
@@ -10,9 +7,9 @@ var PartitionDateTimePattern_1 = require("./PartitionDateTimePattern");
|
|
|
10
7
|
* @param x
|
|
11
8
|
* @param implDetails
|
|
12
9
|
*/
|
|
13
|
-
function FormatDateTimeToParts(dtf, x, implDetails) {
|
|
14
|
-
var parts =
|
|
15
|
-
var result =
|
|
10
|
+
export function FormatDateTimeToParts(dtf, x, implDetails) {
|
|
11
|
+
var parts = PartitionDateTimePattern(dtf, x, implDetails);
|
|
12
|
+
var result = ArrayCreate(0);
|
|
16
13
|
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
17
14
|
var part = parts_1[_i];
|
|
18
15
|
result.push({
|
|
@@ -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 utils_1 = require("./utils");
|
|
1
|
+
import { CanonicalizeLocaleList, CanonicalizeTimeZoneName, GetNumberOption, GetOption, IsValidTimeZoneName, invariant, } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import { ResolveLocale } from '@formatjs/intl-localematcher';
|
|
3
|
+
import { BasicFormatMatcher } from './BasicFormatMatcher.js';
|
|
4
|
+
import { BestFitFormatMatcher } from './BestFitFormatMatcher.js';
|
|
5
|
+
import { DateTimeStyleFormat } from './DateTimeStyleFormat.js';
|
|
6
|
+
import { ToDateTimeOptions } from './ToDateTimeOptions.js';
|
|
7
|
+
import { DATE_TIME_PROPS } from './utils.js';
|
|
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,13 +84,13 @@ 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, {
|
|
91
88
|
zoneNamesFromData: Object.keys(tzData),
|
|
92
89
|
uppercaseLinks: uppercaseLinks,
|
|
93
90
|
})) {
|
|
94
91
|
throw new RangeError('Invalid timeZoneName');
|
|
95
92
|
}
|
|
96
|
-
timeZone =
|
|
93
|
+
timeZone = CanonicalizeTimeZoneName(timeZone, {
|
|
97
94
|
zoneNames: Object.keys(tzData),
|
|
98
95
|
uppercaseLinks: uppercaseLinks,
|
|
99
96
|
});
|
|
@@ -103,15 +100,15 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
103
100
|
}
|
|
104
101
|
internalSlots.timeZone = timeZone;
|
|
105
102
|
opt = Object.create(null);
|
|
106
|
-
opt.weekday =
|
|
107
|
-
opt.era =
|
|
108
|
-
opt.year =
|
|
109
|
-
opt.month =
|
|
110
|
-
opt.day =
|
|
111
|
-
opt.hour =
|
|
112
|
-
opt.minute =
|
|
113
|
-
opt.second =
|
|
114
|
-
opt.timeZoneName =
|
|
103
|
+
opt.weekday = GetOption(options, 'weekday', 'string', ['narrow', 'short', 'long'], undefined);
|
|
104
|
+
opt.era = GetOption(options, 'era', 'string', ['narrow', 'short', 'long'], undefined);
|
|
105
|
+
opt.year = GetOption(options, 'year', 'string', ['2-digit', 'numeric'], undefined);
|
|
106
|
+
opt.month = GetOption(options, 'month', 'string', ['2-digit', 'numeric', 'narrow', 'short', 'long'], undefined);
|
|
107
|
+
opt.day = GetOption(options, 'day', 'string', ['2-digit', 'numeric'], undefined);
|
|
108
|
+
opt.hour = GetOption(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
|
|
109
|
+
opt.minute = GetOption(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
|
|
110
|
+
opt.second = GetOption(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
|
|
111
|
+
opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', [
|
|
115
112
|
'long',
|
|
116
113
|
'short',
|
|
117
114
|
'longOffset',
|
|
@@ -119,23 +116,23 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
119
116
|
'longGeneric',
|
|
120
117
|
'shortGeneric',
|
|
121
118
|
], undefined);
|
|
122
|
-
opt.fractionalSecondDigits =
|
|
119
|
+
opt.fractionalSecondDigits = GetNumberOption(options, 'fractionalSecondDigits', 1, 3, undefined);
|
|
123
120
|
var dataLocaleData = localeData[dataLocale];
|
|
124
|
-
|
|
121
|
+
invariant(!!dataLocaleData, "Missing locale data for ".concat(dataLocale));
|
|
125
122
|
var formats = dataLocaleData.formats[calendar];
|
|
126
123
|
// UNSPECCED: IMPLEMENTATION DETAILS
|
|
127
124
|
if (!formats) {
|
|
128
125
|
throw new RangeError("Calendar \"".concat(calendar, "\" is not supported. Try setting \"calendar\" to 1 of the following: ").concat(Object.keys(dataLocaleData.formats).join(', ')));
|
|
129
126
|
}
|
|
130
|
-
var formatMatcher =
|
|
131
|
-
var dateStyle =
|
|
127
|
+
var formatMatcher = GetOption(options, 'formatMatcher', 'string', ['basic', 'best fit'], 'best fit');
|
|
128
|
+
var dateStyle = GetOption(options, 'dateStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
|
|
132
129
|
internalSlots.dateStyle = dateStyle;
|
|
133
|
-
var timeStyle =
|
|
130
|
+
var timeStyle = GetOption(options, 'timeStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
|
|
134
131
|
internalSlots.timeStyle = timeStyle;
|
|
135
132
|
var bestFormat;
|
|
136
133
|
if (dateStyle === undefined && timeStyle === undefined) {
|
|
137
134
|
if (formatMatcher === 'basic') {
|
|
138
|
-
bestFormat =
|
|
135
|
+
bestFormat = BasicFormatMatcher(opt, formats);
|
|
139
136
|
}
|
|
140
137
|
else {
|
|
141
138
|
// IMPL DETAILS START
|
|
@@ -144,18 +141,18 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
|
144
141
|
opt.hour12 = hc === 'h11' || hc === 'h12';
|
|
145
142
|
}
|
|
146
143
|
// IMPL DETAILS END
|
|
147
|
-
bestFormat =
|
|
144
|
+
bestFormat = BestFitFormatMatcher(opt, formats);
|
|
148
145
|
}
|
|
149
146
|
}
|
|
150
147
|
else {
|
|
151
|
-
for (var _i = 0, DATE_TIME_PROPS_1 =
|
|
148
|
+
for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
|
|
152
149
|
var prop = DATE_TIME_PROPS_1[_i];
|
|
153
150
|
var p = opt[prop];
|
|
154
151
|
if (p !== undefined) {
|
|
155
152
|
throw new TypeError("Intl.DateTimeFormat can't set option ".concat(prop, " when ").concat(dateStyle ? 'dateStyle' : 'timeStyle', " is used"));
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
bestFormat =
|
|
155
|
+
bestFormat = DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData);
|
|
159
156
|
}
|
|
160
157
|
// IMPL DETAIL START
|
|
161
158
|
// For debugging
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DateTimeFormat, IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern';
|
|
4
|
-
import { ToLocalTimeImplDetails } from './ToLocalTime';
|
|
3
|
+
import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern.js';
|
|
4
|
+
import { ToLocalTimeImplDetails } from './ToLocalTime.js';
|
|
5
5
|
/**
|
|
6
6
|
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
7
7
|
* @param dtf
|