Skip to content

Commit c29428c

Browse files
justingrantptomato
authored andcommitted
Support offset time zones in Intl.DTF polyfill
In Node 23, offset time zone IDs are now supported by `Intl.DateTimeFormat`. This commit changes the polyfill to handle these IDs.
1 parent b8df3ae commit c29428c

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

lib/intl.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ function createDateTimeFormat(
162162
SetSlot(dtf, TZ_ORIGINAL, ro.timeZone);
163163
} else {
164164
const id = ES.ToString(timeZoneOption);
165-
if (ES.IsOffsetTimeZoneIdentifier(id)) {
166-
// Note: https://github.com/tc39/ecma402/issues/683 will remove this
167-
throw new RangeError('Intl.DateTimeFormat does not currently support offset time zones');
165+
if (id.startsWith('−')) {
166+
// The initial (Node 23) implementation of offset time zones allowed use
167+
// of the Unicode minus sign, which was disallowed by a later spec change.
168+
throw new RangeError('Unicode minus (U+2212) is not supported in time zone offsets');
168169
}
169-
const record = ES.GetAvailableNamedTimeZoneIdentifier(id);
170-
if (!record) throw new RangeError(`Intl.DateTimeFormat formats built-in time zones, not ${id}`);
171-
SetSlot(dtf, TZ_ORIGINAL, record.identifier);
170+
// store a normalized identifier
171+
SetSlot(dtf, TZ_ORIGINAL, ES.ToTemporalTimeZoneIdentifier(id));
172172
}
173173
return undefined; // TODO: I couldn't satisfy TS without adding this. Is there another way?
174174
}

test/expected-failures.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
# canonicalizing the timezone name.
77
staging/Intl402/Temporal/old/date-time-format.js
88

9-
# These are caught by the default test glob, but are unrelated to Temporal.
10-
# They rely on Intl.DateTimeFormat supporting offset time zones.
11-
intl402/DateTimeFormat/prototype/format/offset-timezone-gmt-same.js
12-
intl402/DateTimeFormat/prototype/formatToParts/offset-timezone-correct.js
13-
intl402/DateTimeFormat/prototype/resolvedOptions/offset-timezone-basic.js
14-
intl402/DateTimeFormat/prototype/resolvedOptions/offset-timezone-change.js
15-
169
# https://github.com/tc39/test262/pull/4336
1710
intl402/DateTimeFormat/canonicalize-utc-timezone.js
1811

0 commit comments

Comments
 (0)