@formatjs/intl-datetimeformat 6.18.2 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -4
  3. package/package.json +14 -6
  4. package/polyfill-force.js +13 -15
  5. package/polyfill.iife.js +44 -44
  6. package/polyfill.js +15 -17
  7. package/should-polyfill.js +7 -10
  8. package/src/abstract/BasicFormatMatcher.js +26 -29
  9. package/src/abstract/BestFitFormatMatcher.js +19 -23
  10. package/src/abstract/DateTimeStyleFormat.js +5 -8
  11. package/src/abstract/FormatDateTime.d.ts +1 -1
  12. package/src/abstract/FormatDateTime.js +3 -6
  13. package/src/abstract/FormatDateTimePattern.d.ts +1 -1
  14. package/src/abstract/FormatDateTimePattern.js +12 -16
  15. package/src/abstract/FormatDateTimeRange.d.ts +2 -2
  16. package/src/abstract/FormatDateTimeRange.js +3 -6
  17. package/src/abstract/FormatDateTimeRangeToParts.d.ts +2 -2
  18. package/src/abstract/FormatDateTimeRangeToParts.js +4 -7
  19. package/src/abstract/FormatDateTimeToParts.d.ts +1 -1
  20. package/src/abstract/FormatDateTimeToParts.js +5 -8
  21. package/src/abstract/InitializeDateTimeFormat.js +37 -40
  22. package/src/abstract/PartitionDateTimePattern.d.ts +2 -2
  23. package/src/abstract/PartitionDateTimePattern.js +6 -9
  24. package/src/abstract/PartitionDateTimeRangePattern.d.ts +2 -2
  25. package/src/abstract/PartitionDateTimeRangePattern.js +16 -19
  26. package/src/abstract/ToDateTimeOptions.js +3 -6
  27. package/src/abstract/ToLocalTime.js +11 -14
  28. package/src/abstract/skeleton.js +14 -20
  29. package/src/abstract/utils.js +9 -12
  30. package/src/core.d.ts +1 -1
  31. package/src/core.js +115 -116
  32. package/src/data/all-tz.js +1 -3
  33. package/src/data/links.js +1 -3
  34. package/src/get_internal_slots.js +1 -4
  35. package/src/packer.d.ts +1 -1
  36. package/src/packer.js +5 -9
  37. package/src/to_locale_string.js +8 -13
  38. package/src/types.d.ts +1 -1
  39. package/src/types.js +1 -2
  40. package/supported-locales.generated.js +1 -4
  41. package/test262-main.d.ts +1 -1
  42. package/test262-main.js +3 -6
  43. package/lib/index.d.ts +0 -1
  44. package/lib/index.js +0 -1
  45. package/lib/polyfill-force.d.ts +0 -1
  46. package/lib/polyfill-force.js +0 -44
  47. package/lib/polyfill.d.ts +0 -1
  48. package/lib/polyfill.js +0 -47
  49. package/lib/should-polyfill.d.ts +0 -1
  50. package/lib/should-polyfill.js +0 -61
  51. package/lib/src/abstract/BasicFormatMatcher.d.ts +0 -7
  52. package/lib/src/abstract/BasicFormatMatcher.js +0 -106
  53. package/lib/src/abstract/BestFitFormatMatcher.d.ts +0 -16
  54. package/lib/src/abstract/BestFitFormatMatcher.js +0 -116
  55. package/lib/src/abstract/DateTimeStyleFormat.d.ts +0 -2
  56. package/lib/src/abstract/DateTimeStyleFormat.js +0 -50
  57. package/lib/src/abstract/FormatDateTime.d.ts +0 -9
  58. package/lib/src/abstract/FormatDateTime.js +0 -15
  59. package/lib/src/abstract/FormatDateTimePattern.d.ts +0 -14
  60. package/lib/src/abstract/FormatDateTimePattern.js +0 -191
  61. package/lib/src/abstract/FormatDateTimeRange.d.ts +0 -4
  62. package/lib/src/abstract/FormatDateTimeRange.js +0 -10
  63. package/lib/src/abstract/FormatDateTimeRangeToParts.d.ts +0 -5
  64. package/lib/src/abstract/FormatDateTimeRangeToParts.js +0 -14
  65. package/lib/src/abstract/FormatDateTimeToParts.d.ts +0 -11
  66. package/lib/src/abstract/FormatDateTimeToParts.js +0 -21
  67. package/lib/src/abstract/InitializeDateTimeFormat.d.ts +0 -17
  68. package/lib/src/abstract/InitializeDateTimeFormat.js +0 -190
  69. package/lib/src/abstract/PartitionDateTimePattern.d.ts +0 -10
  70. package/lib/src/abstract/PartitionDateTimePattern.js +0 -17
  71. package/lib/src/abstract/PartitionDateTimeRangePattern.d.ts +0 -5
  72. package/lib/src/abstract/PartitionDateTimeRangePattern.js +0 -119
  73. package/lib/src/abstract/ToDateTimeOptions.d.ts +0 -7
  74. package/lib/src/abstract/ToDateTimeOptions.js +0 -63
  75. package/lib/src/abstract/ToLocalTime.d.ts +0 -26
  76. package/lib/src/abstract/ToLocalTime.js +0 -49
  77. package/lib/src/abstract/skeleton.d.ts +0 -13
  78. package/lib/src/abstract/skeleton.js +0 -294
  79. package/lib/src/abstract/utils.d.ts +0 -10
  80. package/lib/src/abstract/utils.js +0 -21
  81. package/lib/src/core.d.ts +0 -20
  82. package/lib/src/core.js +0 -300
  83. package/lib/src/data/all-tz.d.ts +0 -6
  84. package/lib/src/data/all-tz.js +0 -461
  85. package/lib/src/data/links.d.ts +0 -259
  86. package/lib/src/data/links.js +0 -260
  87. package/lib/src/get_internal_slots.d.ts +0 -2
  88. package/lib/src/get_internal_slots.js +0 -11
  89. package/lib/src/packer.d.ts +0 -4
  90. package/lib/src/packer.js +0 -39
  91. package/lib/src/to_locale_string.d.ts +0 -7
  92. package/lib/src/to_locale_string.js +0 -19
  93. package/lib/src/types.d.ts +0 -47
  94. package/lib/src/types.js +0 -1
  95. package/lib/supported-locales.generated.d.ts +0 -1
  96. package/lib/supported-locales.generated.js +0 -1
  97. package/lib/test262-main.d.ts +0 -1
  98. package/lib/test262-main.js +0 -23786
