Temporal: Port staging tests that require non-ISO calendar or non-UTC time zone

As in the previous commit, without custom calendars and time zones, some
functionality cannot be tested on implementations that don't have any
other calendars and time zones than iso8601 and UTC.

Some of the staging tests fall in this category. We take the opportunity
to port these into proper tests, in the intl402/ folder.
This commit is contained in:
Philip Chimento 2024-06-28 01:02:52 +03:00 committed by Ms2ger
parent efc7424844
commit bbfcfd59b0
18 changed files with 159 additions and 76 deletions

View File

@ -0,0 +1,13 @@
// Copyright (C) 2024 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: >
Disregards the calendar if the exact times of the arguments are equal
features: [Temporal]
---*/
const arg1 = new Temporal.ZonedDateTime(1572342398_271_986_102n, "-07:00", "iso8601");
const arg2 = new Temporal.ZonedDateTime(1572342398_271_986_102n, "-07:00", "japanese");
assert.sameValue(Temporal.ZonedDateTime.compare(arg1, arg2), 0);

View File

@ -0,0 +1,46 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.zoneddatetime
description: >
Test construction and properties of an instance with non-UTC time zone and
non-ISO8601 calendar
features: [Temporal, BigInt]
---*/
var epochMillis = Date.UTC(1976, 10, 18, 15, 23, 30, 123);
var epochNanos = BigInt(epochMillis) * 1000000n + 456789n;
const instance = new Temporal.ZonedDateTime(epochNanos, "Europe/Vienna", "gregory");
assert(instance instanceof Temporal.ZonedDateTime, "instanceof is correct");
assert.sameValue(typeof instance, "object", "typeof is correct");
assert.sameValue(instance.era, "ce", "era");
assert.sameValue(instance.eraYear, 1976, "eraYear");
assert.sameValue(instance.year, 1976, "year");
assert.sameValue(instance.month, 11, "month");
assert.sameValue(instance.monthCode, "M11", "monthCode");
assert.sameValue(instance.day, 18, "day");
assert.sameValue(instance.hour, 16, "hour");
assert.sameValue(instance.minute, 23, "minute");
assert.sameValue(instance.second, 30, "second");
assert.sameValue(instance.millisecond, 123, "millisecond");
assert.sameValue(instance.microsecond, 456, "microsecond");
assert.sameValue(instance.nanosecond, 789, "nanosecond");
assert.sameValue(instance.epochMilliseconds, 217178610123, "epochMilliseconds");
assert.sameValue(instance.epochNanoseconds, 217178610123456789n, "epochNanoseconds");
assert.sameValue(instance.dayOfWeek, 4, "dayOfWeek");
assert.sameValue(instance.dayOfYear, 323, "dayOfYear");
assert.sameValue(instance.weekOfYear, 47, "weekOfYear");
assert.sameValue(instance.yearOfWeek, 1976, "yearOfWeek");
assert.sameValue(instance.daysInWeek, 7, "daysInWeek");
assert.sameValue(instance.daysInMonth, 30, "daysInMonth");
assert.sameValue(instance.daysInYear, 366, "daysInYear");
assert.sameValue(instance.monthsInYear, 12, "monthsInYear");
assert.sameValue(instance.inLeapYear, true, "inLeapYear");
assert.sameValue(instance.offset, "+01:00", "offset");
assert.sameValue(instance.offsetNanoseconds, 3600e9, "offsetNanoseconds");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2024 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: Instances with different calendars are not equal to each other
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(0n, "-05:00", "iso8601");
const instance2 = new Temporal.ZonedDateTime(0n, "-05:00", "gregory");
assert(!instance.equals(instance2), "Instances with different calendars are not equal");

View File

@ -0,0 +1,13 @@
// Copyright (C) 2024 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: >
Arithmetic between instances with two different calendars is disallowed
features: [Temporal]
---*/
const instance1 = new Temporal.ZonedDateTime(0n, "UTC", "iso8601");
const instance2 = new Temporal.ZonedDateTime(0n, "UTC", "japanese");
assert.throws(RangeError, () => instance1.since(instance2));

