mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 13:34:38 +02:00
Temporal: Add more getOffsetNanosecondsFor validation tests
This adds tests that validate a user-callable getOffsetNanosecondsFor to several APIs that didn't test this yet: ZonedDateTime.since/until, and Calendar.era/eraYear.
This commit is contained in:
parent
65b51e0769
commit
31ad95d34e
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.since
|
||||||
|
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
|
||||||
|
features: [Temporal]
|
||||||
|
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");
|
||||||
|
const properties = { year: 2004, month: 11, day: 9, hour: 11, minute: 33, second: 20, timeZone };
|
||||||
|
timeZone.getPossibleInstantsFor = function () {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
assert.throws(RangeError, () => datetime.since(properties, { largestUnit: "days" }));
|
||||||
|
});
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.since
|
||||||
|
description: RangeError thrown if time zone reports an offset that is out of range
|
||||||
|
features: [Temporal]
|
||||||
|
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");
|
||||||
|
const properties = { year: 2004, month: 11, day: 9, hour: 11, minute: 33, second: 20, timeZone };
|
||||||
|
timeZone.getPossibleInstantsFor = function () {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
assert.throws(RangeError, () => datetime.since(properties, { largestUnit: "days" }));
|
||||||
|
});
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.since
|
||||||
|
description: TypeError thrown if time zone reports an offset that is not a Number
|
||||||
|
features: [Temporal]
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
[
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"+01:00",
|
||||||
|
Symbol(),
|
||||||
|
3600_000_000_000n,
|
||||||
|
{},
|
||||||
|
{ valueOf() { return 3600_000_000_000; } },
|
||||||
|
].forEach((wrongOffset) => {
|
||||||
|
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
||||||
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
||||||
|
const properties = { year: 2004, month: 11, day: 9, hour: 11, minute: 33, second: 20, timeZone };
|
||||||
|
timeZone.getPossibleInstantsFor = function () {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
assert.throws(TypeError, () => datetime.since(properties, { largestUnit: "days" }));
|
||||||
|
});
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
|
||||||
|
features: [Temporal]
|
||||||
|
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");
|
||||||
|
const properties = { year: 2004, month: 11, day: 9, hour: 11, minute: 33, second: 20, timeZone };
|
||||||
|
timeZone.getPossibleInstantsFor = function () {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
assert.throws(RangeError, () => datetime.until(properties, { largestUnit: "days" }));
|
||||||
|
});
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: RangeError thrown if time zone reports an offset that is out of range
|
||||||
|
features: [Temporal]
|
||||||
|
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");
|
||||||
|
const properties = { year: 2004, month: 11, day: 9, hour: 11, minute: 33, second: 20, timeZone };
|
||||||
|
timeZone.getPossibleInstantsFor = function () {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
assert.throws(RangeError, () => datetime.until(properties, { largestUnit: "days" }));
|
||||||
|
});
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: TypeError thrown if time zone reports an offset that is not a Number
|
||||||
|
features: [Temporal]
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
[
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"+01:00",
|
||||||
|
Symbol(),
|
||||||
|
3600_000_000_000n,
|
||||||
|
{},
|
||||||
|
{ valueOf() { return 3600_000_000_000; } },
|
||||||
|
].forEach((wrongOffset) => {
|
||||||
|
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
||||||
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
||||||
|
const properties = { year: 2004, month: 11, day: 9, hour: 11, minute: 33, second: 20, timeZone };
|
||||||
|
timeZone.getPossibleInstantsFor = function () {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
assert.throws(TypeError, () => datetime.until(properties, { largestUnit: "days" }));
|
||||||
|
});
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.calendar.prototype.era
|
||||||
|
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
|
||||||
|
features: [Temporal]
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => {
|
||||||
|
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
||||||
|
const calendar = new Temporal.Calendar("iso8601");
|
||||||
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
||||||
|
assert.throws(RangeError, () => calendar.era(datetime));
|
||||||
|
});
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.calendar.prototype.era
|
||||||
|
description: RangeError thrown if time zone reports an offset that is out of range
|
||||||
|
features: [Temporal]
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
[-86400_000_000_001, 86400_000_000_001].forEach((wrongOffset) => {
|
||||||
|
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
||||||
|
const calendar = new Temporal.Calendar("iso8601");
|
||||||
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
||||||
|
assert.throws(RangeError, () => calendar.era(datetime));
|
||||||
|
});
|
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.calendar.prototype.era
|
||||||
|
description: TypeError thrown if time zone reports an offset that is not a Number
|
||||||
|
features: [Temporal]
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
[
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"+01:00",
|
||||||
|
Symbol(),
|
||||||
|
3600_000_000_000n,
|
||||||
|
{},
|
||||||
|
{ valueOf() { return 3600_000_000_000; } },
|
||||||
|
].forEach((wrongOffset) => {
|
||||||
|
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
||||||
|
const calendar = new Temporal.Calendar("iso8601");
|
||||||
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
||||||
|
assert.throws(TypeError, () => calendar.era(datetime));
|
||||||
|
});
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.calendar.prototype.erayear
|
||||||
|
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
|
||||||
|
features: [Temporal]
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => {
|
||||||
|
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
||||||
|
const calendar = new Temporal.Calendar("iso8601");
|
||||||
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
||||||
|
assert.throws(RangeError, () => calendar.eraYear(datetime));
|
||||||
|
});
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.calendar.prototype.erayear
|
||||||
|
description: RangeError thrown if time zone reports an offset that is out of range
|
||||||
|
features: [Temporal]
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
[-86400_000_000_001, 86400_000_000_001].forEach((wrongOffset) => {
|
||||||
|
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
||||||
|
const calendar = new Temporal.Calendar("iso8601");
|
||||||
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
||||||
|
assert.throws(RangeError, () => calendar.eraYear(datetime));
|
||||||
|
});
|
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.calendar.prototype.erayear
|
||||||
|
description: TypeError thrown if time zone reports an offset that is not a Number
|
||||||
|
features: [Temporal]
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
[
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"+01:00",
|
||||||
|
Symbol(),
|
||||||
|
3600_000_000_000n,
|
||||||
|
{},
|
||||||
|
{ valueOf() { return 3600_000_000_000; } },
|
||||||
|
].forEach((wrongOffset) => {
|
||||||
|
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
||||||
|
const calendar = new Temporal.Calendar("iso8601");
|
||||||
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
||||||
|
assert.throws(TypeError, () => calendar.eraYear(datetime));
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user