@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.
Files changed (242) hide show
  1. package/262.d.ts +79 -0
  2. package/262.d.ts.map +1 -0
  3. package/262.js +336 -0
  4. package/_validate_dist-base_options.optionsvalid.d.ts +2 -1
  5. package/_validate_dist-esm_options.optionsvalid.d.ts +2 -1
  6. package/index.d.ts +33 -0
  7. package/index.d.ts.map +1 -1
  8. package/index.js +52 -11
  9. package/lib/262.d.ts +79 -0
  10. package/lib/262.d.ts.map +1 -0
  11. package/lib/262.js +312 -0
  12. package/lib/index.d.ts +33 -0
  13. package/lib/index.d.ts.map +1 -1
  14. package/lib/index.js +33 -0
  15. package/lib/src/CanonicalizeLocaleList.d.ts +6 -0
  16. package/lib/src/CanonicalizeLocaleList.d.ts.map +1 -0
  17. package/lib/src/CanonicalizeLocaleList.js +8 -0
  18. package/lib/src/CanonicalizeTimeZoneName.d.ts +9 -0
  19. package/lib/src/CanonicalizeTimeZoneName.d.ts.map +1 -0
  20. package/lib/src/CanonicalizeTimeZoneName.js +17 -0
  21. package/lib/src/DateTimeFormat/BasicFormatMatcher.d.ts +8 -0
  22. package/lib/src/DateTimeFormat/BasicFormatMatcher.d.ts.map +1 -0
  23. package/lib/src/DateTimeFormat/BasicFormatMatcher.js +61 -0
  24. package/lib/src/DateTimeFormat/BestFitFormatMatcher.d.ts +17 -0
  25. package/lib/src/DateTimeFormat/BestFitFormatMatcher.d.ts.map +1 -0
  26. package/lib/src/DateTimeFormat/BestFitFormatMatcher.js +119 -0
  27. package/lib/src/DateTimeFormat/DateTimeStyleFormat.d.ts +3 -0
  28. package/lib/src/DateTimeFormat/DateTimeStyleFormat.d.ts.map +1 -0
  29. package/lib/src/DateTimeFormat/DateTimeStyleFormat.js +50 -0
  30. package/lib/src/DateTimeFormat/FormatDateTime.d.ts +8 -0
  31. package/lib/src/DateTimeFormat/FormatDateTime.d.ts.map +1 -0
  32. package/lib/src/DateTimeFormat/FormatDateTime.js +15 -0
  33. package/lib/src/DateTimeFormat/FormatDateTimeToParts.d.ts +10 -0
  34. package/lib/src/DateTimeFormat/FormatDateTimeToParts.d.ts.map +1 -0
  35. package/lib/src/DateTimeFormat/FormatDateTimeToParts.js +21 -0
  36. package/lib/src/DateTimeFormat/InitializeDateTimeFormat.d.ts +18 -0
  37. package/lib/src/DateTimeFormat/InitializeDateTimeFormat.d.ts.map +1 -0
  38. package/lib/src/DateTimeFormat/InitializeDateTimeFormat.js +163 -0
  39. package/lib/src/DateTimeFormat/PartitionDateTimePattern.d.ts +13 -0
  40. package/lib/src/DateTimeFormat/PartitionDateTimePattern.d.ts.map +1 -0
  41. package/lib/src/DateTimeFormat/PartitionDateTimePattern.js +176 -0
  42. package/lib/src/DateTimeFormat/ToDateTimeOptions.d.ts +9 -0
  43. package/lib/src/DateTimeFormat/ToDateTimeOptions.d.ts.map +1 -0
  44. package/lib/src/DateTimeFormat/ToDateTimeOptions.js +57 -0
  45. package/lib/src/DateTimeFormat/ToLocalTime.d.ts +24 -0
  46. package/lib/src/DateTimeFormat/ToLocalTime.d.ts.map +1 -0
  47. package/lib/src/DateTimeFormat/ToLocalTime.js +49 -0
  48. package/lib/src/DateTimeFormat/skeleton.d.ts +9 -0
  49. package/lib/src/DateTimeFormat/skeleton.d.ts.map +1 -0
  50. package/lib/src/DateTimeFormat/skeleton.js +163 -0
  51. package/lib/src/DateTimeFormat/utils.d.ts +10 -0
  52. package/lib/src/DateTimeFormat/utils.d.ts.map +1 -0
  53. package/lib/src/DateTimeFormat/utils.js +18 -0
  54. package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts +2 -0
  55. package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts.map +1 -0
  56. package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.js +33 -0
  57. package/lib/src/GetOption.js +1 -1
  58. package/lib/src/IsValidTimeZoneName.d.ts +10 -0
  59. package/lib/src/IsValidTimeZoneName.d.ts.map +1 -0
  60. package/lib/src/IsValidTimeZoneName.js +11 -0
  61. package/lib/src/NumberFormat/ComputeExponent.d.ts +12 -0
  62. package/lib/src/NumberFormat/ComputeExponent.d.ts.map +1 -0
  63. package/lib/src/NumberFormat/ComputeExponent.js +39 -0
  64. package/lib/src/NumberFormat/ComputeExponentForMagnitude.d.ts +10 -0
  65. package/lib/src/NumberFormat/ComputeExponentForMagnitude.d.ts.map +1 -0
  66. package/lib/src/NumberFormat/ComputeExponentForMagnitude.js +60 -0
  67. package/lib/src/NumberFormat/CurrencyDigits.d.ts +7 -0
  68. package/lib/src/NumberFormat/CurrencyDigits.d.ts.map +1 -0
  69. package/lib/src/NumberFormat/CurrencyDigits.js +10 -0
  70. package/lib/src/NumberFormat/FormatNumericToParts.d.ts +5 -0
  71. package/lib/src/NumberFormat/FormatNumericToParts.d.ts.map +1 -0
  72. package/lib/src/NumberFormat/FormatNumericToParts.js +14 -0
  73. package/lib/src/NumberFormat/FormatNumericToString.js +1 -1
  74. package/lib/src/NumberFormat/InitializeNumberFormat.d.ts +13 -0
  75. package/lib/src/NumberFormat/InitializeNumberFormat.d.ts.map +1 -0
  76. package/lib/src/NumberFormat/InitializeNumberFormat.js +71 -0
  77. package/lib/src/NumberFormat/PartitionNumberPattern.d.ts +8 -0
  78. package/lib/src/NumberFormat/PartitionNumberPattern.d.ts.map +1 -0
  79. package/lib/src/NumberFormat/PartitionNumberPattern.js +74 -0
  80. package/lib/src/NumberFormat/SetNumberFormatUnitOptions.d.ts +8 -0
  81. package/lib/src/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +1 -0
  82. package/lib/src/NumberFormat/SetNumberFormatUnitOptions.js +39 -0
  83. package/lib/src/NumberFormat/digit-mapping.json +1 -0
  84. package/lib/src/NumberFormat/format_to_parts.d.ts +22 -0
  85. package/lib/src/NumberFormat/format_to_parts.d.ts.map +1 -0
  86. package/lib/src/NumberFormat/format_to_parts.js +421 -0
  87. package/lib/src/PluralRules/GetOperands.d.ts +32 -0
  88. package/lib/src/PluralRules/GetOperands.d.ts.map +1 -0
  89. package/lib/src/PluralRules/GetOperands.js +47 -0
  90. package/lib/src/PluralRules/InitializePluralRules.d.ts +9 -0
  91. package/lib/src/PluralRules/InitializePluralRules.d.ts.map +1 -0
  92. package/lib/src/PluralRules/InitializePluralRules.js +20 -0
  93. package/lib/src/PluralRules/ResolvePlural.d.ts +13 -0
  94. package/lib/src/PluralRules/ResolvePlural.d.ts.map +1 -0
  95. package/lib/src/PluralRules/ResolvePlural.js +25 -0
  96. package/lib/src/RelativeTimeFormat/FormatRelativeTime.d.ts +5 -0
  97. package/lib/src/RelativeTimeFormat/FormatRelativeTime.d.ts.map +1 -0
  98. package/lib/src/RelativeTimeFormat/FormatRelativeTime.js +10 -0
  99. package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts +5 -0
  100. package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts.map +1 -0
  101. package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.js +18 -0
  102. package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts +9 -0
  103. package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts.map +1 -0
  104. package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.js +32 -0
  105. package/lib/src/RelativeTimeFormat/MakePartsList.d.ts +3 -0
  106. package/lib/src/RelativeTimeFormat/MakePartsList.d.ts.map +1 -0
  107. package/lib/src/RelativeTimeFormat/MakePartsList.js +27 -0
  108. package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts +5 -0
  109. package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts.map +1 -0
  110. package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.js +54 -0
  111. package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts +7 -0
  112. package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts.map +1 -0
  113. package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.js +36 -0
  114. package/lib/src/SupportedLocales.js +1 -1
  115. package/lib/src/data.js +1 -1
  116. package/lib/types/core.js +1 -0
  117. package/lib/types/date-time.d.ts +112 -0
  118. package/lib/types/date-time.d.ts.map +1 -0
  119. package/lib/types/date-time.js +1 -0
  120. package/lib/types/displaynames.js +1 -0
  121. package/lib/types/list.js +1 -0
  122. package/lib/types/number.d.ts +44 -0
  123. package/lib/types/number.d.ts.map +1 -1
  124. package/lib/types/number.js +1 -0
  125. package/lib/types/plural-rules.d.ts +6 -0
  126. package/lib/types/plural-rules.d.ts.map +1 -1
  127. package/lib/types/plural-rules.js +1 -0
  128. package/lib/types/relative-time.d.ts +63 -0
  129. package/lib/types/relative-time.d.ts.map +1 -1
  130. package/lib/types/relative-time.js +1 -0
  131. package/package.json +2 -6
  132. package/src/CanonicalizeLocaleList.d.ts +6 -0
  133. package/src/CanonicalizeLocaleList.d.ts.map +1 -0
  134. package/src/CanonicalizeLocaleList.js +12 -0
  135. package/src/CanonicalizeTimeZoneName.d.ts +9 -0
  136. package/src/CanonicalizeTimeZoneName.d.ts.map +1 -0
  137. package/src/CanonicalizeTimeZoneName.js +21 -0
  138. package/src/DateTimeFormat/BasicFormatMatcher.d.ts +8 -0
  139. package/src/DateTimeFormat/BasicFormatMatcher.d.ts.map +1 -0
  140. package/src/DateTimeFormat/BasicFormatMatcher.js +65 -0
  141. package/src/DateTimeFormat/BestFitFormatMatcher.d.ts +17 -0
  142. package/src/DateTimeFormat/BestFitFormatMatcher.d.ts.map +1 -0
  143. package/src/DateTimeFormat/BestFitFormatMatcher.js +124 -0
  144. package/src/DateTimeFormat/DateTimeStyleFormat.d.ts +3 -0
  145. package/src/DateTimeFormat/DateTimeStyleFormat.d.ts.map +1 -0
  146. package/src/DateTimeFormat/DateTimeStyleFormat.js +54 -0
  147. package/src/DateTimeFormat/FormatDateTime.d.ts +8 -0
  148. package/src/DateTimeFormat/FormatDateTime.d.ts.map +1 -0
  149. package/src/DateTimeFormat/FormatDateTime.js +19 -0
  150. package/src/DateTimeFormat/FormatDateTimeToParts.d.ts +10 -0
  151. package/src/DateTimeFormat/FormatDateTimeToParts.d.ts.map +1 -0
  152. package/src/DateTimeFormat/FormatDateTimeToParts.js +25 -0
  153. package/src/DateTimeFormat/InitializeDateTimeFormat.d.ts +18 -0
  154. package/src/DateTimeFormat/InitializeDateTimeFormat.d.ts.map +1 -0
  155. package/src/DateTimeFormat/InitializeDateTimeFormat.js +167 -0
  156. package/src/DateTimeFormat/PartitionDateTimePattern.d.ts +13 -0
  157. package/src/DateTimeFormat/PartitionDateTimePattern.d.ts.map +1 -0
  158. package/src/DateTimeFormat/PartitionDateTimePattern.js +180 -0
  159. package/src/DateTimeFormat/ToDateTimeOptions.d.ts +9 -0
  160. package/src/DateTimeFormat/ToDateTimeOptions.d.ts.map +1 -0
  161. package/src/DateTimeFormat/ToDateTimeOptions.js +61 -0
  162. package/src/DateTimeFormat/ToLocalTime.d.ts +24 -0
  163. package/src/DateTimeFormat/ToLocalTime.d.ts.map +1 -0
  164. package/src/DateTimeFormat/ToLocalTime.js +53 -0
  165. package/src/DateTimeFormat/skeleton.d.ts +9 -0
  166. package/src/DateTimeFormat/skeleton.d.ts.map +1 -0
  167. package/src/DateTimeFormat/skeleton.js +167 -0
  168. package/src/DateTimeFormat/utils.d.ts +10 -0
  169. package/src/DateTimeFormat/utils.d.ts.map +1 -0
  170. package/src/DateTimeFormat/utils.js +21 -0
  171. package/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts +2 -0
  172. package/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts.map +1 -0
  173. package/src/DisplayNames/CanonicalCodeForDisplayNames.js +37 -0
  174. package/src/GetOption.js +2 -5
  175. package/src/IsValidTimeZoneName.d.ts +10 -0
  176. package/src/IsValidTimeZoneName.d.ts.map +1 -0
  177. package/src/IsValidTimeZoneName.js +15 -0
  178. package/src/NumberFormat/ComputeExponent.d.ts +12 -0
  179. package/src/NumberFormat/ComputeExponent.d.ts.map +1 -0
  180. package/src/NumberFormat/ComputeExponent.js +43 -0
  181. package/src/NumberFormat/ComputeExponentForMagnitude.d.ts +10 -0
  182. package/src/NumberFormat/ComputeExponentForMagnitude.d.ts.map +1 -0
  183. package/src/NumberFormat/ComputeExponentForMagnitude.js +64 -0
  184. package/src/NumberFormat/CurrencyDigits.d.ts +7 -0
  185. package/src/NumberFormat/CurrencyDigits.d.ts.map +1 -0
  186. package/src/NumberFormat/CurrencyDigits.js +14 -0
  187. package/src/NumberFormat/FormatNumericToParts.d.ts +5 -0
  188. package/src/NumberFormat/FormatNumericToParts.d.ts.map +1 -0
  189. package/src/NumberFormat/FormatNumericToParts.js +18 -0
  190. package/src/NumberFormat/FormatNumericToString.js +2 -5
  191. package/src/NumberFormat/InitializeNumberFormat.d.ts +13 -0
  192. package/src/NumberFormat/InitializeNumberFormat.d.ts.map +1 -0
  193. package/src/NumberFormat/InitializeNumberFormat.js +75 -0
  194. package/src/NumberFormat/PartitionNumberPattern.d.ts +8 -0
  195. package/src/NumberFormat/PartitionNumberPattern.d.ts.map +1 -0
  196. package/src/NumberFormat/PartitionNumberPattern.js +81 -0
  197. package/src/NumberFormat/SetNumberFormatUnitOptions.d.ts +8 -0
  198. package/src/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +1 -0
  199. package/src/NumberFormat/SetNumberFormatUnitOptions.js +43 -0
  200. package/src/NumberFormat/digit-mapping.json +1 -0
  201. package/src/NumberFormat/format_to_parts.d.ts +22 -0
  202. package/src/NumberFormat/format_to_parts.d.ts.map +1 -0
  203. package/src/NumberFormat/format_to_parts.js +443 -0
  204. package/src/PluralRules/GetOperands.d.ts +32 -0
  205. package/src/PluralRules/GetOperands.d.ts.map +1 -0
  206. package/src/PluralRules/GetOperands.js +51 -0
  207. package/src/PluralRules/InitializePluralRules.d.ts +9 -0
  208. package/src/PluralRules/InitializePluralRules.d.ts.map +1 -0
  209. package/src/PluralRules/InitializePluralRules.js +24 -0
  210. package/src/PluralRules/ResolvePlural.d.ts +13 -0
  211. package/src/PluralRules/ResolvePlural.d.ts.map +1 -0
  212. package/src/PluralRules/ResolvePlural.js +29 -0
  213. package/src/RelativeTimeFormat/FormatRelativeTime.d.ts +5 -0
  214. package/src/RelativeTimeFormat/FormatRelativeTime.d.ts.map +1 -0
  215. package/src/RelativeTimeFormat/FormatRelativeTime.js +14 -0
  216. package/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts +5 -0
  217. package/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts.map +1 -0
  218. package/src/RelativeTimeFormat/FormatRelativeTimeToParts.js +22 -0
  219. package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts +9 -0
  220. package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts.map +1 -0
  221. package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.js +36 -0
  222. package/src/RelativeTimeFormat/MakePartsList.d.ts +3 -0
  223. package/src/RelativeTimeFormat/MakePartsList.d.ts.map +1 -0
  224. package/src/RelativeTimeFormat/MakePartsList.js +31 -0
  225. package/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts +5 -0
  226. package/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts.map +1 -0
  227. package/src/RelativeTimeFormat/PartitionRelativeTimePattern.js +58 -0
  228. package/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts +7 -0
  229. package/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts.map +1 -0
  230. package/src/RelativeTimeFormat/SingularRelativeTimeUnit.js +40 -0
  231. package/src/SupportedLocales.js +2 -5
  232. package/src/data.js +1 -1
  233. package/types/date-time.d.ts +112 -0
  234. package/types/date-time.d.ts.map +1 -0
  235. package/types/date-time.js +2 -0
  236. package/types/number.d.ts +44 -0
  237. package/types/number.d.ts.map +1 -1
  238. package/types/plural-rules.d.ts +6 -0
  239. package/types/plural-rules.d.ts.map +1 -1
  240. package/types/relative-time.d.ts +63 -0
  241. package/types/relative-time.d.ts.map +1 -1
  242. package/types.js +1 -1
