Skip to content

Commit b8138dc

Browse files
12wrigjaptomato
andauthored
Co-authored-by: Philip Chimento <[email protected]>
1 parent 3008a67 commit b8138dc

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

lib/ecmascript.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,21 +283,12 @@ export function RejectObjectWithCalendarOrTimeZone(item: AnyTemporalLikeType) {
283283
throw new TypeError('with() does not support a timeZone property');
284284
}
285285
}
286-
function TemporalTimeZoneFromString(stringIdent: string) {
286+
function ParseTemporalTimeZone(stringIdent: string) {
287287
// TODO: why aren't these three variables destructured to include `undefined` as possible types?
288288
let { ianaName, offset, z } = ParseTemporalTimeZoneString(stringIdent);
289-
let identifier = ianaName;
290-
if (!identifier && z) identifier = 'UTC';
291-
if (!identifier) identifier = offset;
292-
const result = GetCanonicalTimeZoneIdentifier(identifier);
293-
if (offset && identifier !== offset) {
294-
const ns = ParseTemporalInstant(stringIdent);
295-
const offsetNs = GetIANATimeZoneOffsetNanoseconds(ns, result);
296-
if (FormatTimeZoneOffsetString(offsetNs) !== offset) {
297-
throw new RangeError(`invalid offset ${offset}[${ianaName}]`);
298-
}
299-
}
300-
return result;
289+
if (ianaName) return ianaName;
290+
if (z) return 'UTC';
291+
return offset;
301292
}
302293

303294
function FormatCalendarAnnotation(id: string, showCalendar: Temporal.ShowCalendarOption['calendarName']) {
@@ -2154,7 +2145,7 @@ export function ToTemporalTimeZone(temporalTimeZoneLikeParam: TimeZoneParams['fr
21542145
}
21552146
}
21562147
const identifier = ToString(temporalTimeZoneLike);
2157-
const timeZone = TemporalTimeZoneFromString(identifier);
2148+
const timeZone = ParseTemporalTimeZone(identifier);
21582149
const TemporalTimeZone = GetIntrinsic('%Temporal.TimeZone%');
21592150
return new TemporalTimeZone(timeZone);
21602151
}
@@ -5056,7 +5047,7 @@ export const SystemUTCEpochNanoSeconds: () => bigInt.BigInteger = (() => {
50565047
export function SystemTimeZone() {
50575048
const fmt = new IntlDateTimeFormat('en-us');
50585049
const TemporalTimeZone = GetIntrinsic('%Temporal.TimeZone%');
5059-
return new TemporalTimeZone(TemporalTimeZoneFromString(fmt.resolvedOptions().timeZone));
5050+
return new TemporalTimeZone(ParseTemporalTimeZone(fmt.resolvedOptions().timeZone));
50605051
}
50615052

50625053
export function ComparisonResult(value: number) {

test/expected-failures.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
# Blocked on https://github.com/tc39/test262/pull/3304
77
built-ins/Temporal/Instant/prototype/round/options-wrong-type.js
88
built-ins/Temporal/Duration/prototype/total/options-wrong-type.js
9+
10+
# https://github.com/tc39/test262/pull/3316
11+
intl402/Temporal/TimeZone/from/argument-invalid.js

test/regex.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,10 @@ describe('fromString regex', () => {
483483
generateTest('1976-11-18T15:23', zoneString, '-04:00')
484484
);
485485
// Various numbers of decimal places
486-
['1', '12', '123', '1234', '12345', '123456', '1234567', '12345678'].forEach((decimals) =>
487-
test(`1976-11-18T15:23:30.${decimals}Z`, 'UTC')
488-
);
486+
['1', '12', '123', '1234', '12345', '123456', '1234567', '12345678'].forEach((decimals) => {
487+
test(`1976-11-18T15:23:30.${decimals}Z`, 'UTC');
488+
test(`1976-11-18T15:23+01:00[+01:00:00.${decimals}]`, `+01:00:00.${decimals}`);
489+
});
489490
// Lowercase UTC designator
490491
generateTest('1976-11-18T15:23', 'z', 'UTC');
491492
// Comma decimal separator

test/timezone.mjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ describe('TimeZone', () => {
157157
it(`TimeZone.from(${isoString}) is a time zone`, () => equal(typeof tz, 'object'));
158158
it(`TimeZone.from(${isoString}) has ID ${id}`, () => equal(tz.id, id));
159159
}
160-
it('offset disagreeing with IANA name throws', () => {
161-
throws(() => Temporal.TimeZone.from('1994-11-05T08:15:30-05:00[UTC]'), RangeError);
162-
throws(() => Temporal.TimeZone.from('1994-11-05T13:15:30+00:00[America/New_York]'), RangeError);
163-
throws(() => Temporal.TimeZone.from('1994-11-05T13:15:30-03[Europe/Brussels]'), RangeError);
164-
});
165160
it('offset out of range throws', () => {
166161
throws(() => Temporal.TimeZone.from('1994-11-05T08:15:30+25:00'), RangeError);
167162
throws(() => Temporal.TimeZone.from('1994-11-05T13:15:30-25:00'), RangeError);

0 commit comments

Comments
 (0)