Temporal: Override getPossibleInstantsFor to narrow down exception

In order for some tests to ensure that they are testing the right
exception, we need to make sure we are in the path where there are no
possible instants for a particular date-time. Override this method in some
tests.
This commit is contained in:
Philip Chimento 2022-09-15 17:40:50 -07:00 committed by Ms2ger
parent aa3afd1c28
commit 65b51e0769
12 changed files with 36 additions and 0 deletions

View File

@ -12,5 +12,8 @@ includes: [temporalHelpers.js]
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const date = new Temporal.PlainDate(2000, 5, 2);
const plainTime = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(RangeError, () => date.toZonedDateTime({ plainTime, timeZone }));
});

View File

@ -12,5 +12,8 @@ includes: [temporalHelpers.js]
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const date = new Temporal.PlainDate(2000, 5, 2);
const plainTime = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(RangeError, () => date.toZonedDateTime({ plainTime, timeZone }));
});

View File

@ -21,5 +21,8 @@ includes: [temporalHelpers.js]
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const date = new Temporal.PlainDate(2000, 5, 2);
const plainTime = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(TypeError, () => date.toZonedDateTime({ plainTime, timeZone }));
});

View File

@ -11,5 +11,8 @@ includes: [temporalHelpers.js]
[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(RangeError, () => datetime.toZonedDateTime(timeZone));
});

View File

@ -11,5 +11,8 @@ includes: [temporalHelpers.js]
[-86400_000_000_001, 86400_000_000_001].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(RangeError, () => datetime.toZonedDateTime(timeZone));
});

View File

@ -20,5 +20,8 @@ includes: [temporalHelpers.js]
].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(TypeError, () => datetime.toZonedDateTime(timeZone));
});

View File

@ -12,5 +12,8 @@ includes: [temporalHelpers.js]
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const time = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
const plainDate = new Temporal.PlainDate(2000, 5, 2);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(RangeError, () => time.toZonedDateTime({ plainDate, timeZone }));
});

View File

@ -12,5 +12,8 @@ includes: [temporalHelpers.js]
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const time = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
const plainDate = new Temporal.PlainDate(2000, 5, 2);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(RangeError, () => time.toZonedDateTime({ plainDate, timeZone }));
});

View File

@ -21,5 +21,8 @@ includes: [temporalHelpers.js]
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const time = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
const plainDate = new Temporal.PlainDate(2000, 5, 2);
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(TypeError, () => time.toZonedDateTime({ plainDate, timeZone }));
});

View File

@ -11,5 +11,8 @@ includes: [temporalHelpers.js]
[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(RangeError, () => datetime.equals({ year: 2000, month: 5, day: 2, hour: 12, timeZone }));
});

View File

@ -11,5 +11,8 @@ includes: [temporalHelpers.js]
[-86400_000_000_001, 86400_000_000_001].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(RangeError, () => datetime.equals({ year: 2000, month: 5, day: 2, hour: 12, timeZone }));
});

View File

@ -20,5 +20,8 @@ includes: [temporalHelpers.js]
].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
timeZone.getPossibleInstantsFor = function () {
return [];
};
assert.throws(TypeError, () => datetime.equals({ year: 2000, month: 5, day: 2, hour: 12, timeZone }));
});