@formatjs/intl-datetimeformat 7.1.1 → 7.1.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 (54) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/package.json +5 -5
  4. package/polyfill-force.js +28 -44
  5. package/polyfill.iife.js +2301 -3064
  6. package/polyfill.js +29 -45
  7. package/should-polyfill.js +38 -50
  8. package/src/abstract/BasicFormatMatcher.d.ts +5 -5
  9. package/src/abstract/BasicFormatMatcher.js +87 -103
  10. package/src/abstract/BestFitFormatMatcher.d.ts +12 -12
  11. package/src/abstract/BestFitFormatMatcher.js +102 -108
  12. package/src/abstract/DateTimeStyleFormat.d.ts +2 -2
  13. package/src/abstract/DateTimeStyleFormat.js +47 -62
  14. package/src/abstract/FormatDateTime.d.ts +7 -7
  15. package/src/abstract/FormatDateTime.js +12 -12
  16. package/src/abstract/FormatDateTimePattern.d.ts +11 -11
  17. package/src/abstract/FormatDateTimePattern.js +185 -209
  18. package/src/abstract/FormatDateTimeRange.d.ts +3 -3
  19. package/src/abstract/FormatDateTimeRange.js +9 -8
  20. package/src/abstract/FormatDateTimeRangeToParts.d.ts +4 -4
  21. package/src/abstract/FormatDateTimeRangeToParts.js +14 -12
  22. package/src/abstract/FormatDateTimeToParts.d.ts +9 -9
  23. package/src/abstract/FormatDateTimeToParts.js +17 -18
  24. package/src/abstract/InitializeDateTimeFormat.d.ts +15 -15
  25. package/src/abstract/InitializeDateTimeFormat.js +206 -184
  26. package/src/abstract/PartitionDateTimePattern.d.ts +8 -8
  27. package/src/abstract/PartitionDateTimePattern.js +15 -14
  28. package/src/abstract/PartitionDateTimeRangePattern.d.ts +4 -4
  29. package/src/abstract/PartitionDateTimeRangePattern.js +168 -161
  30. package/src/abstract/ToDateTimeOptions.d.ts +5 -5
  31. package/src/abstract/ToDateTimeOptions.js +68 -60
  32. package/src/abstract/ToLocalTime.d.ts +21 -21
  33. package/src/abstract/ToLocalTime.js +108 -111
  34. package/src/abstract/skeleton.d.ts +8 -8
  35. package/src/abstract/skeleton.js +231 -280
  36. package/src/abstract/utils.d.ts +1 -1
  37. package/src/abstract/utils.js +21 -20
  38. package/src/core.d.ts +17 -17
  39. package/src/core.js +250 -286
  40. package/src/data/all-tz.generated.d.ts +5 -3
  41. package/src/data/all-tz.generated.js +458 -458
  42. package/src/data/links.generated.d.ts +258 -256
  43. package/src/data/links.generated.js +256 -256
  44. package/src/get_internal_slots.d.ts +3 -1
  45. package/src/get_internal_slots.js +8 -7
  46. package/src/packer.d.ts +2 -2
  47. package/src/packer.js +23 -35
  48. package/src/to_locale_string.d.ts +3 -3
  49. package/src/to_locale_string.js +11 -11
  50. package/src/types.d.ts +34 -39
  51. package/src/types.js +1 -1
  52. package/supported-locales.generated.js +572 -572
  53. package/test262-main.d.ts +4 -1
  54. package/test262-main.js +24600 -33141
@@ -1,123 +1,120 @@
1
- import { DateFromTime, HourFromTime, MinFromTime, MonthFromTime, SecFromTime, WeekDay, YearFromTime, invariant, msFromTime, } from '@formatjs/ecma402-abstract';
1
+ import { DateFromTime, HourFromTime, MinFromTime, MonthFromTime, SecFromTime, WeekDay, YearFromTime, invariant, msFromTime } from "@formatjs/ecma402-abstract";
2
2
  // Cached regex patterns for performance
