mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 21:45:04 +02:00
Temporal: Improve existing tests for ZDT#toString timeZoneName option
Based on the improvements just made to the calendarName option, improve the tests for the timeZoneName option of ZonedDateTime.prototype.toString as well.
This commit is contained in:
parent
c0bb28d2f3
commit
d5404f4d24
23
test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js
vendored
Normal file
23
test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js
vendored
Normal file
@ -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.zoneddatetime.prototype.tostring
|
||||||
|
description: If timeZoneName is "auto", the time zone ID should be included.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
["UTC", "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in UTC"],
|
||||||
|
["+01:00", "1970-01-01T02:01:01.987654321+01:00[+01:00]", "built-in offset"],
|
||||||
|
[{
|
||||||
|
getOffsetNanosecondsFor() { return 0; },
|
||||||
|
toString() { return "Etc/Custom"; },
|
||||||
|
}, "1970-01-01T01:01:01.987654321+00:00[Etc/Custom]", "custom"],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const [timeZone, expected, description] of tests) {
|
||||||
|
const date = new Temporal.ZonedDateTime(3661_987_654_321n, timeZone);
|
||||||
|
const result = date.toString({ timeZoneName: "auto" });
|
||||||
|
assert.sameValue(result, expected, `${description} time zone for timeZoneName = auto`);
|
||||||
|
}
|
@ -15,4 +15,12 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_64_321n, "UTC");
|
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_64_321n, "UTC");
|
||||||
assert.throws(RangeError, () => datetime.toString({ timeZoneName: "other string" }));
|
const invalidValues = ["NEVER", "sometimes", "other string", "auto\0"];
|
||||||
|
|
||||||
|
for (const timeZoneName of invalidValues) {
|
||||||
|
assert.throws(
|
||||||
|
RangeError,
|
||||||
|
() => datetime.toString({ timeZoneName }),
|
||||||
|
`${timeZoneName} is an invalid value for timeZoneName option`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
23
test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-never.js
vendored
Normal file
23
test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-never.js
vendored
Normal file
@ -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.zoneddatetime.prototype.tostring
|
||||||
|
description: If timeZoneName is "never", the time zone ID should be omitted.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
["UTC", "1970-01-01T01:01:01.987654321+00:00", "built-in UTC"],
|
||||||
|
["+01:00", "1970-01-01T02:01:01.987654321+01:00", "built-in offset"],
|
||||||
|
[{
|
||||||
|
getOffsetNanosecondsFor() { return 0; },
|
||||||
|
toString() { return "Etc/Custom"; },
|
||||||
|
}, "1970-01-01T01:01:01.987654321+00:00", "custom"],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const [timeZone, expected, description] of tests) {
|
||||||
|
const date = new Temporal.ZonedDateTime(3661_987_654_321n, timeZone);
|
||||||
|
const result = date.toString({ timeZoneName: "never" });
|
||||||
|
assert.sameValue(result, expected, `${description} time zone for timeZoneName = never`);
|
||||||
|
}
|
@ -19,4 +19,4 @@ const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
|||||||
const explicit = datetime.toString({ timeZoneName: undefined });
|
const explicit = datetime.toString({ timeZoneName: undefined });
|
||||||
assert.sameValue(explicit, "2001-09-09T01:46:40.987654321+00:00[UTC]", "default timeZoneName option is auto");
|
assert.sameValue(explicit, "2001-09-09T01:46:40.987654321+00:00[UTC]", "default timeZoneName option is auto");
|
||||||
|
|
||||||
// See options-undefined.js for {}
|
// See options-object.js for {} and options-undefined.js for absent
|
||||||
|
@ -11,12 +11,6 @@ features: [Temporal]
|
|||||||
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23+00:00[UTC]");
|
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23+00:00[UTC]");
|
||||||
var fakeGregorian = { toString() { return "gregory" }};
|
var fakeGregorian = { toString() { return "gregory" }};
|
||||||
|
|
||||||
// shows time zone if timeZoneName = auto
|
|
||||||
assert.sameValue(zdt1.toString({ timeZoneName: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");
|
|
||||||
|
|
||||||
// omits time zone if timeZoneName = never
|
|
||||||
assert.sameValue(zdt1.toString({ timeZoneName: "never" }), "1976-11-18T15:23:00+00:00");
|
|
||||||
|
|
||||||
// shows offset if offset = auto
|
// shows offset if offset = auto
|
||||||
assert.sameValue(zdt1.toString({ offset: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");
|
assert.sameValue(zdt1.toString({ offset: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user