@formatjs/intl-datetimeformat 6.11.3 → 6.12.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 (38) hide show
  1. package/LICENSE.md +1 -1
  2. package/lib/index.js +1 -4
  3. package/lib/polyfill-force.js +10 -12
  4. package/lib/polyfill.js +12 -14
  5. package/lib/should-polyfill.js +4 -8
  6. package/lib/src/abstract/BasicFormatMatcher.js +26 -30
  7. package/lib/src/abstract/BestFitFormatMatcher.js +19 -24
  8. package/lib/src/abstract/DateTimeStyleFormat.js +5 -9
  9. package/lib/src/abstract/FormatDateTime.js +3 -7
  10. package/lib/src/abstract/FormatDateTimePattern.js +7 -11
  11. package/lib/src/abstract/FormatDateTimeRange.js +3 -7
  12. package/lib/src/abstract/FormatDateTimeRangeToParts.js +3 -7
  13. package/lib/src/abstract/FormatDateTimeToParts.js +5 -9
  14. package/lib/src/abstract/InitializeDateTimeFormat.d.ts +1 -1
  15. package/lib/src/abstract/InitializeDateTimeFormat.js +43 -43
  16. package/lib/src/abstract/PartitionDateTimePattern.js +5 -9
  17. package/lib/src/abstract/PartitionDateTimeRangePattern.js +16 -20
  18. package/lib/src/abstract/ToDateTimeOptions.js +3 -7
  19. package/lib/src/abstract/ToLocalTime.js +12 -16
  20. package/lib/src/abstract/skeleton.js +15 -22
  21. package/lib/src/abstract/utils.js +9 -12
  22. package/lib/src/core.d.ts +1 -1
  23. package/lib/src/core.js +106 -109
  24. package/lib/src/data/all-tz.js +1 -3
  25. package/lib/src/data/links.js +1 -3
  26. package/lib/src/get_internal_slots.js +1 -4
  27. package/lib/src/packer.js +5 -10
  28. package/lib/src/to_locale_string.js +8 -14
  29. package/lib/src/types.js +1 -2
  30. package/lib/supported-locales.generated.js +1 -4
  31. package/lib/test262-main.js +3 -6
  32. package/package.json +4 -4
  33. package/polyfill.iife.js +6340 -9452
  34. package/src/abstract/InitializeDateTimeFormat.d.ts +1 -1
  35. package/src/abstract/InitializeDateTimeFormat.js +11 -7
  36. package/src/abstract/skeleton.js +1 -1
  37. package/src/core.d.ts +1 -1
  38. package/src/core.js +9 -9
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InitializeDateTimeFormat = void 0;
4
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
5
- var BasicFormatMatcher_1 = require("./BasicFormatMatcher");
6
- var BestFitFormatMatcher_1 = require("./BestFitFormatMatcher");
7
- var utils_1 = require("./utils");
8
- var DateTimeStyleFormat_1 = require("./DateTimeStyleFormat");
9
- var ToDateTimeOptions_1 = require("./ToDateTimeOptions");
10
- var intl_localematcher_1 = require("@formatjs/intl-localematcher");
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';
11
8
  function isTimeRelated(opt) {
12
9
  for (var _i = 0, _a = ['hour', 'minute', 'second']; _i < _a.length; _i++) {
13
10
  var prop = _a[_i];
@@ -32,7 +29,7 @@ function resolveHourCycle(hc, hcDefault, hour12) {
32
29
  }
33
30
  }
34
31
  else {
35
- (0, ecma402_abstract_1.invariant)(!hour12, 'hour12 must not be set');
32
+ invariant(!hour12, 'hour12 must not be set');
36
33
  if (hcDefault === 'h11' || hcDefault === 'h23') {
37
34
  hc = 'h23';
38
35
  }
@@ -50,33 +47,33 @@ var TYPE_REGEX = /^[a-z0-9]{3,8}$/i;
50
47
  * @param locales locales
51
48
  * @param opts options
52
49
  */
53
- function InitializeDateTimeFormat(dtf, locales, opts, _a) {
50
+ export function InitializeDateTimeFormat(dtf, locales, opts, _a) {
54
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;
55
52
  // @ts-ignore
56
- var requestedLocales = (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales);
57
- var options = (0, ToDateTimeOptions_1.ToDateTimeOptions)(opts, 'any', 'date');
53
+ var requestedLocales = CanonicalizeLocaleList(locales);
54
+ var options = ToDateTimeOptions(opts, 'any', 'date');
58
55
  var opt = Object.create(null);
59
- var matcher = (0, ecma402_abstract_1.GetOption)(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
56
+ var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
60
57
  opt.localeMatcher = matcher;
61
- var calendar = (0, ecma402_abstract_1.GetOption)(options, 'calendar', 'string', undefined, undefined);
58
+ var calendar = GetOption(options, 'calendar', 'string', undefined, undefined);
62
59
  if (calendar !== undefined && !TYPE_REGEX.test(calendar)) {
63
60
  throw new RangeError('Malformed calendar');
64
61
  }
65
62
  var internalSlots = getInternalSlots(dtf);
66
63
  opt.ca = calendar;
67
- var numberingSystem = (0, ecma402_abstract_1.GetOption)(options, 'numberingSystem', 'string', undefined, undefined);
64
+ var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
68
65
  if (numberingSystem !== undefined && !TYPE_REGEX.test(numberingSystem)) {
69
66
  throw new RangeError('Malformed numbering system');
70
67
  }
71
68
  opt.nu = numberingSystem;
72
- var hour12 = (0, ecma402_abstract_1.GetOption)(options, 'hour12', 'boolean', undefined, undefined);
73
- var hourCycle = (0, ecma402_abstract_1.GetOption)(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
69
+ var hour12 = GetOption(options, 'hour12', 'boolean', undefined, undefined);
70
+ var hourCycle = GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
74
71
  if (hour12 !== undefined) {
75
72
  // @ts-ignore
76
73
  hourCycle = null;
77
74
  }
78
75
  opt.hc = hourCycle;
79
- var r = (0, intl_localematcher_1.ResolveLocale)(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
76
+ var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
80
77
  internalSlots.locale = r.locale;
81
78
  calendar = r.ca;
82
79
  internalSlots.calendar = calendar;
@@ -87,25 +84,31 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
87
84
  var timeZone = options.timeZone;
88
85
  if (timeZone !== undefined) {
89
86
  timeZone = String(timeZone);
90
- if (!(0, ecma402_abstract_1.IsValidTimeZoneName)(timeZone, { tzData: tzData, uppercaseLinks: uppercaseLinks })) {
87
+ if (!IsValidTimeZoneName(timeZone, {
88
+ zoneNamesFromData: Object.keys(tzData),
89
+ uppercaseLinks: uppercaseLinks,
90
+ })) {
91
91
  throw new RangeError('Invalid timeZoneName');
92
92
  }
93
- timeZone = (0, ecma402_abstract_1.CanonicalizeTimeZoneName)(timeZone, { tzData: tzData, uppercaseLinks: uppercaseLinks });
93
+ timeZone = CanonicalizeTimeZoneName(timeZone, {
94
+ zoneNames: Object.keys(tzData),
95
+ uppercaseLinks: uppercaseLinks,
96
+ });
94
97
  }
95
98
  else {
96
99
  timeZone = getDefaultTimeZone();
97
100
  }
98
101
  internalSlots.timeZone = timeZone;
99
102
  opt = Object.create(null);
100
- opt.weekday = (0, ecma402_abstract_1.GetOption)(options, 'weekday', 'string', ['narrow', 'short', 'long'], undefined);
101
- opt.era = (0, ecma402_abstract_1.GetOption)(options, 'era', 'string', ['narrow', 'short', 'long'], undefined);
102
- opt.year = (0, ecma402_abstract_1.GetOption)(options, 'year', 'string', ['2-digit', 'numeric'], undefined);
103
- opt.month = (0, ecma402_abstract_1.GetOption)(options, 'month', 'string', ['2-digit', 'numeric', 'narrow', 'short', 'long'], undefined);
104
- opt.day = (0, ecma402_abstract_1.GetOption)(options, 'day', 'string', ['2-digit', 'numeric'], undefined);
105
- opt.hour = (0, ecma402_abstract_1.GetOption)(options, 'hour', 'string', ['2-digit', 'numeric'], undefined);
106
- opt.minute = (0, ecma402_abstract_1.GetOption)(options, 'minute', 'string', ['2-digit', 'numeric'], undefined);
107
- opt.second = (0, ecma402_abstract_1.GetOption)(options, 'second', 'string', ['2-digit', 'numeric'], undefined);
108
- opt.timeZoneName = (0, ecma402_abstract_1.GetOption)(options, 'timeZoneName', 'string', [
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', [
109
112
  'long',
110
113
  'short',
111
114
  'longOffset',
@@ -113,25 +116,23 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
113
116
  'longGeneric',
114
117
  'shortGeneric',
115
118
  ], undefined);
116
- opt.fractionalSecondDigits = (0, ecma402_abstract_1.GetNumberOption)(options, 'fractionalSecondDigits', 1, 3,
117
- // @ts-expect-error
118
- undefined);
119
+ opt.fractionalSecondDigits = GetNumberOption(options, 'fractionalSecondDigits', 1, 3, undefined);
119
120
  var dataLocaleData = localeData[dataLocale];
120
- (0, ecma402_abstract_1.invariant)(!!dataLocaleData, "Missing locale data for ".concat(dataLocale));
121
+ invariant(!!dataLocaleData, "Missing locale data for ".concat(dataLocale));
121
122
  var formats = dataLocaleData.formats[calendar];
122
123
  // UNSPECCED: IMPLEMENTATION DETAILS
123
124
  if (!formats) {
124
125
  throw new RangeError("Calendar \"".concat(calendar, "\" is not supported. Try setting \"calendar\" to 1 of the following: ").concat(Object.keys(dataLocaleData.formats).join(', ')));
125
126
  }
126
- var formatMatcher = (0, ecma402_abstract_1.GetOption)(options, 'formatMatcher', 'string', ['basic', 'best fit'], 'best fit');
127
- var dateStyle = (0, ecma402_abstract_1.GetOption)(options, 'dateStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
127
+ var formatMatcher = GetOption(options, 'formatMatcher', 'string', ['basic', 'best fit'], 'best fit');
128
+ var dateStyle = GetOption(options, 'dateStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
128
129
  internalSlots.dateStyle = dateStyle;
129
- var timeStyle = (0, ecma402_abstract_1.GetOption)(options, 'timeStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
130
+ var timeStyle = GetOption(options, 'timeStyle', 'string', ['full', 'long', 'medium', 'short'], undefined);
130
131
  internalSlots.timeStyle = timeStyle;
131
132
  var bestFormat;
132
133
  if (dateStyle === undefined && timeStyle === undefined) {
133
134
  if (formatMatcher === 'basic') {
134
- bestFormat = (0, BasicFormatMatcher_1.BasicFormatMatcher)(opt, formats);
135
+ bestFormat = BasicFormatMatcher(opt, formats);
135
136
  }
136
137
  else {
137
138
  // IMPL DETAILS START
@@ -140,18 +141,18 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
140
141
  opt.hour12 = hc === 'h11' || hc === 'h12';
141
142
  }
142
143
  // IMPL DETAILS END
143
- bestFormat = (0, BestFitFormatMatcher_1.BestFitFormatMatcher)(opt, formats);
144
+ bestFormat = BestFitFormatMatcher(opt, formats);
144
145
  }
145
146
  }
146
147
  else {
147
- for (var _i = 0, DATE_TIME_PROPS_1 = utils_1.DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
148
+ for (var _i = 0, DATE_TIME_PROPS_1 = DATE_TIME_PROPS; _i < DATE_TIME_PROPS_1.length; _i++) {
148
149
  var prop = DATE_TIME_PROPS_1[_i];
149
150
  var p = opt[prop];
150
151
  if (p !== undefined) {
151
152
  throw new TypeError("Intl.DateTimeFormat can't set option ".concat(prop, " when ").concat(dateStyle ? 'dateStyle' : 'timeStyle', " is used"));
152
153
  }
153
154
  }
154
- bestFormat = (0, DateTimeStyleFormat_1.DateTimeStyleFormat)(dateStyle, timeStyle, dataLocaleData);
155
+ bestFormat = DateTimeStyleFormat(dateStyle, timeStyle, dataLocaleData);
155
156
  }
156
157
  // IMPL DETAIL START
157
158
  // For debugging
@@ -187,4 +188,3 @@ function InitializeDateTimeFormat(dtf, locales, opts, _a) {
187
188
  internalSlots.rangePatterns = rangePatterns;
188
189
  return dtf; // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged
189
190
  }
190
- exports.InitializeDateTimeFormat = InitializeDateTimeFormat;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartitionDateTimePattern = void 0;
4
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
5
- var FormatDateTimePattern_1 = require("./FormatDateTimePattern");
1
+ import { PartitionPattern, TimeClip, } from '@formatjs/ecma402-abstract';
2
+ import { FormatDateTimePattern, } from './FormatDateTimePattern';
6
3
  /**
7
4
  * https://tc39.es/ecma402/#sec-partitiondatetimepattern
8
5
  * @param dtf
9
6
  * @param x
10
7
  */
11
- function PartitionDateTimePattern(dtf, x, implDetails) {
12
- x = (0, ecma402_abstract_1.TimeClip)(x);
8
+ export function PartitionDateTimePattern(dtf, x, implDetails) {
9
+ x = TimeClip(x);
13
10
  if (isNaN(x)) {
14
11
  throw new RangeError('invalid time');
15
12
  }
@@ -18,6 +15,5 @@ function PartitionDateTimePattern(dtf, x, implDetails) {
18
15
  var internalSlots = getInternalSlots(dtf);
19
16
  /** IMPL END */
20
17
  var pattern = internalSlots.pattern;
21
- return (0, FormatDateTimePattern_1.FormatDateTimePattern)(dtf, (0, ecma402_abstract_1.PartitionPattern)(pattern), x, implDetails);
18
+ return FormatDateTimePattern(dtf, PartitionPattern(pattern), x, implDetails);
22
19
  }
23
- exports.PartitionDateTimePattern = PartitionDateTimePattern;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartitionDateTimeRangePattern = void 0;
4
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
5
- var ToLocalTime_1 = require("./ToLocalTime");
6
- var FormatDateTimePattern_1 = require("./FormatDateTimePattern");
1
+ import { RangePatternType, PartitionPattern, SameValue, TimeClip, } from '@formatjs/ecma402-abstract';
2
+ import { ToLocalTime } from './ToLocalTime';
3
+ import { FormatDateTimePattern, } from './FormatDateTimePattern';
7
4
  var TABLE_2_FIELDS = [
8
5
  'era',
9
6
  'year',
@@ -16,12 +13,12 @@ var TABLE_2_FIELDS = [
16
13
  'second',
17
14
  'fractionalSecondDigits',
18
15
  ];
19
- function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
20
- x = (0, ecma402_abstract_1.TimeClip)(x);
16
+ export function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
17
+ x = TimeClip(x);
21
18
  if (isNaN(x)) {
22
19
  throw new RangeError('Invalid start time');
23
20
  }
24
- y = (0, ecma402_abstract_1.TimeClip)(y);
21
+ y = TimeClip(y);
25
22
  if (isNaN(y)) {
26
23
  throw new RangeError('Invalid end time');
27
24
  }
@@ -29,10 +26,10 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
29
26
  var getInternalSlots = implDetails.getInternalSlots, tzData = implDetails.tzData;
30
27
  var internalSlots = getInternalSlots(dtf);
31
28
  /** IMPL END */
32
- var tm1 = (0, ToLocalTime_1.ToLocalTime)(x,
29
+ var tm1 = ToLocalTime(x,
33
30
  // @ts-ignore
34
31
  internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
35
- var tm2 = (0, ToLocalTime_1.ToLocalTime)(y,
32
+ var tm2 = ToLocalTime(y,
36
33
  // @ts-ignore
37
34
  internalSlots.calendar, internalSlots.timeZone, { tzData: tzData });
38
35
  var pattern = internalSlots.pattern, rangePatterns = internalSlots.rangePatterns;
@@ -65,14 +62,14 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
65
62
  }
66
63
  var v1 = Math.floor(tm1.millisecond * Math.pow(10, (fractionalSecondDigits - 3)));
67
64
  var v2 = Math.floor(tm2.millisecond * Math.pow(10, (fractionalSecondDigits - 3)));
68
- if (!(0, ecma402_abstract_1.SameValue)(v1, v2)) {
65
+ if (!SameValue(v1, v2)) {
69
66
  dateFieldsPracticallyEqual = false;
70
67
  }
71
68
  }
72
69
  else {
73
70
  var v1 = tm1[fieldName];
74
71
  var v2 = tm2[fieldName];
75
- if (!(0, ecma402_abstract_1.SameValue)(v1, v2)) {
72
+ if (!SameValue(v1, v2)) {
76
73
  dateFieldsPracticallyEqual = false;
77
74
  }
78
75
  }
@@ -80,10 +77,10 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
80
77
  }
81
78
  }
82
79
  if (dateFieldsPracticallyEqual) {
83
- var result_2 = (0, FormatDateTimePattern_1.FormatDateTimePattern)(dtf, (0, ecma402_abstract_1.PartitionPattern)(pattern), x, implDetails);
80
+ var result_2 = FormatDateTimePattern(dtf, PartitionPattern(pattern), x, implDetails);
84
81
  for (var _a = 0, result_1 = result_2; _a < result_1.length; _a++) {
85
82
  var r = result_1[_a];
86
- r.source = ecma402_abstract_1.RangePatternType.shared;
83
+ r.source = RangePatternType.shared;
87
84
  }
88
85
  return result_2;
89
86
  }
@@ -103,15 +100,15 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
103
100
  var rangePatternPart = _e[_d];
104
101
  var source = rangePatternPart.source, pattern_1 = rangePatternPart.pattern;
105
102
  var z = void 0;
106
- if (source === ecma402_abstract_1.RangePatternType.startRange ||
107
- source === ecma402_abstract_1.RangePatternType.shared) {
103
+ if (source === RangePatternType.startRange ||
104
+ source === RangePatternType.shared) {
108
105
  z = x;
109
106
  }
110
107
  else {
111
108
  z = y;
112
109
  }
113
- var patternParts = (0, ecma402_abstract_1.PartitionPattern)(pattern_1);
114
- var partResult = (0, FormatDateTimePattern_1.FormatDateTimePattern)(dtf, patternParts, z, implDetails);
110
+ var patternParts = PartitionPattern(pattern_1);
111
+ var partResult = FormatDateTimePattern(dtf, patternParts, z, implDetails);
115
112
  for (var _f = 0, partResult_1 = partResult; _f < partResult_1.length; _f++) {
116
113
  var r = partResult_1[_f];
117
114
  r.source = source;
@@ -120,4 +117,3 @@ function PartitionDateTimeRangePattern(dtf, x, y, implDetails) {
120
117
  }
121
118
  return result;
122
119
  }
123
- exports.PartitionDateTimeRangePattern = PartitionDateTimeRangePattern;
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToDateTimeOptions = void 0;
4
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
1
+ import { ToObject } from '@formatjs/ecma402-abstract';
5
2
  /**
6
3
  * https://tc39.es/ecma402/#sec-todatetimeoptions
7
4
  * @param options
8
5
  * @param required
9
6
  * @param defaults
10
7
  */
11
- function ToDateTimeOptions(options, required, defaults) {
8
+ export function ToDateTimeOptions(options, required, defaults) {
12
9
  if (options === undefined) {
13
10
  options = null;
14
11
  }
15
12
  else {
16
- options = (0, ecma402_abstract_1.ToObject)(options);
13
+ options = ToObject(options);
17
14
  }
18
15
  options = Object.create(options);
19
16
  var needDefaults = true;
@@ -64,4 +61,3 @@ function ToDateTimeOptions(options, required, defaults) {
64
61
  }
65
62
  return options;
66
63
  }
67
- exports.ToDateTimeOptions = ToDateTimeOptions;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToLocalTime = void 0;
4
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
1
+ import { Type, YearFromTime, WeekDay, MonthFromTime, DateFromTime, HourFromTime, MinFromTime, SecFromTime, msFromTime, invariant, } from '@formatjs/ecma402-abstract';
5
2
  function getApplicableZoneData(t, timeZone, tzData) {
6
3
  var _a;
7
4
  var zoneData = tzData[timeZone];
@@ -27,28 +24,27 @@ function getApplicableZoneData(t, timeZone, tzData) {
27
24
  * @param calendar
28
25
  * @param timeZone
29
26
  */
30
- function ToLocalTime(t, calendar, timeZone, _a) {
27
+ export function ToLocalTime(t, calendar, timeZone, _a) {
31
28
  var tzData = _a.tzData;
32
- (0, ecma402_abstract_1.invariant)((0, ecma402_abstract_1.Type)(t) === 'Number', 'invalid time');
33
- (0, ecma402_abstract_1.invariant)(calendar === 'gregory', 'We only support Gregory calendar right now');
29
+ invariant(Type(t) === 'Number', 'invalid time');
30
+ invariant(calendar === 'gregory', 'We only support Gregory calendar right now');
34
31
  var _b = getApplicableZoneData(t, timeZone, tzData), timeZoneOffset = _b[0], inDST = _b[1];
35
32
  var tz = t + timeZoneOffset;
36
- var year = (0, ecma402_abstract_1.YearFromTime)(tz);
33
+ var year = YearFromTime(tz);
37
34
  return {
38
- weekday: (0, ecma402_abstract_1.WeekDay)(tz),
35
+ weekday: WeekDay(tz),
39
36
  era: year < 0 ? 'BC' : 'AD',
40
37
  year: year,
41
38
  relatedYear: undefined,
42
39
  yearName: undefined,
43
- month: (0, ecma402_abstract_1.MonthFromTime)(tz),
44
- day: (0, ecma402_abstract_1.DateFromTime)(tz),
45
- hour: (0, ecma402_abstract_1.HourFromTime)(tz),
46
- minute: (0, ecma402_abstract_1.MinFromTime)(tz),
47
- second: (0, ecma402_abstract_1.SecFromTime)(tz),
48
- millisecond: (0, ecma402_abstract_1.msFromTime)(tz),
40
+ month: MonthFromTime(tz),
41
+ day: DateFromTime(tz),
42
+ hour: HourFromTime(tz),
43
+ minute: MinFromTime(tz),
44
+ second: SecFromTime(tz),
45
+ millisecond: msFromTime(tz),
49
46
  inDST: inDST,
50
47
  // IMPORTANT: Not in spec
51
48
  timeZoneOffset: timeZoneOffset,
52
49
  };
53
50
  }
54
- exports.ToLocalTime = ToLocalTime;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitRangePattern = exports.splitFallbackRangePattern = exports.parseDateTimeSkeleton = exports.processDateTimePattern = void 0;
4
- var tslib_1 = require("tslib");
5
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
1
+ import { __assign } from "tslib";
2
+ import { RangePatternType, } from '@formatjs/ecma402-abstract';
6
3
  /**
7
4
  * https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
8
5
  * Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
@@ -111,7 +108,7 @@ function matchSkeletonPattern(match, result) {
111
108
  // Zone
112
109
  case 'z': // 1..3, 4: specific non-location format
113
110
  case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
114
- case 'O': // 1, 4: miliseconds in day short, long
111
+ case 'O': // 1, 4: milliseconds in day short, long
115
112
  case 'v': // 1, 4: generic non-location format
116
113
  case 'V': // 1, 2, 3, 4: time zone ID or city
117
114
  case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
@@ -166,7 +163,7 @@ function skeletonTokenToTable2(c) {
166
163
  throw new RangeError('Invalid range pattern token');
167
164
  }
168
165
  }
169
- function processDateTimePattern(pattern, result) {
166
+ export function processDateTimePattern(pattern, result) {
170
167
  var literals = [];
171
168
  // Use skeleton to populate result, but use mapped pattern to populate pattern
172
169
  var pattern12 = pattern
@@ -195,14 +192,13 @@ function processDateTimePattern(pattern, result) {
195
192
  pattern12,
196
193
  ];
197
194
  }
198
- exports.processDateTimePattern = processDateTimePattern;
199
195
  /**
200
196
  * Parse Date time skeleton into Intl.DateTimeFormatOptions
201
197
  * Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
202
198
  * @public
203
199
  * @param skeleton skeleton string
204
200
  */
205
- function parseDateTimeSkeleton(skeleton, rawPattern, rangePatterns, intervalFormatFallback) {
201
+ export function parseDateTimeSkeleton(skeleton, rawPattern, rangePatterns, intervalFormatFallback) {
206
202
  if (rawPattern === void 0) { rawPattern = skeleton; }
207
203
  var result = {
208
204
  pattern: '',
@@ -220,8 +216,8 @@ function parseDateTimeSkeleton(skeleton, rawPattern, rangePatterns, intervalForm
220
216
  patternParts: [],
221
217
  };
222
218
  var _a = processDateTimePattern(rawPattern_1, intervalResult), pattern_1 = _a[0], pattern12_1 = _a[1];
223
- result.rangePatterns[key] = tslib_1.__assign(tslib_1.__assign({}, intervalResult), { patternParts: splitRangePattern(pattern_1) });
224
- result.rangePatterns12[key] = tslib_1.__assign(tslib_1.__assign({}, intervalResult), { patternParts: splitRangePattern(pattern12_1) });
219
+ result.rangePatterns[key] = __assign(__assign({}, intervalResult), { patternParts: splitRangePattern(pattern_1) });
220
+ result.rangePatterns12[key] = __assign(__assign({}, intervalResult), { patternParts: splitRangePattern(pattern12_1) });
225
221
  }
226
222
  }
227
223
  if (intervalFormatFallback) {
@@ -240,31 +236,29 @@ function parseDateTimeSkeleton(skeleton, rawPattern, rangePatterns, intervalForm
240
236
  result.pattern12 = pattern12;
241
237
  return result;
242
238
  }
243
- exports.parseDateTimeSkeleton = parseDateTimeSkeleton;
244
- function splitFallbackRangePattern(pattern) {
239
+ export function splitFallbackRangePattern(pattern) {
245
240
  var parts = pattern.split(/(\{[0|1]\})/g).filter(Boolean);
246
241
  return parts.map(function (pattern) {
247
242
  switch (pattern) {
248
243
  case '{0}':
249
244
  return {
250
- source: ecma402_abstract_1.RangePatternType.startRange,
245
+ source: RangePatternType.startRange,
251
246
  pattern: pattern,
252
247
  };
253
248
  case '{1}':
254
249
  return {
255
- source: ecma402_abstract_1.RangePatternType.endRange,
250
+ source: RangePatternType.endRange,
256
251
  pattern: pattern,
257
252
  };
258
253
  default:
259
254
  return {
260
- source: ecma402_abstract_1.RangePatternType.shared,
255
+ source: RangePatternType.shared,
261
256
  pattern: pattern,
262
257
  };
263
258
  }
264
259
  });
265
260
  }
266
- exports.splitFallbackRangePattern = splitFallbackRangePattern;
267
- function splitRangePattern(pattern) {
261
+ export function splitRangePattern(pattern) {
268
262
  var PART_REGEX = /\{(.*?)\}/g;
269
263
  // Map of part and index within the string
270
264
  var parts = {};
@@ -282,20 +276,19 @@ function splitRangePattern(pattern) {
282
276
  if (!splitIndex) {
283
277
  return [
284
278
  {
285
- source: ecma402_abstract_1.RangePatternType.startRange,
279
+ source: RangePatternType.startRange,
286
280
  pattern: pattern,
287
281
  },
288
282
  ];
289
283
  }
290
284
  return [
291
285
  {
292
- source: ecma402_abstract_1.RangePatternType.startRange,
286
+ source: RangePatternType.startRange,
293
287
  pattern: pattern.slice(0, splitIndex),
294
288
  },
295
289
  {
296
- source: ecma402_abstract_1.RangePatternType.endRange,
290
+ source: RangePatternType.endRange,
297
291
  pattern: pattern.slice(splitIndex),
298
292
  },
299
293
  ];
300
294
  }
301
- exports.splitRangePattern = splitRangePattern;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.offsetPenalty = exports.shortMorePenalty = exports.shortLessPenalty = exports.longMorePenalty = exports.longLessPenalty = exports.differentNumericTypePenalty = exports.additionPenalty = exports.removalPenalty = exports.DATE_TIME_PROPS = void 0;
4
- exports.DATE_TIME_PROPS = [
1
+ export var DATE_TIME_PROPS = [
5
2
  'weekday',
6
3
  'era',
7
4
  'year',
@@ -14,11 +11,11 @@ exports.DATE_TIME_PROPS = [
14
11
  'fractionalSecondDigits',
15
12
  'timeZoneName',
16
13
  ];
17
- exports.removalPenalty = 120;
18
- exports.additionPenalty = 20;
19
- exports.differentNumericTypePenalty = 15;
20
- exports.longLessPenalty = 8;
21
- exports.longMorePenalty = 6;
22
- exports.shortLessPenalty = 6;
23
- exports.shortMorePenalty = 3;
24
- exports.offsetPenalty = 1;
14
+ export var removalPenalty = 120;
15
+ export var additionPenalty = 20;
16
+ export var differentNumericTypePenalty = 15;
17
+ export var longLessPenalty = 8;
18
+ export var longMorePenalty = 6;
19
+ export var shortLessPenalty = 6;
20
+ export var shortMorePenalty = 3;
21
+ export var offsetPenalty = 1;
package/lib/src/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DateTimeFormat as IDateTimeFormat, DateTimeFormatLocaleInternalData, UnpackedZoneData } from '@formatjs/ecma402-abstract';
1
+ import { DateTimeFormatLocaleInternalData, DateTimeFormat as IDateTimeFormat, UnpackedZoneData } from '@formatjs/ecma402-abstract';
2
2
  import { PackedData, RawDateTimeLocaleData } from './types';
3
3
  export interface DateTimeFormatConstructor {
4
4
  new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): IDateTimeFormat;