View File

@ -0,0 +1,12 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.zoneddatetime.prototype.toplaindate
description: The receiver's calendar is preserved in the return value
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(1572342398_271_986_102n, "-07:00", "gregory");
const result = instance.toPlainDate();
assert.sameValue(result.calendarId, "gregory", "Calendar is preserved in return value");

View File

@ -0,0 +1,13 @@
// Copyright (C) 2024 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: >
Arithmetic between instances with two different calendars is disallowed
features: [Temporal]
---*/
const instance1 = new Temporal.ZonedDateTime(0n, "UTC", "iso8601");
const instance2 = new Temporal.ZonedDateTime(0n, "UTC", "japanese");
assert.throws(RangeError, () => instance1.until(instance2));

View File

@ -0,0 +1,12 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.zoneddatetime.prototype.withcalendar
description: Basic functionality of withCalendar
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(1572342398_271_986_102n, "-07:00", "gregory");
const result = instance.withCalendar("japanese");
assert.sameValue(result.calendarId, "japanese", "withCalendar() returns a new instance with different calendarId");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.zoneddatetime.prototype.withcalendar
description: The receiver's exact time is preserved in the return value
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(1572342398_271_986_102n, "-07:00", "gregory");
const result = instance.withCalendar("japanese");
assert.sameValue(result.epochNanoseconds, 1572342398_271_986_102n, "Exact time is preserved in return value");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2024 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: The receiver's time zone is preserved in the return value
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(1572342398_271_986_102n, "-07:00", "gregory");
const result = instance.withCalendar("japanese");
assert.sameValue(result.timeZoneId, "-07:00", "Time zone is preserved in return value");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2024 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: The receiver's calendar is preserved in the return value
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(1572342398_271_986_102n, "-07:00", "gregory");
const result = instance.withTimeZone("-08:00");
assert.sameValue(result.calendarId, "gregory", "Calendar is preserved in return value");

View File

@ -110,9 +110,6 @@ assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(zdt1, {
// disregards time zone IDs if exact times are equal
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withTimeZone("+05:30")), 0);
// disregards calendar IDs if exact times and time zones are equal
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withCalendar("japanese")), 0);
// compares exact time, not clock time
var clockBefore = Temporal.ZonedDateTime.from("1999-12-31T23:30-08:00[-08:00]");
var clockAfter = Temporal.ZonedDateTime.from("2000-01-01T01:30-04:00[-04:00]");

View File

@ -45,35 +45,3 @@ assert.sameValue(zdt.inLeapYear, true);
assert.sameValue(zdt.offset, "+00:00");
assert.sameValue(zdt.offsetNanoseconds, 0);
assert.sameValue(`${ zdt }`, "1976-11-18T15:23:30.123456789+00:00[UTC]");
// Temporal.ZonedDateTime with non-UTC time zone and non-ISO calendar
// can be constructed
var zdt = new Temporal.ZonedDateTime(epochNanos, "Europe/Vienna", "gregory");
assert(zdt instanceof Temporal.ZonedDateTime);
assert.sameValue(typeof zdt, "object");
assert.sameValue(zdt.era, "ce");
assert.sameValue(zdt.year, 1976);
assert.sameValue(zdt.month, 11);
assert.sameValue(zdt.monthCode, "M11");
assert.sameValue(zdt.day, 18);
assert.sameValue(zdt.hour, 16);
assert.sameValue(zdt.minute, 23);
assert.sameValue(zdt.second, 30);
assert.sameValue(zdt.millisecond, 123);
assert.sameValue(zdt.microsecond, 456);
assert.sameValue(zdt.nanosecond, 789);
assert.sameValue(zdt.epochMilliseconds, 217178610123);
assert.sameValue(zdt.epochNanoseconds, 217178610123456789n);
assert.sameValue(zdt.dayOfWeek, 4);
assert.sameValue(zdt.dayOfYear, 323);
assert.sameValue(zdt.weekOfYear, 47);
assert.sameValue(zdt.daysInWeek, 7);
assert.sameValue(zdt.daysInMonth, 30);
assert.sameValue(zdt.daysInYear, 366);
assert.sameValue(zdt.monthsInYear, 12);
assert.sameValue(zdt.inLeapYear, true);
assert.sameValue(zdt.offset, "+01:00");
assert.sameValue(zdt.offsetNanoseconds, 3600000000000);
assert.sameValue(`${ zdt }`, "1976-11-18T16:23:30.123456789+01:00[Europe/Vienna][u-ca=gregory]");

