Temporal: Move tests for ZonedDateTime/compare out of staging into test/built-ins

This commit is contained in:
Tim Chevalier 2024-10-29 11:59:33 -07:00 committed by Philip Chimento
parent 455cfa5a66
commit 01dbd4db41
5 changed files with 102 additions and 43 deletions

View File

@ -0,0 +1,24 @@
// 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: Temporal.ZonedDateTime.compare works
features: [Temporal]
---*/
/*
const zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
const zdt2 = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102+01:00[+01:00]");
*/
const zdt1 = new Temporal.ZonedDateTime(217175010123456789n, "+01:00");
const zdt2 = new Temporal.ZonedDateTime(1572342398271986102n, "+01:00");
// equal
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1), 0)
// smaller/larger
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt2), -1)
// larger/smaller
assert.sameValue(Temporal.ZonedDateTime.compare(zdt2, zdt1), 1)

View File

@ -0,0 +1,35 @@
// 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: Casts first and second arguments.
features: [Temporal]
---*/
/*
const zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
const zdt2 = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102+01:00[+01:00]");
*/
const zdt1 = new Temporal.ZonedDateTime(217175010123456789n, "+01:00");
const zdt2 = new Temporal.ZonedDateTime(1572342398271986102n, "+01:00");
// casts first argument
assert.sameValue(Temporal.ZonedDateTime.compare({
year: 1976,
month: 11,
day: 18,
hour: 15,
timeZone: "+01:00"
}, zdt2), -1);
assert.sameValue(Temporal.ZonedDateTime.compare("1976-11-18T15:23:30.123456789+01:00[+01:00]", zdt2), -1);
// casts second argument
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, {
year: 2019,
month: 10,
day: 29,
hour: 10,
timeZone: "+01:00"
}), -1);
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, "2019-10-29T10:46:38.271986102+01:00[+01:00]"), -1);

View File

@ -0,0 +1,19 @@
// 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: Compares exact time, not clock time.
features: [Temporal]
---*/
/*
const clockBefore = Temporal.ZonedDateTime.from("1999-12-31T23:30-08:00[-08:00]");
const clockAfter = Temporal.ZonedDateTime.from("2000-01-01T01:30-04:00[-04:00]");
*/
const clockBefore = new Temporal.ZonedDateTime(946711800000000000n, "-08:00");
const clockAfter = new Temporal.ZonedDateTime(946704600000000000n, "-04:00");
assert.sameValue(Temporal.ZonedDateTime.compare(clockBefore, clockAfter), 1);
assert.sameValue(Temporal.PlainDateTime.compare(clockBefore.toPlainDateTime(), clockAfter.toPlainDateTime()), -1);

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.compare
description: Disregards time zone IDs if exact times are equal.
features: [Temporal]
---*/
/*
const zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
*/
const zdt1 = new Temporal.ZonedDateTime(217175010123456789n, "+01:00");
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withTimeZone("+05:30")), 0);

View File

@ -1,43 +1,18 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved. // Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-temporal-zoneddatetime-objects esid: sec-temporal.zoneddatetime.compare
description: Temporal.ZonedDateTime.compare() description: Object must contain at least the required properties.
features: [Temporal] features: [Temporal]
---*/ ---*/
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]"); /*
var zdt2 = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102+01:00[+01:00]"); const zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
const zdt2 = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102+01:00[+01:00]");
// equal */
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1), 0) const zdt1 = new Temporal.ZonedDateTime(217175010123456789n, "+01:00");
const zdt2 = new Temporal.ZonedDateTime(1572342398271986102n, "+01:00");
// smaller/larger
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt2), -1)
// larger/smaller
assert.sameValue(Temporal.ZonedDateTime.compare(zdt2, zdt1), 1)
// casts first argument
assert.sameValue(Temporal.ZonedDateTime.compare({
year: 1976,
month: 11,
day: 18,
hour: 15,
timeZone: "+01:00"
}, zdt2), -1);
assert.sameValue(Temporal.ZonedDateTime.compare("1976-11-18T15:23:30.123456789+01:00[+01:00]", zdt2), -1);
// casts second argument
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, {
year: 2019,
month: 10,
day: 29,
hour: 10,
timeZone: "+01:00"
}), -1);
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, "2019-10-29T10:46:38.271986102+01:00[+01:00]"), -1);
// object must contain at least the required properties // object must contain at least the required properties
assert.sameValue(Temporal.ZonedDateTime.compare({ assert.sameValue(Temporal.ZonedDateTime.compare({
@ -106,12 +81,3 @@ assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(zdt1, {
hours: 10, hours: 10,
timeZone: "+01:00" timeZone: "+01:00"
})); }));
// disregards time zone IDs if exact times are equal
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withTimeZone("+05:30")), 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]");
assert.sameValue(Temporal.ZonedDateTime.compare(clockBefore, clockAfter), 1);
assert.sameValue(Temporal.PlainDateTime.compare(clockBefore.toPlainDateTime(), clockAfter.toPlainDateTime()), -1);