Temporal: Add tests for casting a time zone ID string to a Temporal.TimeZone

This adds tests to every entry point where a Temporal.TimeZone is
accepted, making sure that a time zone ID string is also accepted.
This commit is contained in:
Philip Chimento 2022-07-28 17:11:59 -07:00 committed by Philip Chimento
parent 7d31aa21ad
commit bc0e006de4
26 changed files with 377 additions and 0 deletions

View File

@ -0,0 +1,14 @@
// 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.duration.compare
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
});

View File

@ -0,0 +1,16 @@
// 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.duration.prototype.add
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.Duration(1);
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
});

View File

@ -0,0 +1,16 @@
// 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.duration.prototype.round
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.Duration(1);
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
});

View File

@ -0,0 +1,16 @@
// 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.duration.prototype.subtract
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.Duration(1);
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
});

View File

@ -0,0 +1,16 @@
// 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.duration.prototype.total
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.Duration(1);
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
});

View File

@ -0,0 +1,16 @@
// 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.instant.prototype.tostring
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.Instant(0n);
const result1 = instance.toString({ timeZone: "UTC" });
assert.sameValue(result1.substr(-6), "+00:00", "Time zone created from string 'UTC'");
const result2 = instance.toString({ timeZone: "-01:30" });
assert.sameValue(result2.substr(-6), "-01:30", "Time zone created from string '-01:30'");

View File

@ -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.instant.prototype.tozoneddatetime
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.Instant(0n);
["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -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.instant.prototype.tozoneddatetimeiso
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.Instant(0n);
["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -0,0 +1,14 @@
// 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.now.plaindate
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainDate("iso8601", timeZone);
});

View File

@ -0,0 +1,14 @@
// 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.now.plaindateiso
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainDateISO(timeZone);
});

View File

@ -0,0 +1,14 @@
// 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.now.plaindatetime
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainDateTime("iso8601", timeZone);
});

View File

@ -0,0 +1,14 @@
// 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.now.plaindatetimeiso
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainDateTimeISO(timeZone);
});

View File

@ -0,0 +1,14 @@
// 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.now.plaintimeiso
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainTimeISO(timeZone);
});

View File

@ -0,0 +1,13 @@
// 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.now.zoneddatetime
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
["UTC", "+01:30"].forEach((timeZone) => {
const result = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -0,0 +1,13 @@
// 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.now.zoneddatetimeiso
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
["UTC", "+01:30"].forEach((timeZone) => {
const result = Temporal.Now.zonedDateTimeISO(timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -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.plaindate.prototype.tozoneddatetime
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.PlainDate(2000, 5, 2);
["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTime(timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -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: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.PlainDateTime(2000, 5, 2);
["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTime(timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -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.plaintime.prototype.tozoneddatetime
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.PlainTime();
["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTime({ plainDate: new Temporal.PlainDate(2000, 5, 2), timeZone });
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -0,0 +1,13 @@
// 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.timezone.from
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
["UTC", "+01:30"].forEach((timeZone) => {
const result = Temporal.TimeZone.from(timeZone);
assert.sameValue(result.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -0,0 +1,16 @@
// 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.compare
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
["UTC", "+01:30"].forEach((timeZone) => {
const epoch = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone(timeZone));
// These should be valid input and not throw
Temporal.ZonedDateTime.compare({ year: 2020, month: 5, day: 2, timeZone }, epoch);
Temporal.ZonedDateTime.compare(epoch, { year: 2020, month: 5, day: 2, timeZone });
});

View File

@ -0,0 +1,13 @@
// 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.from
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
["UTC", "+01:30"].forEach((timeZone) => {
const result = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone });
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -0,0 +1,14 @@
// 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.equals
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance1 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC"));
assert(instance1.equals({ year: 1970, month: 1, day: 1, timeZone: "UTC" }), "Time zone created from string 'UTC'");
const instance2 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("-01:30"));
assert(instance2.equals({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }), "Time zone created from string '-01:30'");

View File

@ -0,0 +1,14 @@
// 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.since
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance1 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC"));
assert(instance1.since({ year: 1970, month: 1, day: 1, timeZone: "UTC" }).blank, "Time zone created from string 'UTC'");
const instance2 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("-01:30"));
assert(instance2.since({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }).blank, "Time zone created from string '-01:30'");

View File

@ -0,0 +1,14 @@
// 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.until
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance1 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC"));
assert(instance1.until({ year: 1970, month: 1, day: 1, timeZone: "UTC" }).blank, "Time zone created from string 'UTC'");
const instance2 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("-01:30"));
assert(instance2.until({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }).blank, "Time zone created from string '-01:30'");

View File

@ -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.zoneddatetime.prototype.withtimezone
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(0n, "UTC");
["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.withTimeZone(timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});

View File

@ -0,0 +1,13 @@
// 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
description: Time zone IDs are valid input for a time zone
features: [Temporal]
---*/
["UTC", "+01:30"].forEach((timeZone) => {
const result = new Temporal.ZonedDateTime(0n, timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
});