@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.
- package/add-all-tz.js +319 -318
- package/add-golden-tz.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +5 -5
- package/polyfill-force.js +28 -44
- package/polyfill.iife.js +2803 -3046
- package/polyfill.js +29 -45
- package/should-polyfill.js +38 -50
- package/src/abstract/BasicFormatMatcher.d.ts +5 -5
- package/src/abstract/BasicFormatMatcher.js +87 -103
- package/src/abstract/BestFitFormatMatcher.d.ts +12 -12
- package/src/abstract/BestFitFormatMatcher.js +102 -108
- package/src/abstract/DateTimeStyleFormat.d.ts +2 -2
- package/src/abstract/DateTimeStyleFormat.js +47 -62
- package/src/abstract/FormatDateTime.d.ts +7 -7
- package/src/abstract/FormatDateTime.js +12 -12
- package/src/abstract/FormatDateTimePattern.d.ts +11 -11
- package/src/abstract/FormatDateTimePattern.js +185 -198
- package/src/abstract/FormatDateTimeRange.d.ts +3 -3
- package/src/abstract/FormatDateTimeRange.js +9 -8
- package/src/abstract/FormatDateTimeRangeToParts.d.ts +4 -4
- package/src/abstract/FormatDateTimeRangeToParts.js +14 -12
- package/src/abstract/FormatDateTimeToParts.d.ts +9 -9
- package/src/abstract/FormatDateTimeToParts.js +17 -18
- package/src/abstract/InitializeDateTimeFormat.d.ts +15 -15
- package/src/abstract/InitializeDateTimeFormat.js +206 -184
- package/src/abstract/PartitionDateTimePattern.d.ts +8 -8
- package/src/abstract/PartitionDateTimePattern.js +15 -14
- package/src/abstract/PartitionDateTimeRangePattern.d.ts +4 -4
- package/src/abstract/PartitionDateTimeRangePattern.js +168 -161
- package/src/abstract/ToDateTimeOptions.d.ts +5 -5
- package/src/abstract/ToDateTimeOptions.js +68 -60
- package/src/abstract/ToLocalTime.d.ts +21 -21
- package/src/abstract/ToLocalTime.js +116 -45
- package/src/abstract/skeleton.d.ts +8 -8
- package/src/abstract/skeleton.js +231 -280
- package/src/abstract/utils.d.ts +1 -1
- package/src/abstract/utils.js +21 -20
- package/src/core.d.ts +17 -17
- package/src/core.js +250 -286
- package/src/data/all-tz.generated.d.ts +8 -0
- package/src/data/all-tz.generated.js +462 -0
- package/src/data/links.generated.d.ts +261 -0
- package/src/data/links.generated.js +260 -0
- package/src/get_internal_slots.d.ts +3 -1
- package/src/get_internal_slots.js +8 -7
- package/src/packer.d.ts +2 -2
- package/src/packer.js +23 -35
- package/src/to_locale_string.d.ts +3 -3
- package/src/to_locale_string.js +11 -11
- package/src/types.d.ts +34 -39
- package/src/types.js +1 -1
- package/supported-locales.generated.js +573 -1
- package/test262-main.d.ts +4 -1
- package/test262-main.js +24600 -44193
- package/src/data/all-tz.d.ts +0 -6
- package/src/data/all-tz.js +0 -461
- package/src/data/links.d.ts +0 -259
- package/src/data/links.js +0 -260
|
@@ -1,49 +1,120 @@
|
|
|
1
|
-
import { DateFromTime, HourFromTime, MinFromTime, MonthFromTime, SecFromTime, WeekDay, YearFromTime, invariant, msFromTime
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export function ToLocalTime(t, calendar, timeZone,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
2
|
-
export declare function processDateTimePattern(pattern: string, result?: Pick<Intl.DateTimeFormatOptions,
|
|
3
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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>;
|