@@ -1,14 +0,0 @@
1
- import { PartitionDateTimeRangePattern } from './PartitionDateTimeRangePattern';
2
- export function FormatDateTimeRangeToParts(dtf, x, y, implDetails) {
3
- var parts = PartitionDateTimeRangePattern(dtf, x, y, implDetails);
4
- var result = new Array(0);
5
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
6
- var part = parts_1[_i];
7
- result.push({
8
- type: part.type,
9
- value: part.value,
10
- source: part.source,
11
- });
12
- }
13
- return result;
14
- }
@@ -1,11 +0,0 @@
1
- import { IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
2
- import Decimal from 'decimal.js';
3
- import { PartitionDateTimePattern } from './PartitionDateTimePattern';
4
- /**
5
- * https://tc39.es/ecma402/#sec-formatdatetimetoparts
6
- *
7
- * @param dtf
8
- * @param x
9
- * @param implDetails
10
- */
11
- export declare function FormatDateTimeToParts(dtf: Intl.DateTimeFormat, x: Decimal, implDetails: Parameters<typeof PartitionDateTimePattern>[2]): IntlDateTimeFormatPart[];
@@ -1,21 +0,0 @@
1
- import { ArrayCreate } from '@formatjs/ecma402-abstract';
2
- import { PartitionDateTimePattern } from './PartitionDateTimePattern';
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
- }
@@ -1,17 +0,0 @@
1
- import { DateTimeFormat, DateTimeFormatLocaleInternalData, IntlDateTimeFormatInternal } from '@formatjs/ecma402-abstract';
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 | DateTimeFormat, locales: string | string[] | undefined, opts: Intl.DateTimeFormatOptions | undefined, { getInternalSlots, availableLocales, localeData, getDefaultLocale, getDefaultTimeZone, relevantExtensionKeys, tzData, uppercaseLinks, }: {
9
- getInternalSlots(dtf: DateTimeFormat | Intl.DateTimeFormat): IntlDateTimeFormatInternal;
10
- availableLocales: Set<string>;
11
- getDefaultLocale(): string;
12
- getDefaultTimeZone(): string;
13
- relevantExtensionKeys: string[];
14
- localeData: Record<string, DateTimeFormatLocaleInternalData | undefined>;
15
- tzData: Record<string, unknown>;
16
- uppercaseLinks: Record<string, string>;
17
- }): Intl.DateTimeFormat;
@@ -1,190 +0,0 @@
1
- import { CanonicalizeLocaleList, CanonicalizeTimeZoneName, GetNumberOption, GetOption, IsValidTimeZoneName, invariant, } from '@formatjs/ecma402-abstract';
2
- import { ResolveLocale } from '@formatjs/intl-localematcher';
3
- import { BasicFormatMatcher } from './BasicFormatMatcher';
4
- import { BestFitFormatMatcher } from './BestFitFormatMatcher';
5
- import { DateTimeStyleFormat } from './DateTimeStyleFormat';
6
- import { ToDateTimeOptions } from './ToDateTimeOptions';
7
- import { DATE_TIME_PROPS } from './utils';
8
- function isTimeRelated(opt) {
9
- for (var _i = 0, _a = ['hour', 'minute', 'second']; _i < _a.length; _i++) {
10
- var prop = _a[_i];
11
- var value = opt[prop];
12
- if (value !== undefined) {
13
- return true;
14
- }
15
- }
16
- return false;
17
- }
18
- function resolveHourCycle(hc, hcDefault, hour12) {
19
- if (hc == null) {
20
- hc = hcDefault;
21
- }
22
- if (hour12 !== undefined) {
23
- if (hour12) {
24
- if (hcDefault === 'h11' || hcDefault === 'h23') {
25
- hc = 'h11';
26
- }
27
- else {
28
- hc = 'h12';
29
- }
30
- }
31
- else {
32
- invariant(!hour12, 'hour12 must not be set');
33
- if (hcDefault === 'h11' || hcDefault === 'h23') {
34
- hc = 'h23';
35
- }
36
- else {
37
- hc = 'h24';
38
- }
39
- }
40
- }
41
- return hc;
42
- }
43
- var TYPE_REGEX = /^[a-z0-9]{3,8}$/i;
44
- /**
45
- * https://tc39.es/ecma402/#sec-initializedatetimeformat
46
- * @param dtf DateTimeFormat
47
- * @param locales locales
48
- * @param opts options
49
- */
50
- export function InitializeDateTimeFormat(dtf, locales, opts, _a) {
51
- var getInternalSlots = _a.getInternalSlots, availableLocales = _a.availableLocales, localeData = _a.localeData, getDefaultLocale = _a.getDefaultLocale, getDefaultTimeZone = _a.getDefaultTimeZone, relevantExtensionKeys = _a.relevantExtensionKeys, tzData = _a.tzData, uppercaseLinks = _a.uppercaseLinks;
52
- // @ts-ignore
53
- var requestedLocales = CanonicalizeLocaleList(locales);
54
- var options = ToDateTimeOptions(opts, 'any', 'date');
55
- var opt = Object.create(null);
56
- var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
57
- opt.localeMatcher = matcher;
58
- var calendar = GetOption(options, 'calendar', 'string', undefined, undefined);
59
- if (calendar !== undefined && !TYPE_REGEX.test(calendar)) {
60
- throw new RangeError('Malformed calendar');
61
- }
62
- var internalSlots = getInternalSlots(dtf);
63
- opt.ca = calendar;
64
- var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
65
- if (numberingSystem !== undefined && !TYPE_REGEX.test(numberingSystem)) {
66
- throw new RangeError('Malformed numbering system');
67
- }
68
- opt.nu = numberingSystem;
69
- var hour12 = GetOption(options, 'hour12', 'boolean', undefined, undefined);
70
- var hourCycle = GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
71
- if (hour12 !== undefined) {
72
- // @ts-ignore
73
- hourCycle = null;
74
- }
75
- opt.hc = hourCycle;
76
- var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
77
- internalSlots.locale = r.locale;
78
- calendar = r.ca;
79
- internalSlots.calendar = calendar;
80
- internalSlots.hourCycle = r.hc;
81
- internalSlots.numberingSystem = r.nu;
82
- var dataLocale = r.dataLocale;
83
- internalSlots.dataLocale = dataLocale;
84
- var timeZone = options.timeZone;
85
- if (timeZone !== undefined) {
86
- timeZone = String(timeZone);
87
- if (!IsValidTimeZoneName(timeZone, {
88
- zoneNamesFromData: Object.keys(tzData),
89
- uppercaseLinks: uppercaseLinks,
90
- })) {
91
- throw new RangeError('Invalid timeZoneName');
92
- }
93
- timeZone = CanonicalizeTimeZoneName(timeZone, {
94
- zoneNames: Object.keys(tzData),
95
- uppercaseLinks: uppercaseLinks,
96
- });
97
- }
98
- else {
99
- timeZone = getDefaultTimeZone();
100
- }
101
- internalSlots.timeZone = timeZone;
102
- opt = Object.create(null);
103
- opt.weekday = GetOption(options, 'weekday', 'string', ['narrow', 'short', 'long'], undefined);
104
- opt.era = GetOption(options, 'era', 'string', ['narrow', 'short', 'long'], undefined);
105
- opt.year = GetOption(options, 'year', 'string', ['2-digit', 'numeric'], undefined);
106
- opt.month = GetOption(options, 'month', 'string', ['2-digit', 'numeric', 'narrow', 'short', 'long'], undefined);
107
- opt.day = GetOption(options, 'day', 'string', ['2-digit', 'numeric'], undefined);
108
- opt.hour = GetOption(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
109
- opt.minute = GetOption(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
110
- opt.second = GetOption(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
111
- opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', [
112
- 'long',
113
- 'short',
114
- 'longOffset',
115
- 'shortOffset',
116
- 'longGeneric',
117
- 'shortGeneric',
118
- ], undefined);
119
- opt.fractionalSecondDigits = GetNumberOption(options, 'fractionalSecondDigits', 1, 3, undefined);
120
- var dataLocaleData = localeData[dataLocale];
121
- invariant(!!dataLocaleData, "Missing locale data for ".concat(dataLocale));
122
- var formats = dataLocaleData.formats[calendar];
123
- // UNSPECCED: IMPLEMENTATION DETAILS
124
- if (!formats) {
125
- throw new RangeError("Calendar \"".concat(calendar, "\" is not supported. Try setting \"calendar\" to 1 of the following: ").concat(Object.keys(dataLocaleData.formats).join(', ')));
126
- }
127
- var formatMatcher = GetOption(options, 'formatMatcher', 'string', ['basic', 'best fit'], 'best fit');
128
- var dateStyle = GetOption(options, 'dateStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
129
- internalSlots.dateStyle = dateStyle;
130
- var timeStyle = GetOption(options, 'timeStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
131
- internalSlots.timeStyle = timeStyle;
132
- var bestFormat;
133
- if (dateStyle === undefined && timeStyle === undefined) {
134
- if (formatMatcher === 'basic') {
135
- bestFormat = BasicFormatMatcher(opt, formats);
136
- }
137
- else {
138
- // IMPL DETAILS START
139
- if (isTimeRelated(opt)) {
140
- var hc = resolveHourCycle(internalSlots.hourCycle, dataLocaleData.hourCycle, hour12);
141
- opt.hour12 = hc === 'h11' || hc === 'h12';
142
- }
143
- // IMPL DETAILS END
144
- bestFormat = BestFitFormatMatcher(opt, formats);
145
- }
146
- }
147
- else {
148
- for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
149
- var prop = DATE_TIME_PROPS_1[_i];
150
- var p = opt[prop];
151
- if (p !== undefined) {
152
- throw new TypeError("Intl.DateTimeFormat can't set option ".concat(prop, " when ").concat(dateStyle ? 'dateStyle' : 'timeStyle', " is used"));
153
- }
154
- }
155
- bestFormat = DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData);
156
- }
157
- // IMPL DETAIL START
158
- // For debugging
159
- internalSlots.format = bestFormat;
160
- // IMPL DETAIL END
161
- for (var prop in opt) {
162
- var p = bestFormat[prop];
163
- if (p !== undefined) {
164
- internalSlots[prop] = p;
165
- }
166
- }
167
- var pattern;
168
- var rangePatterns;
169
- if (internalSlots.hour !== undefined) {
170
- var hc = resolveHourCycle(internalSlots.hourCycle, dataLocaleData.hourCycle, hour12);
171
- internalSlots.hourCycle = hc;
172
- if (hc === 'h11' || hc === 'h12') {
173
- pattern = bestFormat.pattern12;
174
- rangePatterns = bestFormat.rangePatterns12;
175
- }
176
- else {
177
- pattern = bestFormat.pattern;
178
- rangePatterns = bestFormat.rangePatterns;
179
- }
180
- }
181
- else {
182
- // @ts-ignore
183
- internalSlots.hourCycle = undefined;
184
- pattern = bestFormat.pattern;
185
- rangePatterns = bestFormat.rangePatterns;
186
- }
187
- internalSlots.pattern = pattern;
188
- internalSlots.rangePatterns = rangePatterns;
189
- return dtf; // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged
190
- }
@@ -1,10 +0,0 @@
1
- import { DateTimeFormat, IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
2
- import Decimal from 'decimal.js';
3
- import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern';
4
- import { ToLocalTimeImplDetails } from './ToLocalTime';
5
- /**
6
- * https://tc39.es/ecma402/#sec-partitiondatetimepattern
7
- * @param dtf
8
- * @param x
9
- */
10
- export declare function PartitionDateTimePattern(dtf: Intl.DateTimeFormat | DateTimeFormat, x: Decimal, implDetails: ToLocalTimeImplDetails & FormatDateTimePatternImplDetails): IntlDateTimeFormatPart[];
@@ -1,17 +0,0 @@
1
- import { invariant, PartitionPattern, TimeClip, } from '@formatjs/ecma402-abstract';
2
- import { FormatDateTimePattern, } from './FormatDateTimePattern';
3
- /**
4
- * https://tc39.es/ecma402/#sec-partitiondatetimepattern
5
- * @param dtf
6
- * @param x
7
- */
8
- export function PartitionDateTimePattern(dtf, x, implDetails) {
9
- x = TimeClip(x);
10
- invariant(!x.isNaN(), 'Invalid time', RangeError);
11
- /** IMPL START */
12
- var getInternalSlots = implDetails.getInternalSlots;
13
- var internalSlots = getInternalSlots(dtf);
14
- /** IMPL END */
15
- var pattern = internalSlots.pattern;
16
- return FormatDateTimePattern(dtf, PartitionPattern(pattern), x, implDetails);
17
- }
@@ -1,5 +0,0 @@
1
- import { IntlDateTimeFormatPart } from '@formatjs/ecma402-abstract';
2
- import Decimal from 'decimal.js';
3
- import { FormatDateTimePatternImplDetails } from './FormatDateTimePattern';
4
- import { ToLocalTimeImplDetails } from './ToLocalTime';
5
- export declare function PartitionDateTimeRangePattern(dtf: Intl.DateTimeFormat, x: Decimal, y: Decimal, implDetails: FormatDateTimePatternImplDetails & ToLocalTimeImplDetails): IntlDateTimeFormatPart[];
@@ -1,119 +0,0 @@
1
- import { PartitionPattern, RangePatternType, SameValue, TimeClip, } from '@formatjs/ecma402-abstract';
2
- import { FormatDateTimePattern, } from './FormatDateTimePattern';
3
- import { ToLocalTime } from './ToLocalTime';
4
- var TABLE_2_FIELDS = [
5
- 'era',
6
- 'year',
7
- 'month',
8
- 'day',
9
- 'dayPeriod',
10
- 'ampm',
11
- 'hour',
12
- 'minute',
13
- 'second',
14
- 'fractionalSecondDigits',
15
- ];
16
- export function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
17
- x = TimeClip(x);
18
- if (x.isNaN()) {
19
- throw new RangeError('Invalid start time');
20
- }
21
- y = TimeClip(y);
22
- if (y.isNaN()) {
23
- throw new RangeError('Invalid end time');
24
- }
25
- /** IMPL START */
26
- var getInternalSlots = implDetails.getInternalSlots, tzData = implDetails.tzData;
27
- var internalSlots = getInternalSlots(dtf);
28
- /** IMPL END */
29
- var tm1 = ToLocalTime(x,
30
- // @ts-ignore
31
- internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
32
- var tm2 = ToLocalTime(y,
33
- // @ts-ignore
34
- internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
35
- var pattern = internalSlots.pattern, rangePatterns = internalSlots.rangePatterns;
36
- var rangePattern;
37
- var dateFieldsPracticallyEqual = true;
38
- var patternContainsLargerDateField = false;
39
- for (var _i = 0, TABLE_2_FIELDS_1 = TABLE_2_FIELDS; _i < TABLE_2_FIELDS_1.length; _i++) {
40
- var fieldName = TABLE_2_FIELDS_1[_i];
41
- if (dateFieldsPracticallyEqual && !patternContainsLargerDateField) {
42
- var rp = fieldName in rangePatterns ? rangePatterns[fieldName] : undefined;
43
- if (rangePattern !== undefined && rp === undefined) {
44
- patternContainsLargerDateField = true;
45
- }
46
- else {
47
- rangePattern = rp;
48
- if (fieldName === 'ampm') {
49
- var v1 = tm1.hour;
50
- var v2 = tm2.hour;
51
- if ((v1 > 11 && v2 < 11) || (v1 < 11 && v2 > 11)) {
52
- dateFieldsPracticallyEqual = false;
53
- }
54
- }
55
- else if (fieldName === 'dayPeriod') {
56
- // TODO
57
- }
58
- else if (fieldName === 'fractionalSecondDigits') {
59
- var fractionalSecondDigits = internalSlots.fractionalSecondDigits;
60
- if (fractionalSecondDigits === undefined) {
61
- fractionalSecondDigits = 3;
62
- }
63
- var v1 = Math.floor(tm1.millisecond * Math.pow(10, (fractionalSecondDigits - 3)));
64
- var v2 = Math.floor(tm2.millisecond * Math.pow(10, (fractionalSecondDigits - 3)));
65
- if (!SameValue(v1, v2)) {
66
- dateFieldsPracticallyEqual = false;
67
- }
68
- }
69
- else {
70
- var v1 = tm1[fieldName];
71
- var v2 = tm2[fieldName];
72
- if (!SameValue(v1, v2)) {
73
- dateFieldsPracticallyEqual = false;
74
- }
75
- }
76
- }
77
- }
78
- }
79
- if (dateFieldsPracticallyEqual) {
80
- var result_2 = FormatDateTimePattern(dtf, PartitionPattern(pattern), x, implDetails);
81
- for (var _a = 0, result_1 = result_2; _a < result_1.length; _a++) {
82
- var r = result_1[_a];
83
- r.source = RangePatternType.shared;
84
- }
85
- return result_2;
86
- }
87
- var result = [];
88
- if (rangePattern === undefined) {
89
- rangePattern = rangePatterns.default;
90
- /** IMPL DETAILS */
91
- // Now we have to replace {0} & {1} with actual pattern
92
- for (var _b = 0, _c = rangePattern.patternParts; _b < _c.length; _b++) {
93
- var patternPart = _c[_b];
94
- if (patternPart.pattern === '{0}' || patternPart.pattern === '{1}') {
95
- patternPart.pattern = pattern;
96
- }
97
- }
98
- }
99
- for (var _d = 0, _e = rangePattern.patternParts; _d < _e.length; _d++) {
100
- var rangePatternPart = _e[_d];
101
- var source = rangePatternPart.source, pattern_1 = rangePatternPart.pattern;
102
- var z = void 0;
103
- if (source === RangePatternType.startRange ||
104
- source === RangePatternType.shared) {
105
- z = x;
106
- }
107
- else {
108
- z = y;
109
- }
110
- var patternParts = PartitionPattern(pattern_1);
111
- var partResult = FormatDateTimePattern(dtf, patternParts, z, implDetails);
112
- for (var _f = 0, partResult_1 = partResult; _f < partResult_1.length; _f++) {
113
- var r = partResult_1[_f];
114
- r.source = source;
115
- }
116
- result = result.concat(partResult);
117
- }
118
- return result;
119
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-todatetimeoptions
3
- * @param options
4
- * @param required
5
- * @param defaults
6
- */
7
- export declare function ToDateTimeOptions(options?: Intl.DateTimeFormatOptions | null, required?: string, defaults?: string): Intl.DateTimeFormatOptions;
@@ -1,63 +0,0 @@
1
- import { ToObject } from '@formatjs/ecma402-abstract';
2
- /**
3
- * https://tc39.es/ecma402/#sec-todatetimeoptions
4
- * @param options
5
- * @param required
6
- * @param defaults
7
- */
8
- export function ToDateTimeOptions(options, required, defaults) {
9
- if (options === undefined) {
10
- options = null;
11
- }
12
- else {
13
- options = ToObject(options);
14
- }
15
- options = Object.create(options);
16
- var needDefaults = true;
17
- if (required === 'date' || required === 'any') {
18
- for (var _i = 0, _a = ['weekday', 'year', 'month', 'day']; _i < _a.length; _i++) {
19
- var prop = _a[_i];
20
- var value = options[prop];
21
- if (value !== undefined) {
22
- needDefaults = false;
23
- }
24
- }
25
- }
26
- if (required === 'time' || required === 'any') {
27
- for (var _b = 0, _c = [
28
- 'dayPeriod',
29
- 'hour',
30
- 'minute',
31
- 'second',
32
- 'fractionalSecondDigits',
33
- ]; _b < _c.length; _b++) {
34
- var prop = _c[_b];
35
- var value = options[prop];
36
- if (value !== undefined) {
37
- needDefaults = false;
38
- }
39
- }
40
- }
41
- if (options.dateStyle !== undefined || options.timeStyle !== undefined) {
42
- needDefaults = false;
43
- }
44
- if (required === 'date' && options.timeStyle) {
45
- throw new TypeError('Intl.DateTimeFormat date was required but timeStyle was included');
46
- }
47
- if (required === 'time' && options.dateStyle) {
48
- throw new TypeError('Intl.DateTimeFormat time was required but dateStyle was included');
49
- }
50
- if (needDefaults && (defaults === 'date' || defaults === 'all')) {
51
- for (var _d = 0, _e = ['year', 'month', 'day']; _d < _e.length; _d++) {
52
- var prop = _e[_d];
53
- options[prop] = 'numeric';
54
- }
55
- }
56
- if (needDefaults && (defaults === 'time' || defaults === 'all')) {
57
- for (var _f = 0, _g = ['hour', 'minute', 'second']; _f < _g.length; _f++) {
58
- var prop = _g[_f];
59
- options[prop] = 'numeric';
60
- }
61
- }
62
- return options;
63
- }
@@ -1,26 +0,0 @@
1
- import { UnpackedZoneData } from '@formatjs/ecma402-abstract';
2
- import Decimal from 'decimal.js';
3
- export interface ToLocalTimeImplDetails {
4
- tzData: Record<string, UnpackedZoneData[]>;
5
- }
6
- /**
7
- * https://tc39.es/ecma402/#sec-tolocaltime
8
- * @param t
9
- * @param calendar
10
- * @param timeZone
11
- */
12
- export declare function ToLocalTime(t: Decimal, calendar: string, timeZone: string, { tzData }: ToLocalTimeImplDetails): {
13
- weekday: number;
14
- era: string;
15
- year: number;
16
- relatedYear: undefined;
17
- yearName: undefined;
18
- month: number;
19
- day: number;
20
- hour: number;
21
- minute: number;
22
- second: number;
23
- millisecond: number;
24
- inDST: boolean;
25
- timeZoneOffset: number;
26
- };
@@ -1,49 +0,0 @@
1
- import { DateFromTime, HourFromTime, MinFromTime, MonthFromTime, SecFromTime, WeekDay, YearFromTime, invariant, msFromTime, } from '@formatjs/ecma402-abstract';
2
- function getApplicableZoneData(t, timeZone, tzData) {
3
- var _a;
4
- var zoneData = tzData[timeZone];
5
- // We don't have data for this so just say it's UTC
6
- if (!zoneData) {
7
- return [0, false];
8
- }
9
- var i = 0;
10
- var offset = 0;
11
- var dst = false;
12
- for (; i <= zoneData.length; i++) {
13
- if (i === zoneData.length || zoneData[i][0] * 1e3 > t) {
14
- ;
15
- _a = zoneData[i - 1], offset = _a[2], dst = _a[3];
16
- break;
17
- }
18
- }
19
- return [offset * 1e3, dst];
20
- }
21
- /**
22
- * https://tc39.es/ecma402/#sec-tolocaltime
23
- * @param t
24
- * @param calendar
25
- * @param timeZone
26
- */
27
- export function ToLocalTime(t, calendar, timeZone, _a) {
28
- var tzData = _a.tzData;
29
- invariant(calendar === 'gregory', 'We only support Gregory calendar right now');
30
- var _b = getApplicableZoneData(t.toNumber(), timeZone, tzData), timeZoneOffset = _b[0], inDST = _b[1];
31
- var tz = t.plus(timeZoneOffset).toNumber();
32
- var year = YearFromTime(tz);
33
- return {
34
- weekday: WeekDay(tz),
35
- era: year < 0 ? 'BC' : 'AD',
36
- year: year,
37
- relatedYear: undefined,
38
- yearName: undefined,
39
- month: MonthFromTime(tz),
40
- day: DateFromTime(tz),
41
- hour: HourFromTime(tz),
42
- minute: MinFromTime(tz),
43
- second: SecFromTime(tz),
44
- millisecond: msFromTime(tz),
45
- inDST: inDST,
46
- // IMPORTANT: Not in spec
47
- timeZoneOffset: timeZoneOffset,
48
- };
49
- }
@@ -1,13 +0,0 @@
1
- import { Formats, RangePatternPart } from '@formatjs/ecma402-abstract';
2
- export declare function processDateTimePattern(pattern: string, result?: Pick<Intl.DateTimeFormatOptions, 'weekday' | 'era' | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'timeZoneName'> & {
3
- hour12?: boolean;
4
- }): [string, string];
5
- /**
6
- * Parse Date time skeleton into Intl.DateTimeFormatOptions
7
- * Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
8
- * @public
9
- * @param skeleton skeleton string
10
- */
11
- export declare function parseDateTimeSkeleton(skeleton: string, rawPattern?: string, rangePatterns?: Record<string, string>, intervalFormatFallback?: string): Formats;
12
- export declare function splitFallbackRangePattern(pattern: string): Array<RangePatternPart>;
13
- export declare function splitRangePattern(pattern: string): Array<RangePatternPart>;