@formatjs/intl-datetimeformat 7.1.0 → 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 (60) hide show
  1. package/add-all-tz.js +319 -318
  2. package/add-golden-tz.js +1 -1
  3. package/index.d.ts +1 -1
  4. package/index.js +1 -1
  5. package/package.json +5 -5
  6. package/polyfill-force.js +28 -44
  7. package/polyfill.iife.js +2803 -3046
  8. package/polyfill.js +29 -45
  9. package/should-polyfill.js +38 -50
  10. package/src/abstract/BasicFormatMatcher.d.ts +5 -5
  11. package/src/abstract/BasicFormatMatcher.js +87 -103
  12. package/src/abstract/BestFitFormatMatcher.d.ts +12 -12
  13. package/src/abstract/BestFitFormatMatcher.js +102 -108
  14. package/src/abstract/DateTimeStyleFormat.d.ts +2 -2
  15. package/src/abstract/DateTimeStyleFormat.js +47 -62
  16. package/src/abstract/FormatDateTime.d.ts +7 -7
  17. package/src/abstract/FormatDateTime.js +12 -12
  18. package/src/abstract/FormatDateTimePattern.d.ts +11 -11
  19. package/src/abstract/FormatDateTimePattern.js +185 -198
  20. package/src/abstract/FormatDateTimeRange.d.ts +3 -3
  21. package/src/abstract/FormatDateTimeRange.js +9 -8
  22. package/src/abstract/FormatDateTimeRangeToParts.d.ts +4 -4
  23. package/src/abstract/FormatDateTimeRangeToParts.js +14 -12
  24. package/src/abstract/FormatDateTimeToParts.d.ts +9 -9
  25. package/src/abstract/FormatDateTimeToParts.js +17 -18
  26. package/src/abstract/InitializeDateTimeFormat.d.ts +15 -15
  27. package/src/abstract/InitializeDateTimeFormat.js +206 -184
  28. package/src/abstract/PartitionDateTimePattern.d.ts +8 -8
  29. package/src/abstract/PartitionDateTimePattern.js +15 -14
  30. package/src/abstract/PartitionDateTimeRangePattern.d.ts +4 -4
  31. package/src/abstract/PartitionDateTimeRangePattern.js +168 -161
  32. package/src/abstract/ToDateTimeOptions.d.ts +5 -5
  33. package/src/abstract/ToDateTimeOptions.js +68 -60
  34. package/src/abstract/ToLocalTime.d.ts +21 -21
  35. package/src/abstract/ToLocalTime.js +116 -45
  36. package/src/abstract/skeleton.d.ts +8 -8
  37. package/src/abstract/skeleton.js +231 -280
  38. package/src/abstract/utils.d.ts +1 -1
  39. package/src/abstract/utils.js +21 -20
  40. package/src/core.d.ts +17 -17
  41. package/src/core.js +250 -286
  42. package/src/data/all-tz.generated.d.ts +8 -0
  43. package/src/data/all-tz.generated.js +462 -0
  44. package/src/data/links.generated.d.ts +261 -0
  45. package/src/data/links.generated.js +260 -0
  46. package/src/get_internal_slots.d.ts +3 -1
  47. package/src/get_internal_slots.js +8 -7
  48. package/src/packer.d.ts +2 -2
  49. package/src/packer.js +23 -35
  50. package/src/to_locale_string.d.ts +3 -3
  51. package/src/to_locale_string.js +11 -11
  52. package/src/types.d.ts +34 -39
  53. package/src/types.js +1 -1
  54. package/supported-locales.generated.js +573 -1
  55. package/test262-main.d.ts +4 -1
  56. package/test262-main.js +24600 -44193
  57. package/src/data/all-tz.d.ts +0 -6
  58. package/src/data/all-tz.js +0 -461
  59. package/src/data/links.d.ts +0 -259
  60. package/src/data/links.js +0 -260
@@ -1,49 +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
+ // Cached regex patterns for performance
3
+ const OFFSET_TIMEZONE_PREFIX_REGEX = /^[+-]/;
4
+ const OFFSET_TIMEZONE_FORMAT_REGEX = /^([+-])(\d{2})(?::?(\d{2}))?(?::?(\d{2}))?(?:\.(\d{1,9}))?$/;
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
+ */
14
+ function IsTimeZoneOffsetString(offsetString) {
15
+ return OFFSET_TIMEZONE_PREFIX_REGEX.test(offsetString);
16
+ }
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
+ */
29
+ function ParseTimeZoneOffsetString(offsetString) {
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
+ }
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
+ */
2
66
  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];
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];
20
93
  }
21
94
  /**
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
- };
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
+ };
49
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>;