3
- var OFFSET_TIMEZONE_PREFIX_REGEX = /^[+-]/;
4
- var OFFSET_TIMEZONE_FORMAT_REGEX = /^([+-])(\d{2})(?::?(\d{2}))?(?::?(\d{2}))?(?:\.(\d{1,9}))?$/;
3
+ const OFFSET_TIMEZONE_PREFIX_REGEX = /^[+-]/;
4
+ const OFFSET_TIMEZONE_FORMAT_REGEX = /^([+-])(\d{2})(?::?(\d{2}))?(?::?(\d{2}))?(?:\.(\d{1,9}))?$/;
5
5
  /**
6
- * IsTimeZoneOffsetString ( offsetString )
7
- * https://tc39.es/ecma262/#sec-istimezoneoffsetstring
8
- *
9
- * Determines if a string is a UTC offset identifier.
10
- *
11
- * @param offsetString - The string to check
12
- * @returns true if offsetString is a UTC offset format
13
- */
6
+ * IsTimeZoneOffsetString ( offsetString )
7
+ * https://tc39.es/ecma262/#sec-istimezoneoffsetstring
8
+ *
9
+ * Determines if a string is a UTC offset identifier.
10
+ *
11
+ * @param offsetString - The string to check
12
+ * @returns true if offsetString is a UTC offset format
13
+ */
14
14
  function IsTimeZoneOffsetString(offsetString) {
15
- return OFFSET_TIMEZONE_PREFIX_REGEX.test(offsetString);
15
+ return OFFSET_TIMEZONE_PREFIX_REGEX.test(offsetString);
16
16
  }
17
17
  /**
18
- * ParseTimeZoneOffsetString ( offsetString )
19
- * https://tc39.es/ecma262/#sec-parsetimezoneoffsetstring
20
- *
21
- * Parses a UTC offset string and returns the offset in milliseconds.
22
- * This is used to calculate the timezone offset for ToLocalTime.
23
- *
24
- * Supports formats: ±HH, ±HHMM, ±HH:MM, ±HH:MM:SS, ±HH:MM:SS.sss
25
- *
26
- * @param offsetString - The UTC offset string to parse (e.g., "+01:00")
27
- * @returns The offset in milliseconds
28
- */
18
+ * ParseTimeZoneOffsetString ( offsetString )
19
+ * https://tc39.es/ecma262/#sec-parsetimezoneoffsetstring
20
+ *
21
+ * Parses a UTC offset string and returns the offset in milliseconds.
22
+ * This is used to calculate the timezone offset for ToLocalTime.
23
+ *
24
+ * Supports formats: ±HH, ±HHMM, ±HH:MM, ±HH:MM:SS, ±HH:MM:SS.sss
25
+ *
26
+ * @param offsetString - The UTC offset string to parse (e.g., "+01:00")
27
+ * @returns The offset in milliseconds
28
+ */
29
29
  function ParseTimeZoneOffsetString(offsetString) {
30
- // 1. Let parseResult be ParseText(offsetString, UTCOffset)
31
- var match = OFFSET_TIMEZONE_FORMAT_REGEX.exec(offsetString);
32
- // 2. Assert: parseResult is not a List of errors
33
- if (!match) {
34
- return 0;
35
- }
36
- // 3. Extract components from parseResult
37
- var sign = match[1] === '+' ? 1 : -1;
38
- var hours = parseInt(match[2], 10);
39
- var minutes = match[3] ? parseInt(match[3], 10) : 0;
40
- var seconds = match[4] ? parseInt(match[4], 10) : 0;
41
- var fractionalStr = match[5] || '0';
42
- // 4. Convert fractional seconds (nanoseconds) to milliseconds
43
- // Pad to 9 digits and divide by 1000000
44
- // Use manual padding for compatibility (padEnd is ES2017)
45
- var paddedFractional = (fractionalStr + '000000000').slice(0, 9);
46
- var fractional = parseInt(paddedFractional, 10) / 1000000;
47
- // 5. Calculate total offset in milliseconds
48
- // offset = sign × (hours × 3600000 + minutes × 60000 + seconds × 1000 + fractional)
49
- var offsetMs = sign * (hours * 3600000 + minutes * 60000 + seconds * 1000 + fractional);
50
- // 6. Return offset in milliseconds
51
- return offsetMs;
30
+ // 1. Let parseResult be ParseText(offsetString, UTCOffset)
31
+ const match = OFFSET_TIMEZONE_FORMAT_REGEX.exec(offsetString);
32
+ // 2. Assert: parseResult is not a List of errors
33
+ if (!match) {
34
+ return 0;
35
+ }
36
+ // 3. Extract components from parseResult
37
+ const sign = match[1] === "+" ? 1 : -1;
38
+ const hours = parseInt(match[2], 10);
39
+ const minutes = match[3] ? parseInt(match[3], 10) : 0;
40
+ const seconds = match[4] ? parseInt(match[4], 10) : 0;
41
+ const fractionalStr = match[5] || "0";
42
+ // 4. Convert fractional seconds (nanoseconds) to milliseconds
43
+ // Pad to 9 digits and divide by 1000000
44
+ // Use manual padding for compatibility (padEnd is ES2017)
45
+ const paddedFractional = (fractionalStr + "000000000").slice(0, 9);
46
+ const fractional = parseInt(paddedFractional, 10) / 1e6;
47
+ // 5. Calculate total offset in milliseconds
48
+ // offset = sign × (hours × 3600000 + minutes × 60000 + seconds × 1000 + fractional)
49
+ const offsetMs = sign * (hours * 36e5 + minutes * 6e4 + seconds * 1e3 + fractional);
50
+ // 6. Return offset in milliseconds
51
+ return offsetMs;
52
52
  }
