-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
12 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...Time/prototype/since/argument-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" })); | ||
}); |
19 changes: 19 additions & 0 deletions
19
...ime/prototype/since/argument-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" })); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...eTime/prototype/since/argument-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" })); | ||
}); |
19 changes: 19 additions & 0 deletions
19
...Time/prototype/until/argument-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" })); | ||
}); |
19 changes: 19 additions & 0 deletions
19
...ime/prototype/until/argument-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" })); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...eTime/prototype/until/argument-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" })); | ||
}); |
16 changes: 16 additions & 0 deletions
16
...ndar/prototype/era/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); |
16 changes: 16 additions & 0 deletions
16
...dar/prototype/era/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...endar/prototype/era/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); |
16 changes: 16 additions & 0 deletions
16
.../prototype/eraYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); |
16 changes: 16 additions & 0 deletions
16
...prototype/eraYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...r/prototype/eraYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); |