-
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: Port Demitasse tests for PlainDateTime toZonedDateTime
- Loading branch information
1 parent
45fa006
commit cba0235
Showing
5 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/basic.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,15 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindatetime.prototype.tozoneddatetime | ||
description: Straightforward case of using UTC | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dt = new Temporal.PlainDateTime(2020, 1, 1, 0, 0); | ||
const zdt = dt.toZonedDateTime("UTC"); | ||
|
||
assert.sameValue(zdt.epochNanoseconds, 1577836800000000000n, "nanoseconds"); | ||
assert.sameValue(zdt.calendar.toString(), "iso8601", "calendar"); | ||
assert.sameValue(zdt.timeZone, "UTC", "timezone"); |
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
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/invalid-instant.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindatetime.prototype.tozoneddatetime | ||
description: Convert to zoned datetime outside valid range | ||
features: [Temporal] | ||
---*/ | ||
|
||
const max = new Temporal.PlainDateTime(275760, 9, 13, 23, 59, 59, 999, 999, 999); | ||
const min = new Temporal.PlainDateTime(-271821, 4, 19, 0, 0, 0, 0, 0, 1); | ||
|
||
assert.throws( | ||
RangeError, | ||
() => max.toZonedDateTime("UTC"), | ||
"outside of Instant range (too big)" | ||
); | ||
|
||
assert.throws( | ||
RangeError, | ||
() => min.toZonedDateTime("UTC"), | ||
"outside of Instant range (too small)" | ||
); |
47 changes: 47 additions & 0 deletions
47
test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/multiple-instants.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,47 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindatetime.prototype.tozoneddatetime | ||
description: Checking disambiguation options for daylight savings time changes | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
const tz = TemporalHelpers.springForwardFallBackTimeZone(); | ||
|
||
const dt1 = new Temporal.PlainDateTime(2000, 4, 2, 2); | ||
|
||
const zdt1 = dt1.toZonedDateTime(tz); | ||
const zdt1_compatible = dt1.toZonedDateTime(tz, { disambiguation: "compatible" }); | ||
const zdt1_earlier = dt1.toZonedDateTime(tz, { disambiguation: "earlier" }); | ||
const zdt1_later = dt1.toZonedDateTime(tz, { disambiguation: "later" }); | ||
|
||
assert.sameValue(zdt1.epochNanoseconds, 954669600000000000n, "Fall DST (no disambiguation)"); | ||
assert.sameValue(zdt1_compatible.epochNanoseconds, 954669600000000000n, "Fall DST (disambiguation = compatible)"); | ||
assert.sameValue(zdt1_earlier.epochNanoseconds, 954666000000000000n, "Fall DST (disambiguation = earlier)"); | ||
assert.sameValue(zdt1_later.epochNanoseconds, 954669600000000000n, "Fall DST (disambiguation = later)"); | ||
|
||
assert.throws( | ||
RangeError, | ||
() => dt1.toZonedDateTime(tz, { disambiguation: "reject" }), | ||
"Fall DST (disambiguation = reject)" | ||
); | ||
|
||
const dt2 = new Temporal.PlainDateTime(2000, 10, 29, 1); | ||
|
||
const zdt2 = dt2.toZonedDateTime(tz); | ||
const zdt2_compatible = dt2.toZonedDateTime(tz, { disambiguation: "compatible" }); | ||
const zdt2_earlier = dt2.toZonedDateTime(tz, { disambiguation: "earlier" }); | ||
const zdt2_later = dt2.toZonedDateTime(tz, { disambiguation: "later" }); | ||
|
||
assert.sameValue(zdt2.epochNanoseconds, 972806400000000000n, "Spring DST (no disambiguation)"); | ||
assert.sameValue(zdt2_compatible.epochNanoseconds, 972806400000000000n, "Spring DST (disambiguation = compatible)"); | ||
assert.sameValue(zdt2_earlier.epochNanoseconds, 972806400000000000n, "Spring DST (disambiguation = earlier)"); | ||
assert.sameValue(zdt2_later.epochNanoseconds, 972810000000000000n, "Spring DST (disambiguation = later)"); | ||
|
||
assert.throws( | ||
RangeError, | ||
() => dt2.toZonedDateTime(tz, { disambiguation: "reject" }), | ||
"Spring DST (disambiguation = reject)" | ||
); |
22 changes: 22 additions & 0 deletions
22
test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/options-object.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,22 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.prototype.tozoneddatetime | ||
description: Empty object may be used as options | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dt = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102); | ||
|
||
assert.sameValue( | ||
dt.toZonedDateTime("UTC", {}).epochNanoseconds, | ||
1572345998271986102n, | ||
"options may be an empty plain object" | ||
); | ||
|
||
assert.sameValue( | ||
dt.toZonedDateTime("UTC", () => {}).epochNanoseconds, | ||
1572345998271986102n, | ||
"options may be a function object" | ||
); |