View File

@ -29,10 +29,6 @@ assert(!zdt.equals(zdt2));
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", "iso8601");
assert(!zdt.equals(zdt2));
// different calendar not equal
var zdt2 = new Temporal.ZonedDateTime(0n, "-05:00", "gregory");
assert(!zdt.equals(zdt2));
// casts its argument
var instance = new Temporal.ZonedDateTime(0n, "UTC", "iso8601");
assert(instance.equals("1970-01-01T00:00+00:00[UTC][u-ca=iso8601]"));

View File

@ -85,11 +85,6 @@ var monthsDifference = laterDateTime.since(zdt, { largestUnit: "months" });
assert.sameValue(monthsDifference.weeks, 0);
assert.notSameValue(monthsDifference.months, 0);
// no two different calendars
var zdt1 = new Temporal.ZonedDateTime(0n, "UTC");
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", "japanese");
assert.throws(RangeError, () => zdt1.since(zdt2));
var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
var later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
// assumes a different default for largestUnit if smallestUnit is larger than days

View File

@ -10,7 +10,3 @@ features: [Temporal]
// works
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO("-07:00");
assert.sameValue(`${ zdt.toPlainDate() }`, "2019-10-29");
// preserves the calendar
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO("-07:00").withCalendar("gregory");
assert.sameValue(zdt.toPlainDate().calendarId, "gregory");

View File

@ -85,11 +85,6 @@ var monthsDifference = zdt.until(laterDateTime, { largestUnit: "months" });
assert.sameValue(monthsDifference.weeks, 0);
assert.notSameValue(monthsDifference.months, 0);
// no two different calendars
var zdt1 = new Temporal.ZonedDateTime(0n, "UTC");
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", "japanese");
assert.throws(RangeError, () => zdt1.until(zdt2));
var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
var later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
// assumes a different default for largestUnit if smallestUnit is larger than hours

View File

@ -1,20 +0,0 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal-zoneddatetime-objects
description: Temporal.ZonedDateTime.prototype.withCalendar()
features: [Temporal]
---*/
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789-08:00[-08:00]");
// zonedDateTime.withCalendar(japanese) works
assert.sameValue(`${ zdt.withCalendar("japanese") }`, "2019-11-18T15:23:30.123456789-08:00[-08:00][u-ca=japanese]");
// keeps instant and time zone the same
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00][u-ca=iso8601]");
var zdt2 = zdt.withCalendar("japanese");
assert.sameValue(zdt.epochNanoseconds, zdt2.epochNanoseconds);
assert.sameValue(zdt2.calendarId, "japanese");
assert.sameValue(zdt2.timeZoneId, "+01:00");

View File

@ -7,10 +7,9 @@ description: Temporal.ZonedDateTime.prototype.withTimeZone()
features: [Temporal]
---*/
// keeps instant and calendar the same
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00]").withCalendar("gregory");
// keeps instant the same
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00]");
var zdt2 = zdt.withTimeZone("-08:00");
assert.sameValue(zdt.epochNanoseconds, zdt2.epochNanoseconds);
assert.sameValue(zdt2.calendarId, "gregory");
assert.sameValue(zdt2.timeZoneId, "-08:00");
assert.notSameValue(`${ zdt.toPlainDateTime() }`, `${ zdt2.toPlainDateTime() }`);