@formatjs/ecma402-abstract 1.0.3 → 1.2.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/262.d.ts +79 -0
- package/262.d.ts.map +1 -0
- package/262.js +336 -0
- package/_validate_dist-base_options.optionsvalid.d.ts +2 -1
- package/_validate_dist-esm_options.optionsvalid.d.ts +2 -1
- package/index.d.ts +33 -0
- package/index.d.ts.map +1 -1
- package/index.js +52 -11
- package/lib/262.d.ts +79 -0
- package/lib/262.d.ts.map +1 -0
- package/lib/262.js +312 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +33 -0
- package/lib/src/CanonicalizeLocaleList.d.ts +6 -0
- package/lib/src/CanonicalizeLocaleList.d.ts.map +1 -0
- package/lib/src/CanonicalizeLocaleList.js +8 -0
- package/lib/src/CanonicalizeTimeZoneName.d.ts +9 -0
- package/lib/src/CanonicalizeTimeZoneName.d.ts.map +1 -0
- package/lib/src/CanonicalizeTimeZoneName.js +17 -0
- package/lib/src/DateTimeFormat/BasicFormatMatcher.d.ts +8 -0
- package/lib/src/DateTimeFormat/BasicFormatMatcher.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/BasicFormatMatcher.js +61 -0
- package/lib/src/DateTimeFormat/BestFitFormatMatcher.d.ts +17 -0
- package/lib/src/DateTimeFormat/BestFitFormatMatcher.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/BestFitFormatMatcher.js +119 -0
- package/lib/src/DateTimeFormat/DateTimeStyleFormat.d.ts +3 -0
- package/lib/src/DateTimeFormat/DateTimeStyleFormat.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/DateTimeStyleFormat.js +50 -0
- package/lib/src/DateTimeFormat/FormatDateTime.d.ts +8 -0
- package/lib/src/DateTimeFormat/FormatDateTime.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/FormatDateTime.js +15 -0
- package/lib/src/DateTimeFormat/FormatDateTimeToParts.d.ts +10 -0
- package/lib/src/DateTimeFormat/FormatDateTimeToParts.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/FormatDateTimeToParts.js +21 -0
- package/lib/src/DateTimeFormat/InitializeDateTimeFormat.d.ts +18 -0
- package/lib/src/DateTimeFormat/InitializeDateTimeFormat.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/InitializeDateTimeFormat.js +163 -0
- package/lib/src/DateTimeFormat/PartitionDateTimePattern.d.ts +13 -0
- package/lib/src/DateTimeFormat/PartitionDateTimePattern.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/PartitionDateTimePattern.js +176 -0
- package/lib/src/DateTimeFormat/ToDateTimeOptions.d.ts +9 -0
- package/lib/src/DateTimeFormat/ToDateTimeOptions.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/ToDateTimeOptions.js +57 -0
- package/lib/src/DateTimeFormat/ToLocalTime.d.ts +24 -0
- package/lib/src/DateTimeFormat/ToLocalTime.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/ToLocalTime.js +49 -0
- package/lib/src/DateTimeFormat/skeleton.d.ts +9 -0
- package/lib/src/DateTimeFormat/skeleton.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/skeleton.js +163 -0
- package/lib/src/DateTimeFormat/utils.d.ts +10 -0
- package/lib/src/DateTimeFormat/utils.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/utils.js +18 -0
- package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts +2 -0
- package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts.map +1 -0
- package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.js +33 -0
- package/lib/src/GetOption.js +1 -1
- package/lib/src/IsValidTimeZoneName.d.ts +10 -0
- package/lib/src/IsValidTimeZoneName.d.ts.map +1 -0
- package/lib/src/IsValidTimeZoneName.js +11 -0
- package/lib/src/NumberFormat/ComputeExponent.d.ts +12 -0
- package/lib/src/NumberFormat/ComputeExponent.d.ts.map +1 -0
- package/lib/src/NumberFormat/ComputeExponent.js +39 -0
- package/lib/src/NumberFormat/ComputeExponentForMagnitude.d.ts +10 -0
- package/lib/src/NumberFormat/ComputeExponentForMagnitude.d.ts.map +1 -0
- package/lib/src/NumberFormat/ComputeExponentForMagnitude.js +60 -0
- package/lib/src/NumberFormat/CurrencyDigits.d.ts +7 -0
- package/lib/src/NumberFormat/CurrencyDigits.d.ts.map +1 -0
- package/lib/src/NumberFormat/CurrencyDigits.js +10 -0
- package/lib/src/NumberFormat/FormatNumericToParts.d.ts +5 -0
- package/lib/src/NumberFormat/FormatNumericToParts.d.ts.map +1 -0
- package/lib/src/NumberFormat/FormatNumericToParts.js +14 -0
- package/lib/src/NumberFormat/FormatNumericToString.js +1 -1
- package/lib/src/NumberFormat/InitializeNumberFormat.d.ts +13 -0
- package/lib/src/NumberFormat/InitializeNumberFormat.d.ts.map +1 -0
- package/lib/src/NumberFormat/InitializeNumberFormat.js +71 -0
- package/lib/src/NumberFormat/PartitionNumberPattern.d.ts +8 -0
- package/lib/src/NumberFormat/PartitionNumberPattern.d.ts.map +1 -0
- package/lib/src/NumberFormat/PartitionNumberPattern.js +74 -0
- package/lib/src/NumberFormat/SetNumberFormatUnitOptions.d.ts +8 -0
- package/lib/src/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +1 -0
- package/lib/src/NumberFormat/SetNumberFormatUnitOptions.js +39 -0
- package/lib/src/NumberFormat/digit-mapping.json +1 -0
- package/lib/src/NumberFormat/format_to_parts.d.ts +22 -0
- package/lib/src/NumberFormat/format_to_parts.d.ts.map +1 -0
- package/lib/src/NumberFormat/format_to_parts.js +421 -0
- package/lib/src/PluralRules/GetOperands.d.ts +32 -0
- package/lib/src/PluralRules/GetOperands.d.ts.map +1 -0
- package/lib/src/PluralRules/GetOperands.js +47 -0
- package/lib/src/PluralRules/InitializePluralRules.d.ts +9 -0
- package/lib/src/PluralRules/InitializePluralRules.d.ts.map +1 -0
- package/lib/src/PluralRules/InitializePluralRules.js +20 -0
- package/lib/src/PluralRules/ResolvePlural.d.ts +13 -0
- package/lib/src/PluralRules/ResolvePlural.d.ts.map +1 -0
- package/lib/src/PluralRules/ResolvePlural.js +25 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTime.d.ts +5 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTime.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTime.js +10 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts +5 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.js +18 -0
- package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts +9 -0
- package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.js +32 -0
- package/lib/src/RelativeTimeFormat/MakePartsList.d.ts +3 -0
- package/lib/src/RelativeTimeFormat/MakePartsList.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/MakePartsList.js +27 -0
- package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts +5 -0
- package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.js +54 -0
- package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts +7 -0
- package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.js +36 -0
- package/lib/src/SupportedLocales.js +1 -1
- package/lib/src/data.js +1 -1
- package/lib/types/core.js +1 -0
- package/lib/types/date-time.d.ts +112 -0
- package/lib/types/date-time.d.ts.map +1 -0
- package/lib/types/date-time.js +1 -0
- package/lib/types/displaynames.js +1 -0
- package/lib/types/list.js +1 -0
- package/lib/types/number.d.ts +44 -0
- package/lib/types/number.d.ts.map +1 -1
- package/lib/types/number.js +1 -0
- package/lib/types/plural-rules.d.ts +6 -0
- package/lib/types/plural-rules.d.ts.map +1 -1
- package/lib/types/plural-rules.js +1 -0
- package/lib/types/relative-time.d.ts +63 -0
- package/lib/types/relative-time.d.ts.map +1 -1
- package/lib/types/relative-time.js +1 -0
- package/package.json +2 -6
- package/src/CanonicalizeLocaleList.d.ts +6 -0
- package/src/CanonicalizeLocaleList.d.ts.map +1 -0
- package/src/CanonicalizeLocaleList.js +12 -0
- package/src/CanonicalizeTimeZoneName.d.ts +9 -0
- package/src/CanonicalizeTimeZoneName.d.ts.map +1 -0
- package/src/CanonicalizeTimeZoneName.js +21 -0
- package/src/DateTimeFormat/BasicFormatMatcher.d.ts +8 -0
- package/src/DateTimeFormat/BasicFormatMatcher.d.ts.map +1 -0
- package/src/DateTimeFormat/BasicFormatMatcher.js +65 -0
- package/src/DateTimeFormat/BestFitFormatMatcher.d.ts +17 -0
- package/src/DateTimeFormat/BestFitFormatMatcher.d.ts.map +1 -0
- package/src/DateTimeFormat/BestFitFormatMatcher.js +124 -0
- package/src/DateTimeFormat/DateTimeStyleFormat.d.ts +3 -0
- package/src/DateTimeFormat/DateTimeStyleFormat.d.ts.map +1 -0
- package/src/DateTimeFormat/DateTimeStyleFormat.js +54 -0
- package/src/DateTimeFormat/FormatDateTime.d.ts +8 -0
- package/src/DateTimeFormat/FormatDateTime.d.ts.map +1 -0
- package/src/DateTimeFormat/FormatDateTime.js +19 -0
- package/src/DateTimeFormat/FormatDateTimeToParts.d.ts +10 -0
- package/src/DateTimeFormat/FormatDateTimeToParts.d.ts.map +1 -0
- package/src/DateTimeFormat/FormatDateTimeToParts.js +25 -0
- package/src/DateTimeFormat/InitializeDateTimeFormat.d.ts +18 -0
- package/src/DateTimeFormat/InitializeDateTimeFormat.d.ts.map +1 -0
- package/src/DateTimeFormat/InitializeDateTimeFormat.js +167 -0
- package/src/DateTimeFormat/PartitionDateTimePattern.d.ts +13 -0
- package/src/DateTimeFormat/PartitionDateTimePattern.d.ts.map +1 -0
- package/src/DateTimeFormat/PartitionDateTimePattern.js +180 -0
- package/src/DateTimeFormat/ToDateTimeOptions.d.ts +9 -0
- package/src/DateTimeFormat/ToDateTimeOptions.d.ts.map +1 -0
- package/src/DateTimeFormat/ToDateTimeOptions.js +61 -0
- package/src/DateTimeFormat/ToLocalTime.d.ts +24 -0
- package/src/DateTimeFormat/ToLocalTime.d.ts.map +1 -0
- package/src/DateTimeFormat/ToLocalTime.js +53 -0
- package/src/DateTimeFormat/skeleton.d.ts +9 -0
- package/src/DateTimeFormat/skeleton.d.ts.map +1 -0
- package/src/DateTimeFormat/skeleton.js +167 -0
- package/src/DateTimeFormat/utils.d.ts +10 -0
- package/src/DateTimeFormat/utils.d.ts.map +1 -0
- package/src/DateTimeFormat/utils.js +21 -0
- package/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts +2 -0
- package/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts.map +1 -0
- package/src/DisplayNames/CanonicalCodeForDisplayNames.js +37 -0
- package/src/GetOption.js +2 -5
- package/src/IsValidTimeZoneName.d.ts +10 -0
- package/src/IsValidTimeZoneName.d.ts.map +1 -0
- package/src/IsValidTimeZoneName.js +15 -0
- package/src/NumberFormat/ComputeExponent.d.ts +12 -0
- package/src/NumberFormat/ComputeExponent.d.ts.map +1 -0
- package/src/NumberFormat/ComputeExponent.js +43 -0
- package/src/NumberFormat/ComputeExponentForMagnitude.d.ts +10 -0
- package/src/NumberFormat/ComputeExponentForMagnitude.d.ts.map +1 -0
- package/src/NumberFormat/ComputeExponentForMagnitude.js +64 -0
- package/src/NumberFormat/CurrencyDigits.d.ts +7 -0
- package/src/NumberFormat/CurrencyDigits.d.ts.map +1 -0
- package/src/NumberFormat/CurrencyDigits.js +14 -0
- package/src/NumberFormat/FormatNumericToParts.d.ts +5 -0
- package/src/NumberFormat/FormatNumericToParts.d.ts.map +1 -0
- package/src/NumberFormat/FormatNumericToParts.js +18 -0
- package/src/NumberFormat/FormatNumericToString.js +2 -5
- package/src/NumberFormat/InitializeNumberFormat.d.ts +13 -0
- package/src/NumberFormat/InitializeNumberFormat.d.ts.map +1 -0
- package/src/NumberFormat/InitializeNumberFormat.js +75 -0
- package/src/NumberFormat/PartitionNumberPattern.d.ts +8 -0
- package/src/NumberFormat/PartitionNumberPattern.d.ts.map +1 -0
- package/src/NumberFormat/PartitionNumberPattern.js +81 -0
- package/src/NumberFormat/SetNumberFormatUnitOptions.d.ts +8 -0
- package/src/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +1 -0
- package/src/NumberFormat/SetNumberFormatUnitOptions.js +43 -0
- package/src/NumberFormat/digit-mapping.json +1 -0
- package/src/NumberFormat/format_to_parts.d.ts +22 -0
- package/src/NumberFormat/format_to_parts.d.ts.map +1 -0
- package/src/NumberFormat/format_to_parts.js +443 -0
- package/src/PluralRules/GetOperands.d.ts +32 -0
- package/src/PluralRules/GetOperands.d.ts.map +1 -0
- package/src/PluralRules/GetOperands.js +51 -0
- package/src/PluralRules/InitializePluralRules.d.ts +9 -0
- package/src/PluralRules/InitializePluralRules.d.ts.map +1 -0
- package/src/PluralRules/InitializePluralRules.js +24 -0
- package/src/PluralRules/ResolvePlural.d.ts +13 -0
- package/src/PluralRules/ResolvePlural.d.ts.map +1 -0
- package/src/PluralRules/ResolvePlural.js +29 -0
- package/src/RelativeTimeFormat/FormatRelativeTime.d.ts +5 -0
- package/src/RelativeTimeFormat/FormatRelativeTime.d.ts.map +1 -0
- package/src/RelativeTimeFormat/FormatRelativeTime.js +14 -0
- package/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts +5 -0
- package/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts.map +1 -0
- package/src/RelativeTimeFormat/FormatRelativeTimeToParts.js +22 -0
- package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts +9 -0
- package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts.map +1 -0
- package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.js +36 -0
- package/src/RelativeTimeFormat/MakePartsList.d.ts +3 -0
- package/src/RelativeTimeFormat/MakePartsList.d.ts.map +1 -0
- package/src/RelativeTimeFormat/MakePartsList.js +31 -0
- package/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts +5 -0
- package/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts.map +1 -0
- package/src/RelativeTimeFormat/PartitionRelativeTimePattern.js +58 -0
- package/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts +7 -0
- package/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts.map +1 -0
- package/src/RelativeTimeFormat/SingularRelativeTimeUnit.js +40 -0
- package/src/SupportedLocales.js +2 -5
- package/src/data.js +1 -1
- package/types/date-time.d.ts +112 -0
- package/types/date-time.d.ts.map +1 -0
- package/types/date-time.js +2 -0
- package/types/number.d.ts +44 -0
- package/types/number.d.ts.map +1 -1
- package/types/plural-rules.d.ts +6 -0
- package/types/plural-rules.d.ts.map +1 -1
- package/types/relative-time.d.ts +63 -0
- package/types/relative-time.d.ts.map +1 -1
- package/types.js +1 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartitionDateTimePattern = void 0;
|
|
4
|
+
var _262_1 = require("../../262");
|
|
5
|
+
var PartitionPattern_1 = require("../PartitionPattern");
|
|
6
|
+
var utils_1 = require("./utils");
|
|
7
|
+
var ToLocalTime_1 = require("./ToLocalTime");
|
|
8
|
+
function pad(n) {
|
|
9
|
+
if (n < 10) {
|
|
10
|
+
return "0" + n;
|
|
11
|
+
}
|
|
12
|
+
return String(n);
|
|
13
|
+
}
|
|
14
|
+
function offsetToGmtString(gmtFormat, hourFormat, offsetInMs, style) {
|
|
15
|
+
var offsetInMinutes = Math.floor(offsetInMs / 60000);
|
|
16
|
+
var mins = Math.abs(offsetInMinutes) % 60;
|
|
17
|
+
var hours = Math.floor(Math.abs(offsetInMinutes) / 60);
|
|
18
|
+
var _a = hourFormat.split(';'), positivePattern = _a[0], negativePattern = _a[1];
|
|
19
|
+
var offsetStr = '';
|
|
20
|
+
var pattern = offsetInMs < 0 ? negativePattern : positivePattern;
|
|
21
|
+
if (style === 'long') {
|
|
22
|
+
offsetStr = pattern
|
|
23
|
+
.replace('HH', pad(hours))
|
|
24
|
+
.replace('H', String(hours))
|
|
25
|
+
.replace('mm', pad(mins))
|
|
26
|
+
.replace('m', String(mins));
|
|
27
|
+
}
|
|
28
|
+
else if (mins || hours) {
|
|
29
|
+
if (!mins) {
|
|
30
|
+
pattern = pattern.replace(/:?m+/, '');
|
|
31
|
+
}
|
|
32
|
+
offsetStr = pattern
|
|
33
|
+
.replace(/H+/, String(hours))
|
|
34
|
+
.replace(/m+/, String(mins));
|
|
35
|
+
}
|
|
36
|
+
return gmtFormat.replace('{0}', offsetStr);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
40
|
+
* @param dtf
|
|
41
|
+
* @param x
|
|
42
|
+
*/
|
|
43
|
+
function PartitionDateTimePattern(dtf, x, _a) {
|
|
44
|
+
var getInternalSlots = _a.getInternalSlots, localeData = _a.localeData, getDefaultTimeZone = _a.getDefaultTimeZone, tzData = _a.tzData;
|
|
45
|
+
x = _262_1.TimeClip(x);
|
|
46
|
+
if (isNaN(x)) {
|
|
47
|
+
throw new RangeError('invalid time');
|
|
48
|
+
}
|
|
49
|
+
/** IMPL START */
|
|
50
|
+
var internalSlots = getInternalSlots(dtf);
|
|
51
|
+
var dataLocale = internalSlots.dataLocale;
|
|
52
|
+
var dataLocaleData = localeData[dataLocale];
|
|
53
|
+
/** IMPL END */
|
|
54
|
+
var locale = internalSlots.locale;
|
|
55
|
+
var nfOptions = Object.create(null);
|
|
56
|
+
nfOptions.useGrouping = false;
|
|
57
|
+
var nf = new Intl.NumberFormat(locale, nfOptions);
|
|
58
|
+
var nf2Options = Object.create(null);
|
|
59
|
+
nf2Options.minimumIntegerDigits = 2;
|
|
60
|
+
nf2Options.useGrouping = false;
|
|
61
|
+
var nf2 = new Intl.NumberFormat(locale, nf2Options);
|
|
62
|
+
var tm = ToLocalTime_1.ToLocalTime(x,
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
|
|
65
|
+
var result = [];
|
|
66
|
+
var patternParts = PartitionPattern_1.PartitionPattern(internalSlots.pattern);
|
|
67
|
+
for (var _i = 0, patternParts_1 = patternParts; _i < patternParts_1.length; _i++) {
|
|
68
|
+
var patternPart = patternParts_1[_i];
|
|
69
|
+
var p = patternPart.type;
|
|
70
|
+
if (p === 'literal') {
|
|
71
|
+
result.push({
|
|
72
|
+
type: 'literal',
|
|
73
|
+
value: patternPart.value,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else if (utils_1.DATE_TIME_PROPS.indexOf(p) > -1) {
|
|
77
|
+
var fv = '';
|
|
78
|
+
var f = internalSlots[p];
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
var v = tm[p];
|
|
81
|
+
if (p === 'year' && v <= 0) {
|
|
82
|
+
v = 1 - v;
|
|
83
|
+
}
|
|
84
|
+
if (p === 'month') {
|
|
85
|
+
v++;
|
|
86
|
+
}
|
|
87
|
+
var hourCycle = internalSlots.hourCycle;
|
|
88
|
+
if (p === 'hour' && (hourCycle === 'h11' || hourCycle === 'h12')) {
|
|
89
|
+
v = v % 12;
|
|
90
|
+
if (v === 0 && hourCycle === 'h12') {
|
|
91
|
+
v = 12;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (p === 'hour' && hourCycle === 'h24') {
|
|
95
|
+
if (v === 0) {
|
|
96
|
+
v = 24;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (f === 'numeric') {
|
|
100
|
+
fv = nf.format(v);
|
|
101
|
+
}
|
|
102
|
+
else if (f === '2-digit') {
|
|
103
|
+
fv = nf2.format(v);
|
|
104
|
+
if (fv.length > 2) {
|
|
105
|
+
fv = fv.slice(fv.length - 2, fv.length);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else if (f === 'narrow' || f === 'short' || f === 'long') {
|
|
109
|
+
if (p === 'era') {
|
|
110
|
+
fv = dataLocaleData[p][f][v];
|
|
111
|
+
}
|
|
112
|
+
else if (p === 'timeZoneName') {
|
|
113
|
+
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
|
|
114
|
+
var timeZone = internalSlots.timeZone || getDefaultTimeZone();
|
|
115
|
+
var timeZoneData = timeZoneName[timeZone];
|
|
116
|
+
if (timeZoneData && timeZoneData[f]) {
|
|
117
|
+
fv = timeZoneData[f][+tm.inDST];
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Fallback to gmtFormat
|
|
121
|
+
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else if (p === 'month') {
|
|
125
|
+
fv = dataLocaleData.month[f][v - 1];
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
fv = dataLocaleData[p][f][v];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
result.push({
|
|
132
|
+
type: p,
|
|
133
|
+
value: fv,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else if (p === 'ampm') {
|
|
137
|
+
var v = tm.hour;
|
|
138
|
+
var fv = void 0;
|
|
139
|
+
if (v > 11) {
|
|
140
|
+
fv = dataLocaleData.pm;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
fv = dataLocaleData.am;
|
|
144
|
+
}
|
|
145
|
+
result.push({
|
|
146
|
+
type: 'dayPeriod',
|
|
147
|
+
value: fv,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else if (p === 'relatedYear') {
|
|
151
|
+
var v = tm.relatedYear;
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
var fv = nf.format(v);
|
|
154
|
+
result.push({
|
|
155
|
+
// @ts-ignore TODO: Fix TS type
|
|
156
|
+
type: 'relatedYear',
|
|
157
|
+
value: fv,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
else if (p === 'yearName') {
|
|
161
|
+
var v = tm.yearName;
|
|
162
|
+
// @ts-ignore
|
|
163
|
+
var fv = nf.format(v);
|
|
164
|
+
result.push({
|
|
165
|
+
// @ts-ignore TODO: Fix TS type
|
|
166
|
+
type: 'yearName',
|
|
167
|
+
value: fv,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
result.push({
|
|
172
|
+
// @ts-ignore TODO: Fix TS type
|
|
173
|
+
type: 'unknown',
|
|
174
|
+
value: String(x),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
exports.PartitionDateTimePattern = PartitionDateTimePattern;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateTimeFormatOptions } from '../../types/date-time';
|
|
2
|
+
/**
|
|
3
|
+
* https://tc39.es/ecma402/#sec-todatetimeoptions
|
|
4
|
+
* @param options
|
|
5
|
+
* @param required
|
|
6
|
+
* @param defaults
|
|
7
|
+
*/
|
|
8
|
+
export declare function ToDateTimeOptions(options?: DateTimeFormatOptions | null, required?: string, defaults?: string): DateTimeFormatOptions;
|
|
9
|
+
//# sourceMappingURL=ToDateTimeOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToDateTimeOptions.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/ToDateTimeOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAG5D;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,EACtC,QAAQ,CAAC,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,qBAAqB,CAyDvB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToDateTimeOptions = void 0;
|
|
4
|
+
var _262_1 = require("../../262");
|
|
5
|
+
/**
|
|
6
|
+
* https://tc39.es/ecma402/#sec-todatetimeoptions
|
|
7
|
+
* @param options
|
|
8
|
+
* @param required
|
|
9
|
+
* @param defaults
|
|
10
|
+
*/
|
|
11
|
+
function ToDateTimeOptions(options, required, defaults) {
|
|
12
|
+
if (options === undefined) {
|
|
13
|
+
options = null;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
options = _262_1.ToObject(options);
|
|
17
|
+
}
|
|
18
|
+
options = Object.create(options);
|
|
19
|
+
var needDefaults = true;
|
|
20
|
+
if (required === 'date' || required === 'any') {
|
|
21
|
+
for (var _i = 0, _a = ['weekday', 'year', 'month', 'day']; _i < _a.length; _i++) {
|
|
22
|
+
var prop = _a[_i];
|
|
23
|
+
var value = options[prop];
|
|
24
|
+
if (value !== undefined) {
|
|
25
|
+
needDefaults = false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (required === 'time' || required === 'any') {
|
|
30
|
+
for (var _b = 0, _c = ['hour', 'minute', 'second']; _b < _c.length; _b++) {
|
|
31
|
+
var prop = _c[_b];
|
|
32
|
+
var value = options[prop];
|
|
33
|
+
if (value !== undefined) {
|
|
34
|
+
needDefaults = false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (options.dateStyle !== undefined || options.timeStyle !== undefined) {
|
|
39
|
+
needDefaults = false;
|
|
40
|
+
}
|
|
41
|
+
if (required === 'date' && options.timeStyle) {
|
|
42
|
+
throw new TypeError('Intl.DateTimeFormat date was required but timeStyle was included');
|
|
43
|
+
}
|
|
44
|
+
if (required === 'time' && options.dateStyle) {
|
|
45
|
+
throw new TypeError('Intl.DateTimeFormat time was required but dateStyle was included');
|
|
46
|
+
}
|
|
47
|
+
if (needDefaults && (defaults === 'date' || defaults === 'all')) {
|
|
48
|
+
for (var _d = 0, _e = ['year', 'month', 'day']; _d < _e.length; _d++) {
|
|
49
|
+
var prop = _e[_d];
|
|
50
|
+
options[prop] = 'numeric';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (needDefaults && (defaults === 'time' || defaults === 'all')) {
|
|
54
|
+
for (var _f = 0, _g = ['hour', 'minute', 'second']; _f < _g.length; _f++) {
|
|
55
|
+
var prop = _g[_f];
|
|
56
|
+
options[prop] = 'numeric';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return options;
|
|
60
|
+
}
|
|
61
|
+
exports.ToDateTimeOptions = ToDateTimeOptions;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { UnpackedZoneData } from '../../types/date-time';
|
|
2
|
+
/**
|
|
3
|
+
* https://tc39.es/ecma402/#sec-tolocaltime
|
|
4
|
+
* @param t
|
|
5
|
+
* @param calendar
|
|
6
|
+
* @param timeZone
|
|
7
|
+
*/
|
|
8
|
+
export declare function ToLocalTime(t: number, calendar: string, timeZone: string, { tzData }: {
|
|
9
|
+
tzData: Record<string, UnpackedZoneData[]>;
|
|
10
|
+
}): {
|
|
11
|
+
weekday: number;
|
|
12
|
+
era: string;
|
|
13
|
+
year: number;
|
|
14
|
+
relatedYear: undefined;
|
|
15
|
+
yearName: undefined;
|
|
16
|
+
month: number;
|
|
17
|
+
day: number;
|
|
18
|
+
hour: number;
|
|
19
|
+
minute: number;
|
|
20
|
+
second: number;
|
|
21
|
+
inDST: boolean;
|
|
22
|
+
timeZoneOffset: number;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=ToLocalTime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToLocalTime.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/ToLocalTime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAkCvD;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,EAAC,MAAM,EAAC,EAAE;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAA;CAAC,GACrD;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,SAAS,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB,CAyBA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToLocalTime = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
|
+
var _262_1 = require("../../262");
|
|
6
|
+
function getApplicableZoneData(t, timeZone, tzData) {
|
|
7
|
+
var _a;
|
|
8
|
+
var zoneData = tzData[timeZone];
|
|
9
|
+
// We don't have data for this so just say it's UTC
|
|
10
|
+
if (!zoneData) {
|
|
11
|
+
return [0, false];
|
|
12
|
+
}
|
|
13
|
+
var i = 0;
|
|
14
|
+
var offset = 0;
|
|
15
|
+
var dst = false;
|
|
16
|
+
for (; i <= zoneData.length; i++) {
|
|
17
|
+
if (i === zoneData.length || zoneData[i][0] * 1e3 >= t) {
|
|
18
|
+
_a = zoneData[i - 1], offset = _a[2], dst = _a[3];
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return [offset * 1e3, dst];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* https://tc39.es/ecma402/#sec-tolocaltime
|
|
26
|
+
* @param t
|
|
27
|
+
* @param calendar
|
|
28
|
+
* @param timeZone
|
|
29
|
+
*/
|
|
30
|
+
function ToLocalTime(t, calendar, timeZone, _a) {
|
|
31
|
+
var tzData = _a.tzData;
|
|
32
|
+
utils_1.invariant(_262_1.Type(t) === 'Number', 'invalid time');
|
|
33
|
+
utils_1.invariant(calendar === 'gregory', 'We only support Gregory calendar right now');
|
|
34
|
+
var _b = getApplicableZoneData(t, timeZone, tzData), timeZoneOffset = _b[0], inDST = _b[1];
|
|
35
|
+
var tz = t + timeZoneOffset;
|
|
36
|
+
var year = _262_1.YearFromTime(tz);
|
|
37
|
+
return {
|
|
38
|
+
weekday: _262_1.WeekDay(tz),
|
|
39
|
+
era: year < 0 ? 'BC' : 'AD',
|
|
40
|
+
year: year,
|
|
41
|
+
relatedYear: undefined,
|
|
42
|
+
yearName: undefined,
|
|
43
|
+
month: _262_1.MonthFromTime(tz),
|
|
44
|
+
day: _262_1.DateFromTime(tz),
|
|
45
|
+
hour: _262_1.HourFromTime(tz),
|
|
46
|
+
minute: _262_1.MinFromTime(tz),
|
|
47
|
+
second: _262_1.SecFromTime(tz),
|
|
48
|
+
inDST: inDST,
|
|
49
|
+
// IMPORTANT: Not in spec
|
|
50
|
+
timeZoneOffset: timeZoneOffset,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.ToLocalTime = ToLocalTime;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Formats } from '../../types/date-time';
|
|
2
|
+
/**
|
|
3
|
+
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
4
|
+
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
5
|
+
* @public
|
|
6
|
+
* @param skeleton skeleton string
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseDateTimeSkeleton(skeleton: string, pattern?: string): Formats;
|
|
9
|
+
//# sourceMappingURL=skeleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skeleton.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/skeleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAiJ9C;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,MAAiB,GACzB,OAAO,CAqCT"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseDateTimeSkeleton = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
6
|
+
* Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
|
|
7
|
+
* with some tweaks
|
|
8
|
+
*/
|
|
9
|
+
var DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
|
|
10
|
+
// trim patterns after transformations
|
|
11
|
+
var expPatternTrimmer = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
|
|
12
|
+
function matchSkeletonPattern(match, result) {
|
|
13
|
+
if (result === void 0) { result = {
|
|
14
|
+
pattern: '',
|
|
15
|
+
pattern12: '',
|
|
16
|
+
skeleton: '',
|
|
17
|
+
rawPattern: '',
|
|
18
|
+
}; }
|
|
19
|
+
var len = match.length;
|
|
20
|
+
switch (match[0]) {
|
|
21
|
+
// Era
|
|
22
|
+
case 'G':
|
|
23
|
+
result.era = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short';
|
|
24
|
+
return '{era}';
|
|
25
|
+
// Year
|
|
26
|
+
case 'y':
|
|
27
|
+
case 'Y':
|
|
28
|
+
case 'u':
|
|
29
|
+
case 'U':
|
|
30
|
+
case 'r':
|
|
31
|
+
result.year = len === 2 ? '2-digit' : 'numeric';
|
|
32
|
+
return '{year}';
|
|
33
|
+
// Quarter
|
|
34
|
+
case 'q':
|
|
35
|
+
case 'Q':
|
|
36
|
+
throw new RangeError('`w/Q` (quarter) patterns are not supported');
|
|
37
|
+
// Month
|
|
38
|
+
case 'M':
|
|
39
|
+
case 'L':
|
|
40
|
+
result.month = ['numeric', '2-digit', 'short', 'long', 'narrow'][len - 1];
|
|
41
|
+
return '{month}';
|
|
42
|
+
// Week
|
|
43
|
+
case 'w':
|
|
44
|
+
case 'W':
|
|
45
|
+
throw new RangeError('`w/W` (week of year) patterns are not supported');
|
|
46
|
+
case 'd':
|
|
47
|
+
result.day = ['numeric', '2-digit'][len - 1];
|
|
48
|
+
return '{day}';
|
|
49
|
+
case 'D':
|
|
50
|
+
case 'F':
|
|
51
|
+
case 'g':
|
|
52
|
+
result.day = 'numeric';
|
|
53
|
+
return '{day}';
|
|
54
|
+
// Weekday
|
|
55
|
+
case 'E':
|
|
56
|
+
result.weekday = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short';
|
|
57
|
+
return '{weekday}';
|
|
58
|
+
case 'e':
|
|
59
|
+
result.weekday = [
|
|
60
|
+
'numeric',
|
|
61
|
+
'2-digit',
|
|
62
|
+
'short',
|
|
63
|
+
'long',
|
|
64
|
+
'narrow',
|
|
65
|
+
'short',
|
|
66
|
+
][len - 1];
|
|
67
|
+
return '{weekday}';
|
|
68
|
+
case 'c':
|
|
69
|
+
result.weekday = [
|
|
70
|
+
'numeric',
|
|
71
|
+
undefined,
|
|
72
|
+
'short',
|
|
73
|
+
'long',
|
|
74
|
+
'narrow',
|
|
75
|
+
'short',
|
|
76
|
+
][len - 1];
|
|
77
|
+
return '{weekday}';
|
|
78
|
+
// Period
|
|
79
|
+
case 'a': // AM, PM
|
|
80
|
+
case 'b': // am, pm, noon, midnight
|
|
81
|
+
case 'B': // flexible day periods
|
|
82
|
+
result.hour12 = true;
|
|
83
|
+
return '{ampm}';
|
|
84
|
+
// Hour
|
|
85
|
+
case 'h':
|
|
86
|
+
result.hour = ['numeric', '2-digit'][len - 1];
|
|
87
|
+
return '{hour}';
|
|
88
|
+
case 'H':
|
|
89
|
+
result.hour = ['numeric', '2-digit'][len - 1];
|
|
90
|
+
return '{hour}';
|
|
91
|
+
case 'K':
|
|
92
|
+
result.hour = ['numeric', '2-digit'][len - 1];
|
|
93
|
+
return '{hour}';
|
|
94
|
+
case 'k':
|
|
95
|
+
result.hour = ['numeric', '2-digit'][len - 1];
|
|
96
|
+
return '{hour}';
|
|
97
|
+
case 'j':
|
|
98
|
+
case 'J':
|
|
99
|
+
case 'C':
|
|
100
|
+
throw new RangeError('`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead');
|
|
101
|
+
// Minute
|
|
102
|
+
case 'm':
|
|
103
|
+
result.minute = ['numeric', '2-digit'][len - 1];
|
|
104
|
+
return '{minute}';
|
|
105
|
+
// Second
|
|
106
|
+
case 's':
|
|
107
|
+
result.second = ['numeric', '2-digit'][len - 1];
|
|
108
|
+
return '{second}';
|
|
109
|
+
case 'S':
|
|
110
|
+
case 'A':
|
|
111
|
+
result.second = 'numeric';
|
|
112
|
+
return '{second}';
|
|
113
|
+
// Zone
|
|
114
|
+
case 'z': // 1..3, 4: specific non-location format
|
|
115
|
+
case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
|
|
116
|
+
case 'O': // 1, 4: miliseconds in day short, long
|
|
117
|
+
case 'v': // 1, 4: generic non-location format
|
|
118
|
+
case 'V': // 1, 2, 3, 4: time zone ID or city
|
|
119
|
+
case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
|
|
120
|
+
case 'x': // 1, 2, 3, 4: The ISO8601 varios formats
|
|
121
|
+
result.timeZoneName = len < 4 ? 'short' : 'long';
|
|
122
|
+
return '{timeZoneName}';
|
|
123
|
+
}
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
128
|
+
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
129
|
+
* @public
|
|
130
|
+
* @param skeleton skeleton string
|
|
131
|
+
*/
|
|
132
|
+
function parseDateTimeSkeleton(skeleton, pattern) {
|
|
133
|
+
if (pattern === void 0) { pattern = skeleton; }
|
|
134
|
+
var result = {
|
|
135
|
+
pattern: '',
|
|
136
|
+
pattern12: '',
|
|
137
|
+
skeleton: skeleton,
|
|
138
|
+
rawPattern: pattern,
|
|
139
|
+
};
|
|
140
|
+
var literals = [];
|
|
141
|
+
// Use skeleton to populate result, but use mapped pattern to populate pattern
|
|
142
|
+
result.pattern12 = pattern
|
|
143
|
+
// Double apostrophe
|
|
144
|
+
.replace(/'{2}/g, '{apostrophe}')
|
|
145
|
+
// Apostrophe-escaped
|
|
146
|
+
.replace(/'(.*?)'/g, function (_, literal) {
|
|
147
|
+
literals.push(literal);
|
|
148
|
+
return "$$" + (literals.length - 1) + "$$";
|
|
149
|
+
})
|
|
150
|
+
.replace(DATE_TIME_REGEX, matchSkeletonPattern);
|
|
151
|
+
skeleton.replace(DATE_TIME_REGEX, function (m) { return matchSkeletonPattern(m, result); });
|
|
152
|
+
//Restore literals
|
|
153
|
+
if (literals.length) {
|
|
154
|
+
result.pattern12 = result.pattern12
|
|
155
|
+
.replace(/\$\$(\d+)\$\$/g, function (_, i) {
|
|
156
|
+
return literals[+i];
|
|
157
|
+
})
|
|
158
|
+
.replace(/\{apostrophe\}/g, "'");
|
|
159
|
+
}
|
|
160
|
+
// Handle apostrophe-escaped things
|
|
161
|
+
result.pattern = result.pattern12
|
|
162
|
+
.replace(/([\s\uFEFF\xA0])\{ampm\}([\s\uFEFF\xA0])/, '$1')
|
|
163
|
+
.replace('{ampm}', '')
|
|
164
|
+
.replace(expPatternTrimmer, '');
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
exports.parseDateTimeSkeleton = parseDateTimeSkeleton;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IntlDateTimeFormatInternal, TABLE_6 } from '../../types/date-time';
|
|
2
|
+
export declare const DATE_TIME_PROPS: Array<keyof Pick<IntlDateTimeFormatInternal, TABLE_6>>;
|
|
3
|
+
export declare const removalPenalty = 120;
|
|
4
|
+
export declare const additionPenalty = 20;
|
|
5
|
+
export declare const differentNumericTypePenalty = 15;
|
|
6
|
+
export declare const longLessPenalty = 8;
|
|
7
|
+
export declare const longMorePenalty = 6;
|
|
8
|
+
export declare const shortLessPenalty = 6;
|
|
9
|
+
export declare const shortMorePenalty = 3;
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAE,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAE1E,eAAO,MAAM,eAAe,EAAE,KAAK,CACjC,MAAM,IAAI,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAWhD,CAAC;AAEF,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,gBAAgB,IAAI,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shortMorePenalty = exports.shortLessPenalty = exports.longMorePenalty = exports.longLessPenalty = exports.differentNumericTypePenalty = exports.additionPenalty = exports.removalPenalty = exports.DATE_TIME_PROPS = void 0;
|
|
4
|
+
exports.DATE_TIME_PROPS = [
|
|
5
|
+
'weekday',
|
|
6
|
+
'era',
|
|
7
|
+
'year',
|
|
8
|
+
'month',
|
|
9
|
+
'day',
|
|
10
|
+
'hour',
|
|
11
|
+
'minute',
|
|
12
|
+
'second',
|
|
13
|
+
'timeZoneName',
|
|
14
|
+
];
|
|
15
|
+
exports.removalPenalty = 120;
|
|
16
|
+
exports.additionPenalty = 20;
|
|
17
|
+
exports.differentNumericTypePenalty = 15;
|
|
18
|
+
exports.longLessPenalty = 8;
|
|
19
|
+
exports.longMorePenalty = 6;
|
|
20
|
+
exports.shortLessPenalty = 6;
|
|
21
|
+
exports.shortMorePenalty = 3;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanonicalCodeForDisplayNames.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DisplayNames/CanonicalCodeForDisplayNames.ts"],"names":[],"mappings":"AAcA,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,EACnD,IAAI,EAAE,MAAM,OAsBb"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CanonicalCodeForDisplayNames = void 0;
|
|
4
|
+
var CanonicalizeLocaleList_1 = require("../CanonicalizeLocaleList");
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
|
+
var IsWellFormedCurrencyCode_1 = require("../IsWellFormedCurrencyCode");
|
|
7
|
+
var UNICODE_REGION_SUBTAG_REGEX = /^([a-z]{2}|[0-9]{3})$/i;
|
|
8
|
+
var ALPHA_4 = /^[a-z]{4}$/i;
|
|
9
|
+
function isUnicodeRegionSubtag(region) {
|
|
10
|
+
return UNICODE_REGION_SUBTAG_REGEX.test(region);
|
|
11
|
+
}
|
|
12
|
+
function isUnicodeScriptSubtag(script) {
|
|
13
|
+
return ALPHA_4.test(script);
|
|
14
|
+
}
|
|
15
|
+
function CanonicalCodeForDisplayNames(type, code) {
|
|
16
|
+
if (type === 'language') {
|
|
17
|
+
return CanonicalizeLocaleList_1.CanonicalizeLocaleList([code])[0];
|
|
18
|
+
}
|
|
19
|
+
if (type === 'region') {
|
|
20
|
+
if (!isUnicodeRegionSubtag(code)) {
|
|
21
|
+
throw RangeError('invalid region');
|
|
22
|
+
}
|
|
23
|
+
return code.toUpperCase();
|
|
24
|
+
}
|
|
25
|
+
if (type === 'script') {
|
|
26
|
+
if (!isUnicodeScriptSubtag(code)) {
|
|
27
|
+
throw RangeError('invalid script');
|
|
28
|
+
}
|
|
29
|
+
return "" + code[0].toUpperCase() + code.slice(1);
|
|
30
|
+
}
|
|
31
|
+
utils_1.invariant(type === 'currency', 'invalid type');
|
|
32
|
+
if (!IsWellFormedCurrencyCode_1.IsWellFormedCurrencyCode(code)) {
|
|
33
|
+
throw RangeError('invalid currency');
|
|
34
|
+
}
|
|
35
|
+
return code.toUpperCase();
|
|
36
|
+
}
|
|
37
|
+
exports.CanonicalCodeForDisplayNames = CanonicalCodeForDisplayNames;
|
package/src/GetOption.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.GetOption = void 0;
|
|
7
|
-
var
|
|
4
|
+
var _262_1 = require("../262");
|
|
8
5
|
/**
|
|
9
6
|
* https://tc39.es/ecma402/#sec-getoption
|
|
10
7
|
* @param opts
|
|
@@ -24,7 +21,7 @@ function GetOption(opts, prop, type, values, fallback) {
|
|
|
24
21
|
value = Boolean(value);
|
|
25
22
|
}
|
|
26
23
|
if (type === 'string') {
|
|
27
|
-
value =
|
|
24
|
+
value = _262_1.ToString(value);
|
|
28
25
|
}
|
|
29
26
|
if (values !== undefined && !values.filter(function (val) { return val == value; }).length) {
|
|
30
27
|
throw new RangeError(value + " is not within " + values.join(', '));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://tc39.es/ecma402/#sec-isvalidtimezonename
|
|
3
|
+
* @param tz
|
|
4
|
+
* @param implDetails implementation details
|
|
5
|
+
*/
|
|
6
|
+
export declare function IsValidTimeZoneName(tz: string, { tzData, uppercaseLinks, }: {
|
|
7
|
+
tzData: Record<string, unknown>;
|
|
8
|
+
uppercaseLinks: Record<string, unknown>;
|
|
9
|
+
}): boolean;
|
|
10
|
+
//# sourceMappingURL=IsValidTimeZoneName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsValidTimeZoneName.d.ts","sourceRoot":"","sources":["../../../../../../packages/ecma402-abstract/src/IsValidTimeZoneName.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,MAAM,EACV,EACE,MAAM,EACN,cAAc,GACf,EAAE;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,GACA,OAAO,CAIT"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IsValidTimeZoneName = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* https://tc39.es/ecma402/#sec-isvalidtimezonename
|
|
6
|
+
* @param tz
|
|
7
|
+
* @param implDetails implementation details
|
|
8
|
+
*/
|
|
9
|
+
function IsValidTimeZoneName(tz, _a) {
|
|
10
|
+
var tzData = _a.tzData, uppercaseLinks = _a.uppercaseLinks;
|
|
11
|
+
var uppercasedTz = tz.toUpperCase();
|
|
12
|
+
var zoneNames = new Set(Object.keys(tzData).map(function (z) { return z.toUpperCase(); }));
|
|
13
|
+
return zoneNames.has(uppercasedTz) || uppercasedTz in uppercaseLinks;
|
|
14
|
+
}
|
|
15
|
+
exports.IsValidTimeZoneName = IsValidTimeZoneName;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NumberFormatInternal } from '../../types/number';
|
|
2
|
+
/**
|
|
3
|
+
* The abstract operation ComputeExponent computes an exponent (power of ten) by which to scale x
|
|
4
|
+
* according to the number formatting settings. It handles cases such as 999 rounding up to 1000,
|
|
5
|
+
* requiring a different exponent.
|
|
6
|
+
*
|
|
7
|
+
* NOT IN SPEC: it returns [exponent, magnitude].
|
|
8
|
+
*/
|
|
9
|
+
export declare function ComputeExponent(numberFormat: Intl.NumberFormat, x: number, { getInternalSlots, }: {
|
|
10
|
+
getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
|
|
11
|
+
}): [number, number];
|
|
12
|
+
//# sourceMappingURL=ComputeExponent.d.ts.map
|