@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
package/lib/polyfill.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { DateTimeFormat } from './';
|
|
2
|
-
import { defineProperty } from '@formatjs/ecma402-abstract';
|
|
3
|
-
import { shouldPolyfill } from './should-polyfill';
|
|
4
|
-
import { toLocaleString as _toLocaleString, toLocaleDateString as _toLocaleDateString, toLocaleTimeString as _toLocaleTimeString, } from './src/to_locale_string';
|
|
5
|
-
if (shouldPolyfill()) {
|
|
6
|
-
defineProperty(Intl, 'DateTimeFormat', { value: DateTimeFormat });
|
|
7
|
-
defineProperty(Date.prototype, 'toLocaleString', {
|
|
8
|
-
value: function toLocaleString(locales, options) {
|
|
9
|
-
if (options === void 0) { options = {
|
|
10
|
-
dateStyle: 'short',
|
|
11
|
-
timeStyle: 'medium',
|
|
12
|
-
}; }
|
|
13
|
-
try {
|
|
14
|
-
return _toLocaleString(this, locales, options);
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
return 'Invalid Date';
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
defineProperty(Date.prototype, 'toLocaleDateString', {
|
|
22
|
-
value: function toLocaleDateString(locales, options) {
|
|
23
|
-
if (options === void 0) { options = {
|
|
24
|
-
dateStyle: 'short',
|
|
25
|
-
}; }
|
|
26
|
-
try {
|
|
27
|
-
return _toLocaleDateString(this, locales, options);
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
return 'Invalid Date';
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
defineProperty(Date.prototype, 'toLocaleTimeString', {
|
|
35
|
-
value: function toLocaleTimeString(locales, options) {
|
|
36
|
-
if (options === void 0) { options = {
|
|
37
|
-
timeStyle: 'medium',
|
|
38
|
-
}; }
|
|
39
|
-
try {
|
|
40
|
-
return _toLocaleTimeString(this, locales, options);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
return 'Invalid Date';
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}
|
package/lib/should-polyfill.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function shouldPolyfill(locale?: string): string | undefined;
|
package/lib/should-polyfill.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { match } from '@formatjs/intl-localematcher';
|
|
2
|
-
import { supportedLocales } from './supported-locales.generated';
|
|
3
|
-
function supportsDateStyle() {
|
|
4
|
-
try {
|
|
5
|
-
return !!new Intl.DateTimeFormat(undefined, {
|
|
6
|
-
dateStyle: 'short',
|
|
7
|
-
}).resolvedOptions().dateStyle;
|
|
8
|
-
}
|
|
9
|
-
catch (e) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* https://bugs.chromium.org/p/chromium/issues/detail?id=865351
|
|
15
|
-
*/
|
|
16
|
-
function hasChromeLt71Bug() {
|
|
17
|
-
try {
|
|
18
|
-
return (new Intl.DateTimeFormat('en', {
|
|
19
|
-
hourCycle: 'h11',
|
|
20
|
-
hour: 'numeric',
|
|
21
|
-
}).formatToParts(0)[2].type !== 'dayPeriod');
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Node 14's version of Intl.DateTimeFormat does not throw
|
|
29
|
-
* when dateStyle/timeStyle is used with other options.
|
|
30
|
-
* This was fixed in newer V8 versions
|
|
31
|
-
*/
|
|
32
|
-
function hasUnthrownDateTimeStyleBug() {
|
|
33
|
-
try {
|
|
34
|
-
return !!new Intl.DateTimeFormat('en', {
|
|
35
|
-
dateStyle: 'short',
|
|
36
|
-
hour: 'numeric',
|
|
37
|
-
}).format(new Date(0));
|
|
38
|
-
}
|
|
39
|
-
catch (e) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function supportedLocalesOf(locale) {
|
|
44
|
-
if (!locale) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
var locales = Array.isArray(locale) ? locale : [locale];
|
|
48
|
-
return (Intl.DateTimeFormat.supportedLocalesOf(locales).length === locales.length);
|
|
49
|
-
}
|
|
50
|
-
export function shouldPolyfill(locale) {
|
|
51
|
-
if (locale === void 0) { locale = 'en'; }
|
|
52
|
-
if (!('DateTimeFormat' in Intl) ||
|
|
53
|
-
!('formatToParts' in Intl.DateTimeFormat.prototype) ||
|
|
54
|
-
!('formatRange' in Intl.DateTimeFormat.prototype) ||
|
|
55
|
-
hasChromeLt71Bug() ||
|
|
56
|
-
hasUnthrownDateTimeStyleBug() ||
|
|
57
|
-
!supportsDateStyle() ||
|
|
58
|
-
!supportedLocalesOf(locale)) {
|
|
59
|
-
return locale ? match([locale], supportedLocales, 'en') : undefined;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
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';
|
|
4
|
-
/**
|
|
5
|
-
* https://tc39.es/ecma402/#sec-basicformatmatcher
|
|
6
|
-
* @param options
|
|
7
|
-
* @param formats
|
|
8
|
-
*/
|
|
9
|
-
export function BasicFormatMatcher(options, formats) {
|
|
10
|
-
var bestScore = -Infinity;
|
|
11
|
-
var bestFormat = formats[0];
|
|
12
|
-
invariant(Array.isArray(formats), 'formats should be a list of things');
|
|
13
|
-
for (var _i = 0, formats_1 = formats; _i < formats_1.length; _i++) {
|
|
14
|
-
var format = formats_1[_i];
|
|
15
|
-
var score = 0;
|
|
16
|
-
for (var _a = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _a < DATE_TIME_PROPS_1.length; _a++) {
|
|
17
|
-
var prop = DATE_TIME_PROPS_1[_a];
|
|
18
|
-
var optionsProp = options[prop];
|
|
19
|
-
var formatProp = format[prop];
|
|
20
|
-
if (optionsProp === undefined && formatProp !== undefined) {
|
|
21
|
-
score -= additionPenalty;
|
|
22
|
-
}
|
|
23
|
-
else if (optionsProp !== undefined && formatProp === undefined) {
|
|
24
|
-
score -= removalPenalty;
|
|
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
|
-
}
|
|
75
|
-
else if (optionsProp !== formatProp) {
|
|
76
|
-
var values = void 0;
|
|
77
|
-
if (prop === 'fractionalSecondDigits') {
|
|
78
|
-
values = [1, 2, 3];
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
values = ['2-digit', 'numeric', 'narrow', 'short', 'long'];
|
|
82
|
-
}
|
|
83
|
-
var optionsPropIndex = values.indexOf(optionsProp);
|
|
84
|
-
var formatPropIndex = values.indexOf(formatProp);
|
|
85
|
-
var delta = Math.max(-2, Math.min(formatPropIndex - optionsPropIndex, 2));
|
|
86
|
-
if (delta === 2) {
|
|
87
|
-
score -= longMorePenalty;
|
|
88
|
-
}
|
|
89
|
-
else if (delta === 1) {
|
|
90
|
-
score -= shortMorePenalty;
|
|
91
|
-
}
|
|
92
|
-
else if (delta === -1) {
|
|
93
|
-
score -= shortLessPenalty;
|
|
94
|
-
}
|
|
95
|
-
else if (delta === -2) {
|
|
96
|
-
score -= longLessPenalty;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (score > bestScore) {
|
|
101
|
-
bestScore = score;
|
|
102
|
-
bestFormat = format;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return __assign({}, bestFormat);
|
|
106
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Formats } from '@formatjs/ecma402-abstract';
|
|
2
|
-
/**
|
|
3
|
-
* Credit: https://github.com/andyearnshaw/Intl.js/blob/0958dc1ad8153f1056653ea22b8208f0df289a4e/src/12.datetimeformat.js#L611
|
|
4
|
-
* with some modifications
|
|
5
|
-
* @param options
|
|
6
|
-
* @param format
|
|
7
|
-
*/
|
|
8
|
-
export declare function bestFitFormatMatcherScore(options: Intl.DateTimeFormatOptions, format: Formats): number;
|
|
9
|
-
/**
|
|
10
|
-
* https://tc39.es/ecma402/#sec-bestfitformatmatcher
|
|
11
|
-
* Just alias to basic for now
|
|
12
|
-
* @param options
|
|
13
|
-
* @param formats
|
|
14
|
-
* @param implDetails Implementation details
|
|
15
|
-
*/
|
|
16
|
-
export declare function BestFitFormatMatcher(options: Intl.DateTimeFormatOptions, formats: Formats[]): Formats;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
|
-
import { invariant } from '@formatjs/ecma402-abstract';
|
|
3
|
-
import { processDateTimePattern } from './skeleton';
|
|
4
|
-
import { DATE_TIME_PROPS, additionPenalty, differentNumericTypePenalty, longLessPenalty, longMorePenalty, removalPenalty, shortLessPenalty, shortMorePenalty, } from './utils';
|
|
5
|
-
function isNumericType(t) {
|
|
6
|
-
return t === 'numeric' || t === '2-digit';
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Credit: https://github.com/andyearnshaw/Intl.js/blob/0958dc1ad8153f1056653ea22b8208f0df289a4e/src/12.datetimeformat.js#L611
|
|
10
|
-
* with some modifications
|
|
11
|
-
* @param options
|
|
12
|
-
* @param format
|
|
13
|
-
*/
|
|
14
|
-
export function bestFitFormatMatcherScore(options, format) {
|
|
15
|
-
var score = 0;
|
|
16
|
-
if (options.hour12 && !format.hour12) {
|
|
17
|
-
score -= removalPenalty;
|
|
18
|
-
}
|
|
19
|
-
else if (!options.hour12 && format.hour12) {
|
|
20
|
-
score -= additionPenalty;
|
|
21
|
-
}
|
|
22
|
-
for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
|
|
23
|
-
var prop = DATE_TIME_PROPS_1[_i];
|
|
24
|
-
var optionsProp = options[prop];
|
|
25
|
-
var formatProp = format[prop];
|
|
26
|
-
if (optionsProp === undefined && formatProp !== undefined) {
|
|
27
|
-
score -= additionPenalty;
|
|
28
|
-
}
|
|
29
|
-
else if (optionsProp !== undefined && formatProp === undefined) {
|
|
30
|
-
score -= removalPenalty;
|
|
31
|
-
}
|
|
32
|
-
else if (optionsProp !== formatProp) {
|
|
33
|
-
// extra penalty for numeric vs non-numeric
|
|
34
|
-
if (isNumericType(optionsProp) !==
|
|
35
|
-
isNumericType(formatProp)) {
|
|
36
|
-
score -= differentNumericTypePenalty;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
var values = ['2-digit', 'numeric', 'narrow', 'short', 'long'];
|
|
40
|
-
var optionsPropIndex = values.indexOf(optionsProp);
|
|
41
|
-
var formatPropIndex = values.indexOf(formatProp);
|
|
42
|
-
var delta = Math.max(-2, Math.min(formatPropIndex - optionsPropIndex, 2));
|
|
43
|
-
if (delta === 2) {
|
|
44
|
-
score -= longMorePenalty;
|
|
45
|
-
}
|
|
46
|
-
else if (delta === 1) {
|
|
47
|
-
score -= shortMorePenalty;
|
|
48
|
-
}
|
|
49
|
-
else if (delta === -1) {
|
|
50
|
-
score -= shortLessPenalty;
|
|
51
|
-
}
|
|
52
|
-
else if (delta === -2) {
|
|
53
|
-
score -= longLessPenalty;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return score;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* https://tc39.es/ecma402/#sec-bestfitformatmatcher
|
|
62
|
-
* Just alias to basic for now
|
|
63
|
-
* @param options
|
|
64
|
-
* @param formats
|
|
65
|
-
* @param implDetails Implementation details
|
|
66
|
-
*/
|
|
67
|
-
export function BestFitFormatMatcher(options, formats) {
|
|
68
|
-
var bestScore = -Infinity;
|
|
69
|
-
var bestFormat = formats[0];
|
|
70
|
-
invariant(Array.isArray(formats), 'formats should be a list of things');
|
|
71
|
-
for (var _i = 0, formats_1 = formats; _i < formats_1.length; _i++) {
|
|
72
|
-
var format = formats_1[_i];
|
|
73
|
-
var score = bestFitFormatMatcherScore(options, format);
|
|
74
|
-
if (score > bestScore) {
|
|
75
|
-
bestScore = score;
|
|
76
|
-
bestFormat = format;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
var skeletonFormat = __assign({}, bestFormat);
|
|
80
|
-
var patternFormat = { rawPattern: bestFormat.rawPattern };
|
|
81
|
-
processDateTimePattern(bestFormat.rawPattern, patternFormat);
|
|
82
|
-
// Kinda following https://github.com/unicode-org/icu/blob/dd50e38f459d84e9bf1b0c618be8483d318458ad/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java
|
|
83
|
-
// Method adjustFieldTypes
|
|
84
|
-
for (var prop in skeletonFormat) {
|
|
85
|
-
var skeletonValue = skeletonFormat[prop];
|
|
86
|
-
var patternValue = patternFormat[prop];
|
|
87
|
-
var requestedValue = options[prop];
|
|
88
|
-
// Don't mess with minute/second or we can get in the situation of
|
|
89
|
-
// 7:0:0 which is weird
|
|
90
|
-
if (prop === 'minute' || prop === 'second') {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
// Nothing to do here
|
|
94
|
-
if (!requestedValue) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
// https://unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons
|
|
98
|
-
// Looks like we should not convert numeric to alphabetic but the other way
|
|
99
|
-
// around is ok
|
|
100
|
-
if (isNumericType(patternValue) &&
|
|
101
|
-
!isNumericType(requestedValue)) {
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (skeletonValue === requestedValue) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
patternFormat[prop] = requestedValue;
|
|
108
|
-
}
|
|
109
|
-
// Copy those over
|
|
110
|
-
patternFormat.pattern = skeletonFormat.pattern;
|
|
111
|
-
patternFormat.pattern12 = skeletonFormat.pattern12;
|
|
112
|
-
patternFormat.skeleton = skeletonFormat.skeleton;
|
|
113
|
-
patternFormat.rangePatterns = skeletonFormat.rangePatterns;
|
|
114
|
-
patternFormat.rangePatterns12 = skeletonFormat.rangePatterns12;
|
|
115
|
-
return patternFormat;
|
|
116
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { DateTimeFormatLocaleInternalData, Formats } from '@formatjs/ecma402-abstract';
|
|
2
|
-
export declare function DateTimeStyleFormat(dateStyle: Intl.DateTimeFormatOptions['dateStyle'], timeStyle: Intl.DateTimeFormatOptions['timeStyle'], dataLocaleData: DateTimeFormatLocaleInternalData): Formats;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { invariant, } from '@formatjs/ecma402-abstract';
|
|
2
|
-
export function DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData) {
|
|
3
|
-
var dateFormat, timeFormat;
|
|
4
|
-
if (timeStyle !== undefined) {
|
|
5
|
-
invariant(timeStyle === 'full' ||
|
|
6
|
-
timeStyle === 'long' ||
|
|
7
|
-
timeStyle === 'medium' ||
|
|
8
|
-
timeStyle === 'short', 'invalid timeStyle');
|
|
9
|
-
timeFormat = dataLocaleData.timeFormat[timeStyle];
|
|
10
|
-
}
|
|
11
|
-
if (dateStyle !== undefined) {
|
|
12
|
-
invariant(dateStyle === 'full' ||
|
|
13
|
-
dateStyle === 'long' ||
|
|
14
|
-
dateStyle === 'medium' ||
|
|
15
|
-
dateStyle === 'short', 'invalid dateStyle');
|
|
16
|
-
dateFormat = dataLocaleData.dateFormat[dateStyle];
|
|
17
|
-
}
|
|
18
|
-
if (dateStyle !== undefined && timeStyle !== undefined) {
|
|
19
|
-
var format = {};
|
|
20
|
-
for (var field in dateFormat) {
|
|
21
|
-
if (field !== 'pattern') {
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
format[field] = dateFormat[field];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
for (var field in timeFormat) {
|
|
27
|
-
if (field !== 'pattern' && field !== 'pattern12') {
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
format[field] = timeFormat[field];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
var connector = dataLocaleData.dateTimeFormat[dateStyle];
|
|
33
|
-
var pattern = connector
|
|
34
|
-
.replace('{0}', timeFormat.pattern)
|
|
35
|
-
.replace('{1}', dateFormat.pattern);
|
|
36
|
-
format.pattern = pattern;
|
|
37
|
-
if ('pattern12' in timeFormat) {
|
|
38
|
-
var pattern12 = connector
|
|
39
|
-
.replace('{0}', timeFormat.pattern12)
|
|
40
|
-
.replace('{1}', dateFormat.pattern);
|
|
41
|
-
format.pattern12 = pattern12;
|
|
42
|
-
}
|
|
43
|
-
return format;
|
|
44
|
-
}
|
|
45
|
-
if (timeStyle !== undefined) {
|
|
46
|
-
return timeFormat;
|
|
47
|
-
}
|
|
48
|
-
invariant(dateStyle !== undefined, 'dateStyle should not be undefined');
|
|
49
|
-
return dateFormat;
|
|
50
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DateTimeFormat } from '@formatjs/ecma402-abstract';
|
|
2
|
-
import Decimal from 'decimal.js';
|
|
3
|
-
import { PartitionDateTimePattern } from './PartitionDateTimePattern';
|
|
4
|
-
/**
|
|
5
|
-
* https://tc39.es/ecma402/#sec-formatdatetime
|
|
6
|
-
* @param dtf DateTimeFormat
|
|
7
|
-
* @param x
|
|
8
|
-
*/
|
|
9
|
-
export declare function FormatDateTime(dtf: Intl.DateTimeFormat | DateTimeFormat, x: Decimal, implDetails: Parameters<typeof PartitionDateTimePattern>[2]): string;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PartitionDateTimePattern } from './PartitionDateTimePattern';
|
|
2
|
-
/**
|
|
3
|
-
* https://tc39.es/ecma402/#sec-formatdatetime
|
|
4
|
-
* @param dtf DateTimeFormat
|
|
5
|
-
* @param x
|
|
6
|
-
*/
|
|
7
|
-
export function FormatDateTime(dtf, x, implDetails) {
|
|
8
|
-
var parts = PartitionDateTimePattern(dtf, x, implDetails);
|
|
9
|
-
var result = '';
|
|
10
|
-
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
11
|
-
var part = parts_1[_i];
|
|
12
|
-
result += part.value;
|
|
13
|
-
}
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DateTimeFormat, DateTimeFormatLocaleInternalData, IntlDateTimeFormatInternal, IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
|
|
2
|
-
import Decimal from 'decimal.js';
|
|
3
|
-
import { ToLocalTimeImplDetails } from './ToLocalTime';
|
|
4
|
-
export interface FormatDateTimePatternImplDetails {
|
|
5
|
-
getInternalSlots(dtf: Intl.DateTimeFormat | DateTimeFormat): IntlDateTimeFormatInternal;
|
|
6
|
-
localeData: Record<string, DateTimeFormatLocaleInternalData>;
|
|
7
|
-
getDefaultTimeZone(): string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
11
|
-
* @param dtf
|
|
12
|
-
* @param x
|
|
13
|
-
*/
|
|
14
|
-
export declare function FormatDateTimePattern(dtf: Intl.DateTimeFormat | DateTimeFormat, patternParts: IntlDateTimeFormatPart[], x: Decimal, { getInternalSlots, localeData, getDefaultTimeZone, tzData, }: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): IntlDateTimeFormatPart[];
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { TimeClip, createMemoizedNumberFormat, } from '@formatjs/ecma402-abstract';
|
|
2
|
-
import Decimal from 'decimal.js';
|
|
3
|
-
import { ToLocalTime } from './ToLocalTime';
|
|
4
|
-
import { DATE_TIME_PROPS } from './utils';
|
|
5
|
-
function pad(n) {
|
|
6
|
-
if (n < 10) {
|
|
7
|
-
return "0".concat(n);
|
|
8
|
-
}
|
|
9
|
-
return String(n);
|
|
10
|
-
}
|
|
11
|
-
function offsetToGmtString(gmtFormat, hourFormat, offsetInMs, style) {
|
|
12
|
-
var offsetInMinutes = Math.floor(offsetInMs / 60000);
|
|
13
|
-
var mins = Math.abs(offsetInMinutes) % 60;
|
|
14
|
-
var hours = Math.floor(Math.abs(offsetInMinutes) / 60);
|
|
15
|
-
var _a = hourFormat.split(';'), positivePattern = _a[0], negativePattern = _a[1];
|
|
16
|
-
var offsetStr = '';
|
|
17
|
-
var pattern = offsetInMs < 0 ? negativePattern : positivePattern;
|
|
18
|
-
if (style === 'long') {
|
|
19
|
-
offsetStr = pattern
|
|
20
|
-
.replace('HH', pad(hours))
|
|
21
|
-
.replace('H', String(hours))
|
|
22
|
-
.replace('mm', pad(mins))
|
|
23
|
-
.replace('m', String(mins));
|
|
24
|
-
}
|
|
25
|
-
else if (mins || hours) {
|
|
26
|
-
if (!mins) {
|
|
27
|
-
pattern = pattern.replace(/:?m+/, '');
|
|
28
|
-
}
|
|
29
|
-
offsetStr = pattern.replace(/H+/, String(hours)).replace(/m+/, String(mins));
|
|
30
|
-
}
|
|
31
|
-
return gmtFormat.replace('{0}', offsetStr);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
35
|
-
* @param dtf
|
|
36
|
-
* @param x
|
|
37
|
-
*/
|
|
38
|
-
export function FormatDateTimePattern(dtf, patternParts, x, _a) {
|
|
39
|
-
var getInternalSlots = _a.getInternalSlots, localeData = _a.localeData, getDefaultTimeZone = _a.getDefaultTimeZone, tzData = _a.tzData;
|
|
40
|
-
x = TimeClip(x);
|
|
41
|
-
/** IMPL START */
|
|
42
|
-
var internalSlots = getInternalSlots(dtf);
|
|
43
|
-
var dataLocale = internalSlots.dataLocale;
|
|
44
|
-
var dataLocaleData = localeData[dataLocale];
|
|
45
|
-
/** IMPL END */
|
|
46
|
-
var locale = internalSlots.locale;
|
|
47
|
-
var nfOptions = Object.create(null);
|
|
48
|
-
nfOptions.useGrouping = false;
|
|
49
|
-
var nf = createMemoizedNumberFormat(locale, nfOptions);
|
|
50
|
-
var nf2Options = Object.create(null);
|
|
51
|
-
nf2Options.minimumIntegerDigits = 2;
|
|
52
|
-
nf2Options.useGrouping = false;
|
|
53
|
-
var nf2 = createMemoizedNumberFormat(locale, nf2Options);
|
|
54
|
-
var fractionalSecondDigits = internalSlots.fractionalSecondDigits;
|
|
55
|
-
var nf3;
|
|
56
|
-
if (fractionalSecondDigits !== undefined) {
|
|
57
|
-
var nf3Options = Object.create(null);
|
|
58
|
-
nf3Options.minimumIntegerDigits = fractionalSecondDigits;
|
|
59
|
-
nf3Options.useGrouping = false;
|
|
60
|
-
nf3 = createMemoizedNumberFormat(locale, nf3Options);
|
|
61
|
-
}
|
|
62
|
-
var tm = ToLocalTime(x,
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
|
|
65
|
-
var result = [];
|
|
66
|
-
for (var _i = 0, patternParts_1 = patternParts; _i < patternParts_1.length; _i++) {
|
|
67
|
-
var patternPart = patternParts_1[_i];
|
|
68
|
-
var p = patternPart.type;
|
|
69
|
-
if (p === 'literal') {
|
|
70
|
-
result.push({
|
|
71
|
-
type: 'literal',
|
|
72
|
-
value: patternPart.value,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
else if (p === 'fractionalSecondDigits') {
|
|
76
|
-
var v = new Decimal(tm.millisecond)
|
|
77
|
-
.times(10)
|
|
78
|
-
.pow((fractionalSecondDigits || 0) - 3)
|
|
79
|
-
.floor()
|
|
80
|
-
.toNumber();
|
|
81
|
-
result.push({
|
|
82
|
-
type: 'fractionalSecond',
|
|
83
|
-
value: nf3.format(v),
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
else if (p === 'dayPeriod') {
|
|
87
|
-
var f = internalSlots.dayPeriod;
|
|
88
|
-
// @ts-ignore
|
|
89
|
-
var fv = tm[f];
|
|
90
|
-
result.push({ type: p, value: fv });
|
|
91
|
-
}
|
|
92
|
-
else if (p === 'timeZoneName') {
|
|
93
|
-
var f = internalSlots.timeZoneName;
|
|
94
|
-
var fv = void 0;
|
|
95
|
-
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
|
|
96
|
-
var timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
97
|
-
var timeZoneData = timeZoneName[timeZone];
|
|
98
|
-
if (timeZoneData && timeZoneData[f]) {
|
|
99
|
-
fv = timeZoneData[f][+tm.inDST];
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
// Fallback to gmtFormat
|
|
103
|
-
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
104
|
-
}
|
|
105
|
-
result.push({ type: p, value: fv });
|
|
106
|
-
}
|
|
107
|
-
else if (DATE_TIME_PROPS.indexOf(p) > -1) {
|
|
108
|
-
var fv = '';
|
|
109
|
-
var f = internalSlots[p];
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
var v = tm[p];
|
|
112
|
-
if (p === 'year' && v <= 0) {
|
|
113
|
-
v = 1 - v;
|
|
114
|
-
}
|
|
115
|
-
if (p === 'month') {
|
|
116
|
-
v++;
|
|
117
|
-
}
|
|
118
|
-
var hourCycle = internalSlots.hourCycle;
|
|
119
|
-
if (p === 'hour' && (hourCycle === 'h11' || hourCycle === 'h12')) {
|
|
120
|
-
v = v % 12;
|
|
121
|
-
if (v === 0 && hourCycle === 'h12') {
|
|
122
|
-
v = 12;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (p === 'hour' && hourCycle === 'h24') {
|
|
126
|
-
if (v === 0) {
|
|
127
|
-
v = 24;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (f === 'numeric') {
|
|
131
|
-
fv = nf.format(v);
|
|
132
|
-
}
|
|
133
|
-
else if (f === '2-digit') {
|
|
134
|
-
fv = nf2.format(v);
|
|
135
|
-
if (fv.length > 2) {
|
|
136
|
-
fv = fv.slice(fv.length - 2, fv.length);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else if (f === 'narrow' || f === 'short' || f === 'long') {
|
|
140
|
-
if (p === 'era') {
|
|
141
|
-
fv = dataLocaleData[p][f][v];
|
|
142
|
-
}
|
|
143
|
-
else if (p === 'month') {
|
|
144
|
-
fv = dataLocaleData.month[f][v - 1];
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
fv = dataLocaleData[p][f][v];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
result.push({
|
|
151
|
-
type: p,
|
|
152
|
-
value: fv,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
else if (p === 'ampm') {
|
|
156
|
-
var v = tm.hour;
|
|
157
|
-
var fv = void 0;
|
|
158
|
-
if (v > 11) {
|
|
159
|
-
fv = dataLocaleData.pm;
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
fv = dataLocaleData.am;
|
|
163
|
-
}
|
|
164
|
-
result.push({
|
|
165
|
-
type: 'dayPeriod',
|
|
166
|
-
value: fv,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
else if (p === 'relatedYear') {
|
|
170
|
-
var v = tm.relatedYear;
|
|
171
|
-
// @ts-ignore
|
|
172
|
-
var fv = nf.format(v);
|
|
173
|
-
result.push({
|
|
174
|
-
// @ts-ignore TODO: Fix TS type
|
|
175
|
-
type: 'relatedYear',
|
|
176
|
-
value: fv,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
else if (p === 'yearName') {
|
|
180
|
-
var v = tm.yearName;
|
|
181
|
-
// @ts-ignore
|
|
182
|
-
var fv = nf.format(v);
|
|
183
|
-
result.push({
|
|
184
|
-
// @ts-ignore TODO: Fix TS type
|
|
185
|
-
type: 'yearName',
|
|
186
|
-
value: fv,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return result;
|
|
191
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern';
|
|
3
|
-
import { ToLocalTimeImplDetails } from './ToLocalTime';
|
|
4
|
-
export declare function FormatDateTimeRange(dtf: Intl.DateTimeFormat, x: Decimal, y: Decimal, implDetails: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): string;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PartitionDateTimeRangePattern } from './PartitionDateTimeRangePattern';
|
|
2
|
-
export function FormatDateTimeRange(dtf, x, y, implDetails) {
|
|
3
|
-
var parts = PartitionDateTimeRangePattern(dtf, x, y, implDetails);
|
|
4
|
-
var result = '';
|
|
5
|
-
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
6
|
-
var part = parts_1[_i];
|
|
7
|
-
result += part.value;
|
|
8
|
-
}
|
|
9
|
-
return result;
|
|
10
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
|
|
2
|
-
import { Decimal } from 'decimal.js';
|
|
3
|
-
import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern';
|
|
4
|
-
import { ToLocalTimeImplDetails } from './ToLocalTime';
|
|
5
|
-
export declare function FormatDateTimeRangeToParts(dtf: Intl.DateTimeFormat, x: Decimal, y: Decimal, implDetails: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): IntlDateTimeFormatPart[];
|