Temporal: Port staging tests that use next/previousTransition

See: tc39/proposal-temporal#2826
This commit is contained in:
Philip Chimento 2024-05-08 16:40:01 -07:00 committed by Ms2ger
parent 71877cde79
commit c22fbc7b45
10 changed files with 68 additions and 94 deletions

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.gettimezonetransition
description: An offset time zone has no transitions.
features: [Temporal]
---*/
const zdt = new Temporal.ZonedDateTime(0n, "-10:00");
assert.sameValue(zdt.getTimeZoneTransition("next"), null, "An offset time zone has no next transition");
assert.sameValue(zdt.getTimeZoneTransition("previous"), null, "An offset time zone has no previous transition");

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.gettimezonetransition
description: The UTC time zone has no transitions.
features: [Temporal]
---*/
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
assert.sameValue(zdt.getTimeZoneTransition("next"), null, "The UTC time zone has no next transition");
assert.sameValue(zdt.getTimeZoneTransition("previous"), null, "The UTC time zone has no previous transition");

View File

@ -0,0 +1,24 @@
// 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.gettimezonetransition
description: Next and previous transition in a named time zone has the correct return type
features: [Temporal]
---*/
let zdt = new Temporal.ZonedDateTime(0n, "America/Los_Angeles");
for (let count = 0; count < 4; count++) {
const transition = zdt.getTimeZoneTransition("next");
assert(transition instanceof Temporal.ZonedDateTime, "getTimeZoneTransition(next) returns Temporal.ZonedDateTime");
assert(!transition.equals(zdt), "getTimeZoneTransition(next) does not return its input");
zdt = transition;
}
zdt = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "America/Los_Angeles");
for (let count = 0; count < 4; count++) {
const transition = zdt.getTimeZoneTransition("previous");
assert(transition instanceof Temporal.ZonedDateTime, "getTimeZoneTransition(previous) returns Temporal.ZonedDateTime");
assert(!transition.equals(zdt), "getTimeZoneTransition(previous) does not return its input");
zdt = transition;
}

View File

@ -0,0 +1,20 @@
// 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.gettimezonetransition
description: Smoke test specific values from time zone database
features: [Temporal]
---*/
const a1 = new Temporal.ZonedDateTime(1555448460_000_000_000n /* = 2019-04-16T21:01Z */, "America/New_York");
assert.sameValue(a1.getTimeZoneTransition("next").epochNanoseconds, 1572760800_000_000_000n /* = 2019-11-03T06:00:00Z */);
const a2 = new Temporal.ZonedDateTime(-5364662400_000_000_000n /* = 1800-01-01T00:00Z */, "America/New_York");
assert.sameValue(a2.getTimeZoneTransition("next").epochNanoseconds, -2717650800_000_000_000n /* = 1883-11-18T17:00:00Z */);
const a3 = new Temporal.ZonedDateTime(1591909260_000_000_000n /* = 2020-06-11T21:01Z */, "Europe/London");
assert.sameValue(a3.getTimeZoneTransition("previous").epochNanoseconds, 1585443600_000_000_000n /* = 2020-03-29T01:00:00Z */);
const a4 = new Temporal.ZonedDateTime(-3849984000_000_000_000n /* = 1848-01-01T00:00Z */, "Europe/London");
assert.sameValue(a4.getTimeZoneTransition("previous").epochNanoseconds, -3852662325_000_000_000n, /* = 1847-12-01T00:01:15Z */);

View File

@ -14,15 +14,3 @@ assert.sameValue(zone.id, `${ zone }`)
assert.sameValue(zone.getOffsetNanosecondsFor(inst), -8 * 3600000000000)
assert.sameValue(zone.getOffsetStringFor(inst), "-08:00")
assert(zone.getInstantFor(dtm) instanceof Temporal.Instant)
for (var i = 0, txn = inst; i < 4; i++) {
var transition = zone.getNextTransition(txn);
assert(transition instanceof Temporal.Instant);
assert(!transition.equals(txn));
txn = transition;
}
for (var i = 0, txn = inst; i < 4; i++) {
var transition = zone.getPreviousTransition(txn);
assert(transition instanceof Temporal.Instant);
assert(!transition.equals(txn));
txn = transition;
}

View File

