From b6aeb3cdbc907fcf12c68aba8e9b156de83c3282 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 8 May 2024 16:40:01 -0700 Subject: [PATCH] Temporal: Port staging tests that use next/previousTransition See: tc39/proposal-temporal#2826 --- .../offset-timezone-no-transitions.js | 12 +++++ .../utc-no-transitions.js | 12 +++++ .../getTimeZoneTransition/result-type.js | 24 ++++++++++ .../specific-tzdb-values.js | 21 +++++++++ .../Temporal/old/timezone-america-la.js | 12 ----- .../Intl402/Temporal/old/tzdb-transitions.js | 44 ------------------- .../TimeZone/old/getNextTransition.js | 17 ------- .../TimeZone/old/getPreviousTransition.js | 17 ------- .../Temporal/TimeZone/old/timezone-offset.js | 2 - .../TimeZone/old/timezone-utc-offset.js | 2 - 10 files changed, 69 insertions(+), 94 deletions(-) create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/offset-timezone-no-transitions.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/utc-no-transitions.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/result-type.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/specific-tzdb-values.js delete mode 100644 test/staging/Intl402/Temporal/old/tzdb-transitions.js delete mode 100644 test/staging/Temporal/TimeZone/old/getNextTransition.js delete mode 100644 test/staging/Temporal/TimeZone/old/getPreviousTransition.js diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/offset-timezone-no-transitions.js b/test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/offset-timezone-no-transitions.js new file mode 100644 index 00000000000..b64f3ee5eee --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/offset-timezone-no-transitions.js @@ -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"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/utc-no-transitions.js b/test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/utc-no-transitions.js new file mode 100644 index 00000000000..fc6e849ed55 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/utc-no-transitions.js @@ -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"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/result-type.js b/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/result-type.js new file mode 100644 index 00000000000..c017a341b76 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/result-type.js @@ -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; +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/specific-tzdb-values.js b/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/specific-tzdb-values.js new file mode 100644 index 00000000000..dfd078d35e7 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/specific-tzdb-values.js @@ -0,0 +1,21 @@ +// 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 +includes: [temporalHelpers.js] +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 */); diff --git a/test/staging/Intl402/Temporal/old/timezone-america-la.js b/test/staging/Intl402/Temporal/old/timezone-america-la.js index 5ed6a2b3adf..2dec9fba44a 100644 --- a/test/staging/Intl402/Temporal/old/timezone-america-la.js +++ b/test/staging/Intl402/Temporal/old/timezone-america-la.js @@ -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; -} diff --git a/test/staging/Intl402/Temporal/old/tzdb-transitions.js b/test/staging/Intl402/Temporal/old/tzdb-transitions.js deleted file mode 100644 index 441de4e29ab..00000000000 --- a/test/staging/Intl402/Temporal/old/tzdb-transitions.js +++ /dev/null @@ -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"); diff --git a/test/staging/Temporal/TimeZone/old/getNextTransition.js b/test/staging/Temporal/TimeZone/old/getNextTransition.js deleted file mode 100644 index 6aef8533675..00000000000 --- a/test/staging/Temporal/TimeZone/old/getNextTransition.js +++ /dev/null @@ -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); diff --git a/test/staging/Temporal/TimeZone/old/getPreviousTransition.js b/test/staging/Temporal/TimeZone/old/getPreviousTransition.js deleted file mode 100644 index 371f7fc1f58..00000000000 --- a/test/staging/Temporal/TimeZone/old/getPreviousTransition.js +++ /dev/null @@ -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); diff --git a/test/staging/Temporal/TimeZone/old/timezone-offset.js b/test/staging/Temporal/TimeZone/old/timezone-offset.js index 21b0c0798c9..ed76f675880 100644 --- a/test/staging/Temporal/TimeZone/old/timezone-offset.js +++ b/test/staging/Temporal/TimeZone/old/timezone-offset.js @@ -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") diff --git a/test/staging/Temporal/TimeZone/old/timezone-utc-offset.js b/test/staging/Temporal/TimeZone/old/timezone-utc-offset.js index b6421c7910e..c694643e121 100644 --- a/test/staging/Temporal/TimeZone/old/timezone-utc-offset.js +++ b/test/staging/Temporal/TimeZone/old/timezone-utc-offset.js @@ -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)