@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,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.BasicFormatMatcher = void 0;
|
|
15
|
+
var utils_1 = require("../utils");
|
|
16
|
+
var utils_2 = require("./utils");
|
|
17
|
+
/**
|
|
18
|
+
* https://tc39.es/ecma402/#sec-basicformatmatcher
|
|
19
|
+
* @param options
|
|
20
|
+
* @param formats
|
|
21
|
+
*/
|
|
22
|
+
function BasicFormatMatcher(options, formats) {
|
|
23
|
+
var bestScore = -Infinity;
|
|
24
|
+
var bestFormat = formats[0];
|
|
25
|
+
utils_1.invariant(Array.isArray(formats), 'formats should be a list of things');
|
|
26
|
+
for (var _i = 0, formats_1 = formats; _i < formats_1.length; _i++) {
|
|
27
|
+
var format = formats_1[_i];
|
|
28
|
+
var score = 0;
|
|
29
|
+
for (var _a = 0, DATE_TIME_PROPS_1 = utils_2.DATE_TIME_PROPS; _a < DATE_TIME_PROPS_1.length; _a++) {
|
|
30
|
+
var prop = DATE_TIME_PROPS_1[_a];
|
|
31
|
+
var optionsProp = options[prop];
|
|
32
|
+
var formatProp = format[prop];
|
|
33
|
+
if (optionsProp === undefined && formatProp !== undefined) {
|
|
34
|
+
score -= utils_2.additionPenalty;
|
|
35
|
+
}
|
|
36
|
+
else if (optionsProp !== undefined && formatProp === undefined) {
|
|
37
|
+
score -= utils_2.removalPenalty;
|
|
38
|
+
}
|
|
39
|
+
else if (optionsProp !== formatProp) {
|
|
40
|
+
var values = ['2-digit', 'numeric', 'narrow', 'short', 'long'];
|
|
41
|
+
var optionsPropIndex = values.indexOf(optionsProp);
|
|
42
|
+
var formatPropIndex = values.indexOf(formatProp);
|
|
43
|
+
var delta = Math.max(-2, Math.min(formatPropIndex - optionsPropIndex, 2));
|
|
44
|
+
if (delta === 2) {
|
|
45
|
+
score -= utils_2.longMorePenalty;
|
|
46
|
+
}
|
|
47
|
+
else if (delta === 1) {
|
|
48
|
+
score -= utils_2.shortMorePenalty;
|
|
49
|
+
}
|
|
50
|
+
else if (delta === -1) {
|
|
51
|
+
score -= utils_2.shortLessPenalty;
|
|
52
|
+
}
|
|
53
|
+
else if (delta === -2) {
|
|
54
|
+
score -= utils_2.longLessPenalty;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (score > bestScore) {
|
|
59
|
+
bestScore = score;
|
|
60
|
+
bestFormat = format;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return __assign({}, bestFormat);
|
|
64
|
+
}
|
|
65
|
+
exports.BasicFormatMatcher = BasicFormatMatcher;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DateTimeFormatOptions, Formats } from '../../types/date-time';
|
|
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: 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: DateTimeFormatOptions, formats: Formats[]): Formats;
|
|
17
|
+
//# sourceMappingURL=BestFitFormatMatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BestFitFormatMatcher.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/BestFitFormatMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAE,OAAO,EAAU,MAAM,uBAAuB,CAAC;AAoB9E;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,OAAO,GACd,MAAM,CA0CR;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,OAAO,EAAE,WA+CnB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.BestFitFormatMatcher = exports.bestFitFormatMatcherScore = void 0;
|
|
15
|
+
var utils_1 = require("../utils");
|
|
16
|
+
var utils_2 = require("./utils");
|
|
17
|
+
var skeleton_1 = require("./skeleton");
|
|
18
|
+
function isNumericType(t) {
|
|
19
|
+
return t === 'numeric' || t === '2-digit';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Credit: https://github.com/andyearnshaw/Intl.js/blob/0958dc1ad8153f1056653ea22b8208f0df289a4e/src/12.datetimeformat.js#L611
|
|
23
|
+
* with some modifications
|
|
24
|
+
* @param options
|
|
25
|
+
* @param format
|
|
26
|
+
*/
|
|
27
|
+
function bestFitFormatMatcherScore(options, format) {
|
|
28
|
+
var score = 0;
|
|
29
|
+
if (options.hour12 && !format.hour12) {
|
|
30
|
+
score -= utils_2.removalPenalty;
|
|
31
|
+
}
|
|
32
|
+
else if (!options.hour12 && format.hour12) {
|
|
33
|
+
score -= utils_2.additionPenalty;
|
|
34
|
+
}
|
|
35
|
+
for (var _i = 0, DATE_TIME_PROPS_1 = utils_2.DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
|
|
36
|
+
var prop = DATE_TIME_PROPS_1[_i];
|
|
37
|
+
var optionsProp = options[prop];
|
|
38
|
+
var formatProp = format[prop];
|
|
39
|
+
if (optionsProp === undefined && formatProp !== undefined) {
|
|
40
|
+
score -= utils_2.additionPenalty;
|
|
41
|
+
}
|
|
42
|
+
else if (optionsProp !== undefined && formatProp === undefined) {
|
|
43
|
+
score -= utils_2.removalPenalty;
|
|
44
|
+
}
|
|
45
|
+
else if (optionsProp !== formatProp) {
|
|
46
|
+
// extra penalty for numeric vs non-numeric
|
|
47
|
+
if (isNumericType(optionsProp) !==
|
|
48
|
+
isNumericType(formatProp)) {
|
|
49
|
+
score -= utils_2.differentNumericTypePenalty;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
var values = ['2-digit', 'numeric', 'narrow', 'short', 'long'];
|
|
53
|
+
var optionsPropIndex = values.indexOf(optionsProp);
|
|
54
|
+
var formatPropIndex = values.indexOf(formatProp);
|
|
55
|
+
var delta = Math.max(-2, Math.min(formatPropIndex - optionsPropIndex, 2));
|
|
56
|
+
if (delta === 2) {
|
|
57
|
+
score -= utils_2.longMorePenalty;
|
|
58
|
+
}
|
|
59
|
+
else if (delta === 1) {
|
|
60
|
+
score -= utils_2.shortMorePenalty;
|
|
61
|
+
}
|
|
62
|
+
else if (delta === -1) {
|
|
63
|
+
score -= utils_2.shortLessPenalty;
|
|
64
|
+
}
|
|
65
|
+
else if (delta === -2) {
|
|
66
|
+
score -= utils_2.longLessPenalty;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return score;
|
|
72
|
+
}
|
|
73
|
+
exports.bestFitFormatMatcherScore = bestFitFormatMatcherScore;
|
|
74
|
+
/**
|
|
75
|
+
* https://tc39.es/ecma402/#sec-bestfitformatmatcher
|
|
76
|
+
* Just alias to basic for now
|
|
77
|
+
* @param options
|
|
78
|
+
* @param formats
|
|
79
|
+
* @param implDetails Implementation details
|
|
80
|
+
*/
|
|
81
|
+
function BestFitFormatMatcher(options, formats) {
|
|
82
|
+
var bestScore = -Infinity;
|
|
83
|
+
var bestFormat = formats[0];
|
|
84
|
+
utils_1.invariant(Array.isArray(formats), 'formats should be a list of things');
|
|
85
|
+
for (var _i = 0, formats_1 = formats; _i < formats_1.length; _i++) {
|
|
86
|
+
var format = formats_1[_i];
|
|
87
|
+
var score = bestFitFormatMatcherScore(options, format);
|
|
88
|
+
if (score > bestScore) {
|
|
89
|
+
bestScore = score;
|
|
90
|
+
bestFormat = format;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
var skeletonFormat = __assign({}, bestFormat);
|
|
94
|
+
var patternFormat = skeleton_1.parseDateTimeSkeleton(bestFormat.rawPattern);
|
|
95
|
+
// Kinda following https://github.com/unicode-org/icu/blob/dd50e38f459d84e9bf1b0c618be8483d318458ad/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java
|
|
96
|
+
// Method adjustFieldTypes
|
|
97
|
+
for (var prop in patternFormat) {
|
|
98
|
+
var skeletonValue = skeletonFormat[prop];
|
|
99
|
+
var patternValue = patternFormat[prop];
|
|
100
|
+
var requestedValue = options[prop];
|
|
101
|
+
// Don't mess with minute/second or we can get in the situation of
|
|
102
|
+
// 7:0:0 which is weird
|
|
103
|
+
if (prop === 'minute' || prop === 'second') {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// Nothing to do here
|
|
107
|
+
if (!requestedValue) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
// https://unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons
|
|
111
|
+
// Looks like we should not convert numeric to alphabetic but the other way
|
|
112
|
+
// around is ok
|
|
113
|
+
if (isNumericType(patternValue) &&
|
|
114
|
+
!isNumericType(requestedValue)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (skeletonValue === requestedValue) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
patternFormat[prop] = requestedValue;
|
|
121
|
+
}
|
|
122
|
+
return patternFormat;
|
|
123
|
+
}
|
|
124
|
+
exports.BestFitFormatMatcher = BestFitFormatMatcher;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DateTimeFormatOptions, DateTimeFormatLocaleInternalData, Formats } from '../../types/date-time';
|
|
2
|
+
export declare function DateTimeStyleFormat(dateStyle: DateTimeFormatOptions['dateStyle'], timeStyle: DateTimeFormatOptions['timeStyle'], dataLocaleData: DateTimeFormatLocaleInternalData): Formats;
|
|
3
|
+
//# sourceMappingURL=DateTimeStyleFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateTimeStyleFormat.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/DateTimeStyleFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,OAAO,EACR,MAAM,uBAAuB,CAAC;AAG/B,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,qBAAqB,CAAC,WAAW,CAAC,EAC7C,SAAS,EAAE,qBAAqB,CAAC,WAAW,CAAC,EAC7C,cAAc,EAAE,gCAAgC,GAC/C,OAAO,CAuDT"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateTimeStyleFormat = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
|
+
function DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData) {
|
|
6
|
+
var dateFormat, timeFormat;
|
|
7
|
+
if (timeStyle !== undefined) {
|
|
8
|
+
utils_1.invariant(timeStyle === 'full' ||
|
|
9
|
+
timeStyle === 'long' ||
|
|
10
|
+
timeStyle === 'medium' ||
|
|
11
|
+
timeStyle === 'short', 'invalid timeStyle');
|
|
12
|
+
timeFormat = dataLocaleData.timeFormat[timeStyle];
|
|
13
|
+
}
|
|
14
|
+
if (dateStyle !== undefined) {
|
|
15
|
+
utils_1.invariant(dateStyle === 'full' ||
|
|
16
|
+
dateStyle === 'long' ||
|
|
17
|
+
dateStyle === 'medium' ||
|
|
18
|
+
dateStyle === 'short', 'invalid dateStyle');
|
|
19
|
+
dateFormat = dataLocaleData.dateFormat[dateStyle];
|
|
20
|
+
}
|
|
21
|
+
if (dateStyle !== undefined && timeStyle !== undefined) {
|
|
22
|
+
var format = {};
|
|
23
|
+
for (var field in dateFormat) {
|
|
24
|
+
if (field !== 'pattern') {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
format[field] = dateFormat[field];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (var field in timeFormat) {
|
|
30
|
+
if (field !== 'pattern' && field !== 'pattern12') {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
format[field] = timeFormat[field];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var connector = dataLocaleData.dateTimeFormat[dateStyle];
|
|
36
|
+
var pattern = connector
|
|
37
|
+
.replace('{0}', timeFormat.pattern)
|
|
38
|
+
.replace('{1}', dateFormat.pattern);
|
|
39
|
+
format.pattern = pattern;
|
|
40
|
+
if ('pattern12' in timeFormat) {
|
|
41
|
+
var pattern12 = connector
|
|
42
|
+
.replace('{0}', timeFormat.pattern12)
|
|
43
|
+
.replace('{1}', dateFormat.pattern);
|
|
44
|
+
format.pattern12 = pattern12;
|
|
45
|
+
}
|
|
46
|
+
return format;
|
|
47
|
+
}
|
|
48
|
+
if (timeStyle !== undefined) {
|
|
49
|
+
return timeFormat;
|
|
50
|
+
}
|
|
51
|
+
utils_1.invariant(dateStyle !== undefined, 'dateStyle should not be undefined');
|
|
52
|
+
return dateFormat;
|
|
53
|
+
}
|
|
54
|
+
exports.DateTimeStyleFormat = DateTimeStyleFormat;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PartitionDateTimePattern } from './PartitionDateTimePattern';
|
|
2
|
+
/**
|
|
3
|
+
* https://tc39.es/ecma402/#sec-formatdatetime
|
|
4
|
+
* @param dtf DateTimeFormat
|
|
5
|
+
* @param x
|
|
6
|
+
*/
|
|
7
|
+
export declare function FormatDateTime(dtf: Intl.DateTimeFormat, x: number, implDetails: Parameters<typeof PartitionDateTimePattern>[2]): string;
|
|
8
|
+
//# sourceMappingURL=FormatDateTime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatDateTime.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/FormatDateTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AAEpE;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,CAAC,EAAE,MAAM,EACT,WAAW,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,UAQ5D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatDateTime = void 0;
|
|
4
|
+
var PartitionDateTimePattern_1 = require("./PartitionDateTimePattern");
|
|
5
|
+
/**
|
|
6
|
+
* https://tc39.es/ecma402/#sec-formatdatetime
|
|
7
|
+
* @param dtf DateTimeFormat
|
|
8
|
+
* @param x
|
|
9
|
+
*/
|
|
10
|
+
function FormatDateTime(dtf, x, implDetails) {
|
|
11
|
+
var parts = PartitionDateTimePattern_1.PartitionDateTimePattern(dtf, x, implDetails);
|
|
12
|
+
var result = '';
|
|
13
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
14
|
+
var part = parts_1[_i];
|
|
15
|
+
result += part.value;
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
exports.FormatDateTime = FormatDateTime;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PartitionDateTimePattern } from './PartitionDateTimePattern';
|
|
2
|
+
/**
|
|
3
|
+
* https://tc39.es/ecma402/#sec-formatdatetimetoparts
|
|
4
|
+
*
|
|
5
|
+
* @param dtf
|
|
6
|
+
* @param x
|
|
7
|
+
* @param implDetails
|
|
8
|
+
*/
|
|
9
|
+
export declare function FormatDateTimeToParts(dtf: Intl.DateTimeFormat, x: number, implDetails: Parameters<typeof PartitionDateTimePattern>[2]): Intl.DateTimeFormatPart[];
|
|
10
|
+
//# sourceMappingURL=FormatDateTimeToParts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatDateTimeToParts.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/FormatDateTimeToParts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AAGpE;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,CAAC,EAAE,MAAM,EACT,WAAW,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,GAC1D,IAAI,CAAC,kBAAkB,EAAE,CAU3B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatDateTimeToParts = void 0;
|
|
4
|
+
var PartitionDateTimePattern_1 = require("./PartitionDateTimePattern");
|
|
5
|
+
var _262_1 = require("../../262");
|
|
6
|
+
/**
|
|
7
|
+
* https://tc39.es/ecma402/#sec-formatdatetimetoparts
|
|
8
|
+
*
|
|
9
|
+
* @param dtf
|
|
10
|
+
* @param x
|
|
11
|
+
* @param implDetails
|
|
12
|
+
*/
|
|
13
|
+
function FormatDateTimeToParts(dtf, x, implDetails) {
|
|
14
|
+
var parts = PartitionDateTimePattern_1.PartitionDateTimePattern(dtf, x, implDetails);
|
|
15
|
+
var result = _262_1.ArrayCreate(0);
|
|
16
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
17
|
+
var part = parts_1[_i];
|
|
18
|
+
result.push({
|
|
19
|
+
type: part.type,
|
|
20
|
+
value: part.value,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
exports.FormatDateTimeToParts = FormatDateTimeToParts;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DateTimeFormatOptions, IntlDateTimeFormatInternal, DateTimeFormatLocaleInternalData } from '../../types/date-time';
|
|
2
|
+
/**
|
|
3
|
+
* https://tc39.es/ecma402/#sec-initializedatetimeformat
|
|
4
|
+
* @param dtf DateTimeFormat
|
|
5
|
+
* @param locales locales
|
|
6
|
+
* @param opts options
|
|
7
|
+
*/
|
|
8
|
+
export declare function InitializeDateTimeFormat(dtf: Intl.DateTimeFormat, locales: string | string[] | undefined, opts: DateTimeFormatOptions | undefined, { getInternalSlots, availableLocales, localeData, getDefaultLocale, getDefaultTimeZone, relevantExtensionKeys, tzData, uppercaseLinks, }: {
|
|
9
|
+
getInternalSlots(dtf: Intl.DateTimeFormat): IntlDateTimeFormatInternal;
|
|
10
|
+
availableLocales: string[];
|
|
11
|
+
getDefaultLocale(): string;
|
|
12
|
+
getDefaultTimeZone(): string;
|
|
13
|
+
relevantExtensionKeys: string[];
|
|
14
|
+
localeData: Record<string, DateTimeFormatLocaleInternalData>;
|
|
15
|
+
tzData: Record<string, unknown>;
|
|
16
|
+
uppercaseLinks: Record<string, string>;
|
|
17
|
+
}): Intl.DateTimeFormat;
|
|
18
|
+
//# sourceMappingURL=InitializeDateTimeFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitializeDateTimeFormat.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/InitializeDateTimeFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAErB,0BAA0B,EAC1B,gCAAgC,EACjC,MAAM,uBAAuB,CAAC;AAgC/B;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EACtC,IAAI,EAAE,qBAAqB,GAAG,SAAS,EACvC,EACE,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,MAAM,EACN,cAAc,GACf,EAAE;IACD,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,GAAG,0BAA0B,CAAC;IACvE,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,IAAI,MAAM,CAAC;IAC3B,kBAAkB,IAAI,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAC;IAC7D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,GACA,IAAI,CAAC,cAAc,CAqOrB"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InitializeDateTimeFormat = void 0;
|
|
4
|
+
var CanonicalizeLocaleList_1 = require("../CanonicalizeLocaleList");
|
|
5
|
+
var ToDateTimeOptions_1 = require("./ToDateTimeOptions");
|
|
6
|
+
var GetOption_1 = require("../GetOption");
|
|
7
|
+
var ResolveLocale_1 = require("../ResolveLocale");
|
|
8
|
+
var IsValidTimeZoneName_1 = require("../IsValidTimeZoneName");
|
|
9
|
+
var CanonicalizeTimeZoneName_1 = require("../CanonicalizeTimeZoneName");
|
|
10
|
+
var BasicFormatMatcher_1 = require("./BasicFormatMatcher");
|
|
11
|
+
var BestFitFormatMatcher_1 = require("./BestFitFormatMatcher");
|
|
12
|
+
var utils_1 = require("../utils");
|
|
13
|
+
var utils_2 = require("./utils");
|
|
14
|
+
var DateTimeStyleFormat_1 = require("./DateTimeStyleFormat");
|
|
15
|
+
function isTimeRelated(opt) {
|
|
16
|
+
for (var _i = 0, _a = ['hour', 'minute', 'second']; _i < _a.length; _i++) {
|
|
17
|
+
var prop = _a[_i];
|
|
18
|
+
var value = opt[prop];
|
|
19
|
+
if (value !== undefined) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
var TYPE_REGEX = /^[a-z0-9]{3,8}$/i;
|
|
26
|
+
/**
|
|
27
|
+
* https://tc39.es/ecma402/#sec-initializedatetimeformat
|
|
28
|
+
* @param dtf DateTimeFormat
|
|
29
|
+
* @param locales locales
|
|
30
|
+
* @param opts options
|
|
31
|
+
*/
|
|
32
|
+
function InitializeDateTimeFormat(dtf, locales, opts, _a) {
|
|
33
|
+
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;
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
var requestedLocales = CanonicalizeLocaleList_1.CanonicalizeLocaleList(locales);
|
|
36
|
+
var options = ToDateTimeOptions_1.ToDateTimeOptions(opts, 'any', 'date');
|
|
37
|
+
var opt = Object.create(null);
|
|
38
|
+
var matcher = GetOption_1.GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
|
|
39
|
+
opt.localeMatcher = matcher;
|
|
40
|
+
var calendar = GetOption_1.GetOption(options, 'calendar', 'string', undefined, undefined);
|
|
41
|
+
if (calendar !== undefined && !TYPE_REGEX.test(calendar)) {
|
|
42
|
+
throw new RangeError('Malformed calendar');
|
|
43
|
+
}
|
|
44
|
+
var internalSlots = getInternalSlots(dtf);
|
|
45
|
+
opt.ca = calendar;
|
|
46
|
+
var numberingSystem = GetOption_1.GetOption(options, 'numberingSystem', 'string', undefined, undefined);
|
|
47
|
+
if (numberingSystem !== undefined && !TYPE_REGEX.test(numberingSystem)) {
|
|
48
|
+
throw new RangeError('Malformed numbering system');
|
|
49
|
+
}
|
|
50
|
+
opt.nu = numberingSystem;
|
|
51
|
+
var hour12 = GetOption_1.GetOption(options, 'hour12', 'boolean', undefined, undefined);
|
|
52
|
+
var hourCycle = GetOption_1.GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
|
|
53
|
+
if (hour12 !== undefined) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
hourCycle = null;
|
|
56
|
+
}
|
|
57
|
+
opt.hc = hourCycle;
|
|
58
|
+
var r = ResolveLocale_1.ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
|
|
59
|
+
internalSlots.locale = r.locale;
|
|
60
|
+
calendar = r.ca;
|
|
61
|
+
internalSlots.calendar = calendar;
|
|
62
|
+
internalSlots.hourCycle = r.hc;
|
|
63
|
+
internalSlots.numberingSystem = r.nu;
|
|
64
|
+
var dataLocale = r.dataLocale;
|
|
65
|
+
internalSlots.dataLocale = dataLocale;
|
|
66
|
+
var timeZone = options.timeZone;
|
|
67
|
+
if (timeZone !== undefined) {
|
|
68
|
+
timeZone = String(timeZone);
|
|
69
|
+
if (!IsValidTimeZoneName_1.IsValidTimeZoneName(timeZone, { tzData: tzData, uppercaseLinks: uppercaseLinks })) {
|
|
70
|
+
throw new RangeError('Invalid timeZoneName');
|
|
71
|
+
}
|
|
72
|
+
timeZone = CanonicalizeTimeZoneName_1.CanonicalizeTimeZoneName(timeZone, { tzData: tzData, uppercaseLinks: uppercaseLinks });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
timeZone = getDefaultTimeZone();
|
|
76
|
+
}
|
|
77
|
+
internalSlots.timeZone = timeZone;
|
|
78
|
+
opt = Object.create(null);
|
|
79
|
+
opt.weekday = GetOption_1.GetOption(options, 'weekday', 'string', ['narrow', 'short', 'long'], undefined);
|
|
80
|
+
opt.era = GetOption_1.GetOption(options, 'era', 'string', ['narrow', 'short', 'long'], undefined);
|
|
81
|
+
opt.year = GetOption_1.GetOption(options, 'year', 'string', ['2-digit', 'numeric'], undefined);
|
|
82
|
+
opt.month = GetOption_1.GetOption(options, 'month', 'string', ['2-digit', 'numeric', 'narrow', 'short', 'long'], undefined);
|
|
83
|
+
opt.day = GetOption_1.GetOption(options, 'day', 'string', ['2-digit', 'numeric'], undefined);
|
|
84
|
+
opt.hour = GetOption_1.GetOption(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
|
|
85
|
+
opt.minute = GetOption_1.GetOption(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
|
|
86
|
+
opt.second = GetOption_1.GetOption(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
|
|
87
|
+
opt.timeZoneName = GetOption_1.GetOption(options, 'timeZoneName', 'string', ['short', 'long'], undefined);
|
|
88
|
+
var dataLocaleData = localeData[dataLocale];
|
|
89
|
+
var formats = dataLocaleData.formats[calendar];
|
|
90
|
+
matcher = GetOption_1.GetOption(options, 'formatMatcher', 'string', ['basic', 'best fit'], 'best fit');
|
|
91
|
+
var dateStyle = GetOption_1.GetOption(options, 'dateStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
|
|
92
|
+
internalSlots.dateStyle = dateStyle;
|
|
93
|
+
var timeStyle = GetOption_1.GetOption(options, 'timeStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
|
|
94
|
+
internalSlots.timeStyle = timeStyle;
|
|
95
|
+
var bestFormat;
|
|
96
|
+
if (dateStyle === undefined && timeStyle === undefined) {
|
|
97
|
+
if (matcher === 'basic') {
|
|
98
|
+
bestFormat = BasicFormatMatcher_1.BasicFormatMatcher(opt, formats);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (isTimeRelated(opt)) {
|
|
102
|
+
opt.hour12 =
|
|
103
|
+
internalSlots.hourCycle === 'h11' ||
|
|
104
|
+
internalSlots.hourCycle === 'h12';
|
|
105
|
+
}
|
|
106
|
+
bestFormat = BestFitFormatMatcher_1.BestFitFormatMatcher(opt, formats);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
for (var _i = 0, DATE_TIME_PROPS_1 = utils_2.DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
|
|
111
|
+
var prop = DATE_TIME_PROPS_1[_i];
|
|
112
|
+
var p = opt[prop];
|
|
113
|
+
if (p !== undefined) {
|
|
114
|
+
throw new TypeError("Intl.DateTimeFormat can't set option " + prop + " when " + (dateStyle ? 'dateStyle' : 'timeStyle') + " is used");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
bestFormat = DateTimeStyleFormat_1.DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData);
|
|
118
|
+
}
|
|
119
|
+
for (var prop in opt) {
|
|
120
|
+
var p = bestFormat[prop];
|
|
121
|
+
if (p !== undefined) {
|
|
122
|
+
internalSlots[prop] = p;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var pattern;
|
|
126
|
+
if (internalSlots.hour !== undefined) {
|
|
127
|
+
var hcDefault = dataLocaleData.hourCycle;
|
|
128
|
+
var hc = internalSlots.hourCycle;
|
|
129
|
+
if (hc == null) {
|
|
130
|
+
hc = hcDefault;
|
|
131
|
+
}
|
|
132
|
+
if (hour12 !== undefined) {
|
|
133
|
+
if (hour12) {
|
|
134
|
+
if (hcDefault === 'h11' || hcDefault === 'h23') {
|
|
135
|
+
hc = 'h11';
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
hc = 'h12';
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
utils_1.invariant(!hour12, 'hour12 must not be set');
|
|
143
|
+
if (hcDefault === 'h11' || hcDefault === 'h23') {
|
|
144
|
+
hc = 'h23';
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
hc = 'h24';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
internalSlots.hourCycle = hc;
|
|
152
|
+
if (hc === 'h11' || hc === 'h12') {
|
|
153
|
+
pattern = bestFormat.pattern12;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
pattern = bestFormat.pattern;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
internalSlots.hourCycle = undefined;
|
|
162
|
+
pattern = bestFormat.pattern;
|
|
163
|
+
}
|
|
164
|
+
internalSlots.pattern = pattern;
|
|
165
|
+
return dtf;
|
|
166
|
+
}
|
|
167
|
+
exports.InitializeDateTimeFormat = InitializeDateTimeFormat;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IntlDateTimeFormatInternal, DateTimeFormatLocaleInternalData, UnpackedZoneData } from '../../types/date-time';
|
|
2
|
+
/**
|
|
3
|
+
* https://tc39.es/ecma402/#sec-partitiondatetimepattern
|
|
4
|
+
* @param dtf
|
|
5
|
+
* @param x
|
|
6
|
+
*/
|
|
7
|
+
export declare function PartitionDateTimePattern(dtf: Intl.DateTimeFormat, x: number, { getInternalSlots, localeData, getDefaultTimeZone, tzData, }: {
|
|
8
|
+
getInternalSlots(dtf: Intl.DateTimeFormat): IntlDateTimeFormatInternal;
|
|
9
|
+
localeData: Record<string, DateTimeFormatLocaleInternalData>;
|
|
10
|
+
getDefaultTimeZone(): string;
|
|
11
|
+
tzData: Record<string, UnpackedZoneData[]>;
|
|
12
|
+
}): Intl.DateTimeFormatPart[];
|
|
13
|
+
//# sourceMappingURL=PartitionDateTimePattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PartitionDateTimePattern.d.ts","sourceRoot":"","sources":["../../../../../../../packages/ecma402-abstract/src/DateTimeFormat/PartitionDateTimePattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AA4C/B;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,CAAC,EAAE,MAAM,EACT,EACE,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,MAAM,GACP,EAAE;IACD,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,GAAG,0BAA0B,CAAC;IACvE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAC;IAC7D,kBAAkB,IAAI,MAAM,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;CAC5C,GACA,IAAI,CAAC,kBAAkB,EAAE,CA2I3B"}
|