@@ -0,0 +1,119 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { invariant } from '../utils';
13
+ import { DATE_TIME_PROPS, removalPenalty, additionPenalty, differentNumericTypePenalty, longMorePenalty, shortMorePenalty, shortLessPenalty, longLessPenalty, } from './utils';
14
+ import { parseDateTimeSkeleton } from './skeleton';
15
+ function isNumericType(t) {
16
+ return t === 'numeric' || t === '2-digit';
17
+ }
18
+ /**
19
+ * Credit: https://github.com/andyearnshaw/Intl.js/blob/0958dc1ad8153f1056653ea22b8208f0df289a4e/src/12.datetimeformat.js#L611
20
+ * with some modifications
21
+ * @param options
22
+ * @param format
23
+ */
24
+ export function bestFitFormatMatcherScore(options, format) {
25
+ var score = 0;
26
+ if (options.hour12 && !format.hour12) {
27
+ score -= removalPenalty;
28
+ }
29
+ else if (!options.hour12 && format.hour12) {
30
+ score -= additionPenalty;
31
+ }
32
+ for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
33
+ var prop = DATE_TIME_PROPS_1[_i];
34
+ var optionsProp = options[prop];
35
+ var formatProp = format[prop];
36
+ if (optionsProp === undefined && formatProp !== undefined) {
37
+ score -= additionPenalty;
38
+ }
39
+ else if (optionsProp !== undefined && formatProp === undefined) {
40
+ score -= removalPenalty;
41
+ }
42
+ else if (optionsProp !== formatProp) {
43
+ // extra penalty for numeric vs non-numeric
44
+ if (isNumericType(optionsProp) !==
45
+ isNumericType(formatProp)) {
46
+ score -= differentNumericTypePenalty;
47
+ }
48
+ else {
49
+ var values = ['2-digit', 'numeric', 'narrow', 'short', 'long'];
50
+ var optionsPropIndex = values.indexOf(optionsProp);
51
+ var formatPropIndex = values.indexOf(formatProp);
52
+ var delta = Math.max(-2, Math.min(formatPropIndex - optionsPropIndex, 2));
53
+ if (delta === 2) {
54
+ score -= longMorePenalty;
55
+ }
56
+ else if (delta === 1) {
57
+ score -= shortMorePenalty;
58
+ }
59
+ else if (delta === -1) {
60
+ score -= shortLessPenalty;
61
+ }
62
+ else if (delta === -2) {
63
+ score -= longLessPenalty;
64
+ }
65
+ }
66
+ }
67
+ }
68
+ return score;
69
+ }
70
+ /**
71
+ * https://tc39.es/ecma402/#sec-bestfitformatmatcher
72
+ * Just alias to basic for now
73
+ * @param options
74
+ * @param formats
75
+ * @param implDetails Implementation details
76
+ */
77
+ export function BestFitFormatMatcher(options, formats) {
78
+ var bestScore = -Infinity;
79
+ var bestFormat = formats[0];
80
+ invariant(Array.isArray(formats), 'formats should be a list of things');
81
+ for (var _i = 0, formats_1 = formats; _i < formats_1.length; _i++) {
82
+ var format = formats_1[_i];
83
+ var score = bestFitFormatMatcherScore(options, format);
84
+ if (score > bestScore) {
85
+ bestScore = score;
86
+ bestFormat = format;
87
+ }
88
+ }
89
+ var skeletonFormat = __assign({}, bestFormat);
90
+ var patternFormat = parseDateTimeSkeleton(bestFormat.rawPattern);
91
+ // Kinda following https://github.com/unicode-org/icu/blob/dd50e38f459d84e9bf1b0c618be8483d318458ad/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java
92
+ // Method adjustFieldTypes
93
+ for (var prop in patternFormat) {
94
+ var skeletonValue = skeletonFormat[prop];
95
+ var patternValue = patternFormat[prop];
96
+ var requestedValue = options[prop];
97
+ // Don't mess with minute/second or we can get in the situation of
98
+ // 7:0:0 which is weird
99
+ if (prop === 'minute' || prop === 'second') {
100
+ continue;
101
+ }
102
+ // Nothing to do here
103
+ if (!requestedValue) {
104
+ continue;
105
+ }
106
+ // https://unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons
107
+ // Looks like we should not convert numeric to alphabetic but the other way
108
+ // around is ok
109
+ if (isNumericType(patternValue) &&
110
+ !isNumericType(requestedValue)) {
111
+ continue;
112
+ }
113
+ if (skeletonValue === requestedValue) {
114
+ continue;
115
+ }
116
+ patternFormat[prop] = requestedValue;
117
+ }
118
+ return patternFormat;
119
+ }
@@ -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,50 @@
1
+ import { invariant } from '../utils';
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
+ }
@@ -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,15 @@
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
+ }
@@ -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,21 @@
1
+ import { PartitionDateTimePattern } from './PartitionDateTimePattern';
2
+ import { ArrayCreate } from '../../262';
3
+ /**
4
+ * https://tc39.es/ecma402/#sec-formatdatetimetoparts
5
+ *
6
+ * @param dtf
7
+ * @param x
8
+ * @param implDetails
9
+ */
10
+ export function FormatDateTimeToParts(dtf, x, implDetails) {
11
+ var parts = PartitionDateTimePattern(dtf, x, implDetails);
12
+ var result = ArrayCreate(0);
13
+ for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
14
+ var part = parts_1[_i];
15
+ result.push({
16
+ type: part.type,
17
+ value: part.value,
18
+ });
19
+ }
20
+ return result;
21
+ }
@@ -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,163 @@
1
+ import { CanonicalizeLocaleList } from '../CanonicalizeLocaleList';
2
+ import { ToDateTimeOptions } from './ToDateTimeOptions';
3
+ import { GetOption } from '../GetOption';
4
+ import { ResolveLocale } from '../ResolveLocale';
5
+ import { IsValidTimeZoneName } from '../IsValidTimeZoneName';
6
+ import { CanonicalizeTimeZoneName } from '../CanonicalizeTimeZoneName';
7
+ import { BasicFormatMatcher } from './BasicFormatMatcher';
8
+ import { BestFitFormatMatcher } from './BestFitFormatMatcher';
9
+ import { invariant } from '../utils';
10
+ import { DATE_TIME_PROPS } from './utils';
11
+ import { DateTimeStyleFormat } from './DateTimeStyleFormat';
12
+ function isTimeRelated(opt) {
13
+ for (var _i = 0, _a = ['hour', 'minute', 'second']; _i < _a.length; _i++) {
14
+ var prop = _a[_i];
15
+ var value = opt[prop];
16
+ if (value !== undefined) {
17
+ return true;
18
+ }
19
+ }
20
+ return false;
21
+ }
22
+ var TYPE_REGEX = /^[a-z0-9]{3,8}$/i;
23
+ /**
24
+ * https://tc39.es/ecma402/#sec-initializedatetimeformat
25
+ * @param dtf DateTimeFormat
26
+ * @param locales locales
27
+ * @param opts options
28
+ */
29
+ export function InitializeDateTimeFormat(dtf, locales, opts, _a) {
30
+ 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;
31
+ // @ts-ignore
32
+ var requestedLocales = CanonicalizeLocaleList(locales);
33
+ var options = ToDateTimeOptions(opts, 'any', 'date');
34
+ var opt = Object.create(null);
35
+ var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
36
+ opt.localeMatcher = matcher;
37
+ var calendar = GetOption(options, 'calendar', 'string', undefined, undefined);
38
+ if (calendar !== undefined && !TYPE_REGEX.test(calendar)) {
39
+ throw new RangeError('Malformed calendar');
40
+ }
41
+ var internalSlots = getInternalSlots(dtf);
42
+ opt.ca = calendar;
43
+ var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
44
+ if (numberingSystem !== undefined && !TYPE_REGEX.test(numberingSystem)) {
45
+ throw new RangeError('Malformed numbering system');
46
+ }
47
+ opt.nu = numberingSystem;
48
+ var hour12 = GetOption(options, 'hour12', 'boolean', undefined, undefined);
49
+ var hourCycle = GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
50
+ if (hour12 !== undefined) {
51
+ // @ts-ignore
52
+ hourCycle = null;
53
+ }
54
+ opt.hc = hourCycle;
55
+ var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
56
+ internalSlots.locale = r.locale;
57
+ calendar = r.ca;
58
+ internalSlots.calendar = calendar;
59
+ internalSlots.hourCycle = r.hc;
60
+ internalSlots.numberingSystem = r.nu;
61
+ var dataLocale = r.dataLocale;
62
+ internalSlots.dataLocale = dataLocale;
63
+ var timeZone = options.timeZone;
64
+ if (timeZone !== undefined) {
65
+ timeZone = String(timeZone);
66
+ if (!IsValidTimeZoneName(timeZone, { tzData: tzData, uppercaseLinks: uppercaseLinks })) {
67
+ throw new RangeError('Invalid timeZoneName');
68
+ }
69
+ timeZone = CanonicalizeTimeZoneName(timeZone, { tzData: tzData, uppercaseLinks: uppercaseLinks });
70
+ }
71
+ else {
72
+ timeZone = getDefaultTimeZone();
73
+ }
74
+ internalSlots.timeZone = timeZone;
75
+ opt = Object.create(null);
76
+ opt.weekday = GetOption(options, 'weekday', 'string', ['narrow', 'short', 'long'], undefined);
77
+ opt.era = GetOption(options, 'era', 'string', ['narrow', 'short', 'long'], undefined);
78
+ opt.year = GetOption(options, 'year', 'string', ['2-digit', 'numeric'], undefined);
79
+ opt.month = GetOption(options, 'month', 'string', ['2-digit', 'numeric', 'narrow', 'short', 'long'], undefined);
80
+ opt.day = GetOption(options, 'day', 'string', ['2-digit', 'numeric'], undefined);
81
+ opt.hour = GetOption(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
82
+ opt.minute = GetOption(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
83
+ opt.second = GetOption(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
84
+ opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', ['short', 'long'], undefined);
85
+ var dataLocaleData = localeData[dataLocale];
86
+ var formats = dataLocaleData.formats[calendar];
87
+ matcher = GetOption(options, 'formatMatcher', 'string', ['basic', 'best fit'], 'best fit');
88
+ var dateStyle = GetOption(options, 'dateStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
89
+ internalSlots.dateStyle = dateStyle;
90
+ var timeStyle = GetOption(options, 'timeStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
91
+ internalSlots.timeStyle = timeStyle;
92
+ var bestFormat;
93
+ if (dateStyle === undefined && timeStyle === undefined) {
94
+ if (matcher === 'basic') {
95
+ bestFormat = BasicFormatMatcher(opt, formats);
96
+ }
97
+ else {
98
+ if (isTimeRelated(opt)) {
99
+ opt.hour12 =
100
+ internalSlots.hourCycle === 'h11' ||
101
+ internalSlots.hourCycle === 'h12';
102
+ }
103
+ bestFormat = BestFitFormatMatcher(opt, formats);
104
+ }
105
+ }
106
+ else {
107
+ for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
108
+ var prop = DATE_TIME_PROPS_1[_i];
109
+ var p = opt[prop];
110
+ if (p !== undefined) {
111
+ throw new TypeError("Intl.DateTimeFormat can't set option " + prop + " when " + (dateStyle ? 'dateStyle' : 'timeStyle') + " is used");
112
+ }
113
+ }
114
+ bestFormat = DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData);
115
+ }
116
+ for (var prop in opt) {
117
+ var p = bestFormat[prop];
118
+ if (p !== undefined) {
119
+ internalSlots[prop] = p;
120
+ }
121
+ }
122
+ var pattern;
123
+ if (internalSlots.hour !== undefined) {
124
+ var hcDefault = dataLocaleData.hourCycle;
125
+ var hc = internalSlots.hourCycle;
126
+ if (hc == null) {
127
+ hc = hcDefault;
128
+ }
129
+ if (hour12 !== undefined) {
130
+ if (hour12) {
131
+ if (hcDefault === 'h11' || hcDefault === 'h23') {
132
+ hc = 'h11';
133
+ }
134
+ else {
135
+ hc = 'h12';
136
+ }
137
+ }
138
+ else {
139
+ invariant(!hour12, 'hour12 must not be set');
140
+ if (hcDefault === 'h11' || hcDefault === 'h23') {
141
+ hc = 'h23';
142
+ }
143
+ else {
144
+ hc = 'h24';
145
+ }
146
+ }
147
+ }
148
+ internalSlots.hourCycle = hc;
149
+ if (hc === 'h11' || hc === 'h12') {
150
+ pattern = bestFormat.pattern12;
151
+ }
152
+ else {
153
+ pattern = bestFormat.pattern;
154
+ }
155
+ }
156
+ else {
157
+ // @ts-ignore
158
+ internalSlots.hourCycle = undefined;
159
+ pattern = bestFormat.pattern;
160
+ }
161
+ internalSlots.pattern = pattern;
162
+ return dtf;
163
+ }
@@ -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"}
@@ -0,0 +1,176 @@
1
+ import { TimeClip } from '../../262';
2
+ import { PartitionPattern } from '../PartitionPattern';
3
+ import { DATE_TIME_PROPS } from './utils';
4
+ import { ToLocalTime } from './ToLocalTime';
5
+ function pad(n) {
6
+ if (n < 10) {
7
+ return "0" + 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
30
+ .replace(/H+/, String(hours))
31
+ .replace(/m+/, String(mins));
32
+ }
33
+ return gmtFormat.replace('{0}', offsetStr);
34
+ }
35
+ /**
36
+ * https://tc39.es/ecma402/#sec-partitiondatetimepattern
37
+ * @param dtf
38
+ * @param x
39
+ */
40
+ export function PartitionDateTimePattern(dtf, x, _a) {
41
+ var getInternalSlots = _a.getInternalSlots, localeData = _a.localeData, getDefaultTimeZone = _a.getDefaultTimeZone, tzData = _a.tzData;
42
+ x = TimeClip(x);
43
+ if (isNaN(x)) {
44
+ throw new RangeError('invalid time');
45
+ }
46
+ /** IMPL START */
47
+ var internalSlots = getInternalSlots(dtf);
48
+ var dataLocale = internalSlots.dataLocale;
49
+ var dataLocaleData = localeData[dataLocale];
50
+ /** IMPL END */
51
+ var locale = internalSlots.locale;
52
+ var nfOptions = Object.create(null);
53
+ nfOptions.useGrouping = false;
54
+ var nf = new Intl.NumberFormat(locale, nfOptions);
55
+ var nf2Options = Object.create(null);
56
+ nf2Options.minimumIntegerDigits = 2;
57
+ nf2Options.useGrouping = false;
58
+ var nf2 = new Intl.NumberFormat(locale, nf2Options);
59
+ var tm = ToLocalTime(x,
60
+ // @ts-ignore
61
+ internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
62
+ var result = [];
63
+ var patternParts = PartitionPattern(internalSlots.pattern);
64
+ for (var _i = 0, patternParts_1 = patternParts; _i < patternParts_1.length; _i++) {
65
+ var patternPart = patternParts_1[_i];
66
+ var p = patternPart.type;
67
+ if (p === 'literal') {
68
+ result.push({
69
+ type: 'literal',
70
+ value: patternPart.value,
71
+ });
72
+ }
73
+ else if (DATE_TIME_PROPS.indexOf(p) > -1) {
74
+ var fv = '';
75
+ var f = internalSlots[p];
76
+ // @ts-ignore
77
+ var v = tm[p];
78
+ if (p === 'year' && v <= 0) {
79
+ v = 1 - v;
80
+ }
81
+ if (p === 'month') {
82
+ v++;
83
+ }
84
+ var hourCycle = internalSlots.hourCycle;
85
+ if (p === 'hour' && (hourCycle === 'h11' || hourCycle === 'h12')) {
86
+ v = v % 12;
87
+ if (v === 0 && hourCycle === 'h12') {
88
+ v = 12;
89
+ }
90
+ }
91
+ if (p === 'hour' && hourCycle === 'h24') {
92
+ if (v === 0) {
93
+ v = 24;
94
+ }
95
+ }
96
+ if (f === 'numeric') {
97
+ fv = nf.format(v);
98
+ }
99
+ else if (f === '2-digit') {
100
+ fv = nf2.format(v);
101
+ if (fv.length > 2) {
102
+ fv = fv.slice(fv.length - 2, fv.length);
103
+ }
104
+ }
105
+ else if (f === 'narrow' || f === 'short' || f === 'long') {
106
+ if (p === 'era') {
107
+ fv = dataLocaleData[p][f][v];
108
+ }
109
+ else if (p === 'timeZoneName') {
110
+ var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat;
111
+ var timeZone = internalSlots.timeZone || getDefaultTimeZone();
112
+ var timeZoneData = timeZoneName[timeZone];
113
+ if (timeZoneData && timeZoneData[f]) {
114
+ fv = timeZoneData[f][+tm.inDST];
115
+ }
116
+ else {
117
+ // Fallback to gmtFormat
118
+ fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f);
119
+ }
120
+ }
121
+ else if (p === 'month') {
122
+ fv = dataLocaleData.month[f][v - 1];
123
+ }
124
+ else {
125
+ fv = dataLocaleData[p][f][v];
126
+ }
127
+ }
128
+ result.push({
129
+ type: p,
130
+ value: fv,
131
+ });
132
+ }
133
+ else if (p === 'ampm') {
134
+ var v = tm.hour;
135
+ var fv = void 0;
136
+ if (v > 11) {
137
+ fv = dataLocaleData.pm;
138
+ }
139
+ else {
140
+ fv = dataLocaleData.am;
141
+ }
142
+ result.push({
143
+ type: 'dayPeriod',
144
+ value: fv,
145
+ });
146
+ }
147
+ else if (p === 'relatedYear') {
148
+ var v = tm.relatedYear;
149
+ // @ts-ignore
150
+ var fv = nf.format(v);
151
+ result.push({
152
+ // @ts-ignore TODO: Fix TS type
153
+ type: 'relatedYear',
154
+ value: fv,
155
+ });
156
+ }
157
+ else if (p === 'yearName') {
158
+ var v = tm.yearName;
159
+ // @ts-ignore
160
+ var fv = nf.format(v);
161
+ result.push({
162
+ // @ts-ignore TODO: Fix TS type
163
+ type: 'yearName',
164
+ value: fv,
165
+ });
166
+ }
167
+ else {
168
+ result.push({
169
+ // @ts-ignore TODO: Fix TS type
170
+ type: 'unknown',
171
+ value: String(x),
172
+ });
173
+ }
174
+ }
175
+ return result;
176
+ }
@@ -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"}