53
53
  /**
54
- * GetNamedTimeZoneOffsetNanoseconds ( timeZone, t )
55
- * Similar to abstract operation in ECMA-262, adapted for IANA timezone data.
56
- * Extended to support UTC offset time zones per ECMA-402 PR #788.
57
- *
58
- * Returns the timezone offset in milliseconds (not nanoseconds for this impl)
59
- * and DST flag for the given timezone at time t.
60
- *
61
- * @param t - Time value in milliseconds since epoch
62
- * @param timeZone - The timezone identifier
63
- * @param tzData - IANA timezone database
64
- * @returns Tuple of [offset in milliseconds, inDST boolean]
65
- */
54
+ * GetNamedTimeZoneOffsetNanoseconds ( timeZone, t )
55
+ * Similar to abstract operation in ECMA-262, adapted for IANA timezone data.
56
+ * Extended to support UTC offset time zones per ECMA-402 PR #788.
57
+ *
58
+ * Returns the timezone offset in milliseconds (not nanoseconds for this impl)
59
+ * and DST flag for the given timezone at time t.
60
+ *
61
+ * @param t - Time value in milliseconds since epoch
62
+ * @param timeZone - The timezone identifier
63
+ * @param tzData - IANA timezone database
64
+ * @returns Tuple of [offset in milliseconds, inDST boolean]
65
+ */
66
66
  function getApplicableZoneData(t, timeZone, tzData) {
67
- var _a;
68
- // 1. If IsTimeZoneOffsetString(timeZone) is true, then
69
- // a. Let offsetNs be ParseTimeZoneOffsetString(timeZone)
70
- // b. Return offsetNs (no DST for offset timezones)
71
- if (IsTimeZoneOffsetString(timeZone)) {
72
- var offsetMs = ParseTimeZoneOffsetString(timeZone);
73
- return [offsetMs, false]; // UTC offset timezones never observe DST
74
- }
75
- // 2. Let timeZoneData be the IANA Time Zone Database entry for timeZone
76
- var zoneData = tzData[timeZone];
77
- // 3. If no data available, treat as UTC (0 offset, no DST)
78
- if (!zoneData) {
79
- return [0, false];
80
- }
81
- // 4. Find the applicable transition for time t
82
- var i = 0;
83
- var offset = 0;
84
- var dst = false;
85
- for (; i <= zoneData.length; i++) {
86
- if (i === zoneData.length || zoneData[i][0] * 1e3 > t) {
87
- ;
88
- _a = zoneData[i - 1], offset = _a[2], dst = _a[3];
89
- break;
90
- }
91
- }
92
- // 5. Return offset in milliseconds and DST flag
93
- return [offset * 1e3, dst];
67
+ // 1. If IsTimeZoneOffsetString(timeZone) is true, then
68
+ // a. Let offsetNs be ParseTimeZoneOffsetString(timeZone)
69
+ // b. Return offsetNs (no DST for offset timezones)
70
+ if (IsTimeZoneOffsetString(timeZone)) {
71
+ const offsetMs = ParseTimeZoneOffsetString(timeZone);
72
+ return [offsetMs, false];
73
+ }
74
+ // 2. Let timeZoneData be the IANA Time Zone Database entry for timeZone
75
+ const zoneData = tzData[timeZone];
76
+ // 3. If no data available, treat as UTC (0 offset, no DST)
77
+ if (!zoneData) {
78
+ return [0, false];
79
+ }
80
+ // 4. Find the applicable transition for time t
81
+ let i = 0;
82
+ let offset = 0;
83
+ let dst = false;
84
+ for (; i <= zoneData.length; i++) {
85
+ if (i === zoneData.length || zoneData[i][0] * 1e3 > t) {
86
+ ;
87
+ [, , offset, dst] = zoneData[i - 1];
88
+ break;
89
+ }
90
+ }
91
+ // 5. Return offset in milliseconds and DST flag
92
+ return [offset * 1e3, dst];
94
93
  }