@ -1,44 +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-timezone-objects
description: Tests that are impractical to do without a TZDB
features: [Temporal]
---*/
// getNextTransition()
var nyc = Temporal.TimeZone.from("America/New_York");
// should not have bug #510
var a1 = Temporal.Instant.from("2019-04-16T21:01Z");
var a2 = Temporal.Instant.from("1800-01-01T00:00Z");
assert.sameValue(nyc.getNextTransition(a1).toString(), "2019-11-03T06:00:00Z");
assert.sameValue(nyc.getNextTransition(a2).toString(), "1883-11-18T17:00:00Z");
// should not return the same as its input if the input is a transition point
var inst = Temporal.Instant.from("2019-01-01T00:00Z");
assert.sameValue(`${ nyc.getNextTransition(inst) }`, "2019-03-10T07:00:00Z");
assert.sameValue(`${ nyc.getNextTransition(nyc.getNextTransition(inst)) }`, "2019-11-03T06:00:00Z");
// casts argument
assert.sameValue(`${ nyc.getNextTransition("2019-04-16T21:01Z") }`, "2019-11-03T06:00:00Z");
// getPreviousTransition()
var london = Temporal.TimeZone.from("Europe/London");
// should return first and last transition
var a1 = Temporal.Instant.from("2020-06-11T21:01Z");
var a2 = Temporal.Instant.from("1848-01-01T00:00Z");
assert.sameValue(london.getPreviousTransition(a1).toString(), "2020-03-29T01:00:00Z");
assert.sameValue(london.getPreviousTransition(a2).toString(), "1847-12-01T00:01:15Z");
// should not return the same as its input if the input is a transition point
var inst = Temporal.Instant.from("2020-06-01T00:00Z");
assert.sameValue(`${ london.getPreviousTransition(inst) }`, "2020-03-29T01:00:00Z");
assert.sameValue(`${ london.getPreviousTransition(london.getPreviousTransition(inst)) }`, "2019-10-27T01:00:00Z");
// casts argument
assert.sameValue(`${ london.getPreviousTransition("2020-06-11T21:01Z") }`, "2020-03-29T01:00:00Z");

View File

@ -1,17 +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-timezone-objects
description: Temporal.TimeZone.prototype.getNextTransition() works as expected
features: [Temporal]
---*/
var noTransitionTZ = Temporal.TimeZone.from("Etc/GMT+10");
// should work for timezones with no scheduled transitions in the near future
var start = Temporal.Instant.from("1945-10-15T13:00:00Z");
assert.sameValue(noTransitionTZ.getNextTransition(start), null);
// accepts string as argument
assert.sameValue(noTransitionTZ.getNextTransition("2019-04-16T21:01Z"), null);

View File

@ -1,17 +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-timezone-objects
description: Temporal.TimeZone.prototype.getPreviousTransition() works
features: [Temporal]
---*/
var utc = Temporal.TimeZone.from("UTC");
// no transitions without a TZDB
var instant = Temporal.Instant.from("2020-06-11T21:01Z");
assert.sameValue(utc.getPreviousTransition(instant), null);
// accepts string as argument
assert.sameValue(utc.getPreviousTransition("2020-06-11T21:01Z"), null);

View File

@ -14,8 +14,6 @@ assert.sameValue(zone.id, `${ zone }`)
assert.sameValue(zone.getOffsetNanosecondsFor(inst), 3600000000000)
assert(zone.getPlainDateTimeFor(inst) instanceof Temporal.PlainDateTime)
assert(zone.getInstantFor(dtm) instanceof Temporal.Instant)
assert.sameValue(zone.getNextTransition(inst), null)
assert.sameValue(zone.getPreviousTransition(inst), null)
// wraps around to the next day
assert.sameValue(`${ zone.getPlainDateTimeFor(Temporal.Instant.from("2020-02-06T23:59Z")) }`, "2020-02-07T00:59:00")

View File

@ -14,5 +14,3 @@ assert.sameValue(zone.id, `${ zone }`)
assert.sameValue(zone.getOffsetNanosecondsFor(inst), 0)
assert(zone.getPlainDateTimeFor(inst) instanceof Temporal.PlainDateTime)
assert(zone.getInstantFor(dtm) instanceof Temporal.Instant)
assert.sameValue(zone.getNextTransition(inst), null)
assert.sameValue(zone.getPreviousTransition(inst), null)