Temporal: Move more ZonedDateTime tests out of staging

This commit is contained in:
Tim Chevalier 2024-10-29 12:24:00 -07:00 committed by Philip Chimento
parent 5505758111
commit bfb957f669
9 changed files with 161 additions and 104 deletions

View File

@ -2,13 +2,13 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal-zoneddatetime-objects
description: Construction and properties
esid: sec-temporal.zoneddatetime
description: Construction and properties.
features: [Temporal]
---*/
var epochMillis = Date.UTC(1976, 10, 18, 15, 23, 30, 123);
var epochNanos = BigInt(epochMillis) * BigInt(1000000) + BigInt(456789);
const epochMillis = Date.UTC(1976, 10, 18, 15, 23, 30, 123);
const epochNanos = BigInt(epochMillis) * BigInt(1000000) + BigInt(456789);
// works
var zdt = new Temporal.ZonedDateTime(epochNanos, "-08:00");
@ -17,7 +17,7 @@ assert.sameValue(typeof zdt, "object");
assert.sameValue(zdt.toInstant().epochMilliseconds, Date.UTC(1976, 10, 18, 15, 23, 30, 123), "epochMilliseconds");
// Temporal.ZonedDateTime for (1976, 11, 18, 15, 23, 30, 123, 456, 789)"
var zdt = new Temporal.ZonedDateTime(epochNanos, "UTC");
zdt = new Temporal.ZonedDateTime(epochNanos, "UTC");
// can be constructed
assert(zdt instanceof Temporal.ZonedDateTime);
assert.sameValue(typeof zdt, "object");

View File

@ -0,0 +1,43 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.zoneddatetime.prototype.add
description: Hours overflow.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
// subtract result
// var later = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102-03:00[-03:00]");
var later = new Temporal.ZonedDateTime(1572356798271986102n, "-03:00");
var earlier = later.subtract({ hours: 12 });
TemporalHelpers.assertZonedDateTimesEqual(
earlier,
// "2019-10-28T22:46:38.271986102-03:00[-03:00]"
new Temporal.ZonedDateTime(1572313598271986102n, "-03:00"));
// add result
// earlier = Temporal.ZonedDateTime.from("2020-05-31T23:12:38.271986102-04:00[-04:00]");
earlier = new Temporal.ZonedDateTime(1590981158271986102n, "-04:00");
later = earlier.add({ hours: 2 });
TemporalHelpers.assertZonedDateTimesEqual(
later,
new Temporal.ZonedDateTime(1590988358271986102n, "-04:00"));
// 2019-10-29T10:46:38.271986102-03:00[-03:00]
later = new Temporal.ZonedDateTime(1572356798271986102n, "-03:00");
// 2019-10-28T22:46:38.271986102-03:00[-03:00]
earlier = new Temporal.ZonedDateTime(1572313598271986102n, "-03:00");
// symmetrical with regard to negative durations
TemporalHelpers.assertZonedDateTimesEqual(later.add({ hours: -12 }), earlier);
// "2020-05-31T23:12:38.271986102-04:00[-04:00]"
earlier = new Temporal.ZonedDateTime(1590981158271986102n, "-04:00");
later = new Temporal.ZonedDateTime(1590988358271986102n, "-04:00");
TemporalHelpers.assertZonedDateTimesEqual(earlier.subtract({ hours: -2 }), later);

View File

@ -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.equals
description: Different time zones not equal.
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(0n, "UTC", "iso8601");
assert(instance.equals("1970-01-01T00:00+00:00[UTC][u-ca=iso8601]"));
assert(instance.equals({
year: 1970,
month: 1,
day: 1,
timeZone: "UTC",
calendar: "iso8601",
}));

View File

@ -0,0 +1,22 @@
// 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.equals
description: ZonedDateTimes constructed from equivalent parameters are equal.
features: [Temporal]
---*/
const zdt = new Temporal.ZonedDateTime(0n, "-05:00", "iso8601");
// constructed from equivalent parameters are equal
const zdt2 = Temporal.ZonedDateTime.from({
year: 1969,
month: 12,
day: 31,
hour: 19,
timeZone: "-05:00",
calendar: "iso8601",
});
assert(zdt.equals(zdt2));
assert(zdt2.equals(zdt));

View File