95
94
  /**
96
- * https://tc39.es/ecma402/#sec-tolocaltime
97
- * @param t
98
- * @param calendar
99
- * @param timeZone
100
- */
101
- export function ToLocalTime(t, calendar, timeZone, _a) {
102
- var tzData = _a.tzData;
103
- invariant(calendar === 'gregory', 'We only support Gregory calendar right now');
104
- var _b = getApplicableZoneData(t.toNumber(), timeZone, tzData), timeZoneOffset = _b[0], inDST = _b[1];
105
- var tz = t.plus(timeZoneOffset).toNumber();
106
- var year = YearFromTime(tz);
107
- return {
108
- weekday: WeekDay(tz),
109
- era: year < 0 ? 'BC' : 'AD',
110
- year: year,
111
- relatedYear: undefined,
112
- yearName: undefined,
113
- month: MonthFromTime(tz),
114
- day: DateFromTime(tz),
115
- hour: HourFromTime(tz),
116
- minute: MinFromTime(tz),
117
- second: SecFromTime(tz),
118
- millisecond: msFromTime(tz),
119
- inDST: inDST,
120
- // IMPORTANT: Not in spec
121
- timeZoneOffset: timeZoneOffset,
122
- };
95
+ * https://tc39.es/ecma402/#sec-tolocaltime
96
+ * @param t
97
+ * @param calendar
98
+ * @param timeZone
99
+ */
100
+ export function ToLocalTime(t, calendar, timeZone, { tzData }) {
101
+ invariant(calendar === "gregory", "We only support Gregory calendar right now");
102
+ const [timeZoneOffset, inDST] = getApplicableZoneData(t.toNumber(), timeZone, tzData);
103
+ const tz = t.plus(timeZoneOffset).toNumber();
104
+ const year = YearFromTime(tz);
105
+ return {
106
+ weekday: WeekDay(tz),
107
+ era: year < 0 ? "BC" : "AD",
108
+ year,
109
+ relatedYear: undefined,
110
+ yearName: undefined,
111
+ month: MonthFromTime(tz),
112
+ day: DateFromTime(tz),
113
+ hour: HourFromTime(tz),
114
+ minute: MinFromTime(tz),
115
+ second: SecFromTime(tz),
116
+ millisecond: msFromTime(tz),
117
+ inDST,
118
+ timeZoneOffset
119
+ };
123
120
  }
@@ -1,13 +1,13 @@
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;
1
+ import { type Formats, type 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
4
  }): [string, string];
5
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
- */
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
11
  export declare function parseDateTimeSkeleton(skeleton: string, rawPattern?: string, rangePatterns?: Record<string, string>, intervalFormatFallback?: string): Formats;
12
12
  export declare function splitFallbackRangePattern(pattern: string): Array<RangePatternPart>;
13
13
  export declare function splitRangePattern(pattern: string): Array<RangePatternPart>;