Skip to content

Commit 828ed33

Browse files
Ms2gerptomato
authored andcommitted
Polyfill: Add missing brand checks in TimeZone.
1 parent 6fd8d28 commit 828ed33

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

lib/timezone.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class TimeZone {
5454
return ES.GetIANATimeZoneOffsetNanoseconds(GetSlot(instant, EPOCHNANOSECONDS), id);
5555
}
5656
getOffsetStringFor(instant) {
57+
if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver');
5758
instant = ES.ToTemporalInstant(instant);
5859
return ES.BuiltinTimeZoneGetOffsetStringFor(this, instant);
5960
}
@@ -63,6 +64,7 @@ export class TimeZone {
6364
return ES.BuiltinTimeZoneGetPlainDateTimeFor(this, instant, calendar);
6465
}
6566
getInstantFor(dateTime, options = undefined) {
67+
if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver');
6668
dateTime = ES.ToTemporalDateTime(dateTime);
6769
options = ES.GetOptionsObject(options);
6870
const disambiguation = ES.ToTemporalDisambiguation(options);

test/usertimezone.mjs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,14 @@ describe('Userland time zone', () => {
9494
};
9595

9696
const inst = Temporal.Instant.fromEpochNanoseconds(0n);
97-
const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789);
9897

99-
it('has offset string +00:00', () =>
100-
equal(Temporal.TimeZone.prototype.getOffsetStringFor.call(obj, inst), '+00:00'));
10198
it('converts to DateTime', () => {
10299
equal(`${Temporal.TimeZone.prototype.getPlainDateTimeFor.call(obj, inst)}`, '1970-01-01T00:00:00');
103100
equal(
104101
`${Temporal.TimeZone.prototype.getPlainDateTimeFor.call(obj, inst, 'gregory')}`,
105102
'1970-01-01T00:00:00[u-ca=gregory]'
106103
);
107104
});
108-
it('converts to Instant', () => {
109-
equal(`${Temporal.TimeZone.prototype.getInstantFor.call(obj, dt)}`, '1976-11-18T15:23:30.123456789Z');
110-
});
111105
it('offset prints in instant.toString', () => equal(inst.toString({ timeZone: obj }), '1970-01-01T00:00:00+00:00'));
112106
it('prints in zdt.toString', () => {
113107
const zdt = new Temporal.ZonedDateTime(0n, obj);

0 commit comments

Comments
 (0)