@ -0,0 +1,13 @@
// 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.equals
description: Different instants not equal.
features: [Temporal]
---*/
const zdt = new Temporal.ZonedDateTime(0n, "-05:00", "iso8601");
const zdt2 = new Temporal.ZonedDateTime(1n, "-05:00", "iso8601");
assert(!zdt.equals(zdt2));

View File

@ -0,0 +1,14 @@
// 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.equals
description: Different time zones not equal.
features: [Temporal]
---*/
const zdt = new Temporal.ZonedDateTime(0n, "-05:00", "iso8601");
const zdt2 = new Temporal.ZonedDateTime(0n, "UTC", "iso8601");
assert(!zdt.equals(zdt2));

View File

@ -0,0 +1,45 @@
// 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.equals
description: At least the required properties must be present.
features: [Temporal]
---*/
const zdt = new Temporal.ZonedDateTime(0n, "-05:00", "iso8601");
// at least the required properties must be present
assert(!zdt.equals({
year: 1969,
month: 12,
day: 31,
timeZone: "-05:00"
}));
assert.throws(TypeError, () => zdt.equals({
month: 12,
day: 31,
timeZone: "-05:00"
}));
assert.throws(TypeError, () => zdt.equals({
year: 1969,
day: 31,
timeZone: "-05:00"
}));
assert.throws(TypeError, () => zdt.equals({
year: 1969,
month: 12,
timeZone: "-05:00"
}));
assert.throws(TypeError, () => zdt.equals({
year: 1969,
month: 12,
day: 31
}));
assert.throws(TypeError, () => zdt.equals({
years: 1969,
months: 12,
days: 31,
timeZone: "-05:00",
calendarName: "iso8601"
}));

View File

@ -1,23 +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: hours overflow
features: [Temporal]
---*/
// subtract result
var later = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102-03:00[-03:00]");
var earlier = later.subtract({ hours: 12 });
assert.sameValue(`${ earlier }`, "2019-10-28T22:46:38.271986102-03:00[-03:00]");
// add result
var earlier = Temporal.ZonedDateTime.from("2020-05-31T23:12:38.271986102-04:00[-04:00]");
var later = earlier.add({ hours: 2 });
assert.sameValue(`${ later }`, "2020-06-01T01:12:38.271986102-04:00[-04:00]");
// symmetrical with regard to negative durations
assert.sameValue(`${ Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102-03:00[-03:00]").add({ hours: -12 }) }`, "2019-10-28T22:46:38.271986102-03:00[-03:00]");
assert.sameValue(`${ Temporal.ZonedDateTime.from("2020-05-31T23:12:38.271986102-04:00[-04:00]").subtract({ hours: -2 }) }`, "2020-06-01T01:12:38.271986102-04:00[-04:00]");

View File

@ -1,76 +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.equals()
features: [Temporal]
---*/
var zdt = new Temporal.ZonedDateTime(0n, "-05:00", "iso8601");
// constructed from equivalent parameters are equal
var zdt2 = Temporal.ZonedDateTime.from({
year: 1969,
month: 12,
day: 31,
hour: 19,
timeZone: "-05:00",
calendar: "iso8601",
});
assert(zdt.equals(zdt2));
assert(zdt2.equals(zdt));
// different instant not equal
var zdt2 = new Temporal.ZonedDateTime(1n, "-05:00", "iso8601");
assert(!zdt.equals(zdt2));
// different time zone not equal
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", "iso8601");
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]"));
assert(instance.equals({
year: 1970,
month: 1,
day: 1,
timeZone: "UTC",
calendar: "iso8601",
}));
// at least the required properties must be present
assert(!zdt.equals({
year: 1969,
month: 12,
day: 31,
timeZone: "-05:00"
}));
assert.throws(TypeError, () => zdt.equals({
month: 12,
day: 31,
timeZone: "-05:00"
}));
assert.throws(TypeError, () => zdt.equals({
year: 1969,
day: 31,
timeZone: "-05:00"
}));
assert.throws(TypeError, () => zdt.equals({
year: 1969,
month: 12,
timeZone: "-05:00"
}));
assert.throws(TypeError, () => zdt.equals({
year: 1969,
month: 12,
day: 31
}));
assert.throws(TypeError, () => zdt.equals({
years: 1969,
months: 12,
days: 31,
timeZone: "-05:00",
calendarName: "iso8601"
}));