mirror of https://github.com/tc39/test262.git
Temporal: Move tests for getNext/PreviousTransition into ZonedDateTime
See: tc39/proposal-temporal#2826
This commit is contained in:
parent
9ff6ac3368
commit
71877cde79
|
@ -1,24 +0,0 @@
|
|||
// 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.timezone.prototype.getnexttransition
|
||||
description: Throw a TypeError if the receiver is invalid
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const getNextTransition = Temporal.TimeZone.prototype.getNextTransition;
|
||||
|
||||
assert.sameValue(typeof getNextTransition, "function");
|
||||
|
||||
const args = [new Temporal.Instant(0n)];
|
||||
|
||||
assert.throws(TypeError, () => getNextTransition.apply(undefined, args), "undefined");
|
||||
assert.throws(TypeError, () => getNextTransition.apply(null, args), "null");
|
||||
assert.throws(TypeError, () => getNextTransition.apply(true, args), "true");
|
||||
assert.throws(TypeError, () => getNextTransition.apply("", args), "empty string");
|
||||
assert.throws(TypeError, () => getNextTransition.apply(Symbol(), args), "symbol");
|
||||
assert.throws(TypeError, () => getNextTransition.apply(1, args), "1");
|
||||
assert.throws(TypeError, () => getNextTransition.apply({}, args), "plain object");
|
||||
assert.throws(TypeError, () => getNextTransition.apply(Temporal.TimeZone, args), "Temporal.TimeZone");
|
||||
assert.throws(TypeError, () => getNextTransition.apply(Temporal.TimeZone.prototype, args), "Temporal.TimeZone.prototype");
|
|
@ -1,33 +0,0 @@
|
|||
// 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.timezone.prototype.getnexttransition
|
||||
description: >
|
||||
Tests that Temporal.TimeZone.prototype.getNextTransition
|
||||
meets the requirements for built-in objects defined by the
|
||||
introduction of chapter 17 of the ECMAScript Language Specification.
|
||||
info: |
|
||||
Built-in functions that are not constructors do not have a "prototype" property unless
|
||||
otherwise specified in the description of a particular function.
|
||||
|
||||
Unless specified otherwise, a built-in object that is callable as a function is a built-in
|
||||
function object with the characteristics described in 10.3. Unless specified otherwise, the
|
||||
[[Extensible]] internal slot of a built-in object initially has the value true.
|
||||
|
||||
Unless otherwise specified every built-in function and every built-in constructor has the
|
||||
Function prototype object [...] as the value of its [[Prototype]] internal slot.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Object.isExtensible(Temporal.TimeZone.prototype.getNextTransition),
|
||||
true, "Built-in objects must be extensible.");
|
||||
|
||||
assert.sameValue(Object.prototype.toString.call(Temporal.TimeZone.prototype.getNextTransition),
|
||||
"[object Function]", "Object.prototype.toString");
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(Temporal.TimeZone.prototype.getNextTransition),
|
||||
Function.prototype, "prototype");
|
||||
|
||||
assert.sameValue(Temporal.TimeZone.prototype.getNextTransition.hasOwnProperty("prototype"),
|
||||
false, "prototype property");
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getnexttransition
|
||||
description: Temporal.TimeZone.prototype.getNextTransition.length is 1
|
||||
info: |
|
||||
Every built-in function object, including constructors, has a "length" property whose value is
|
||||
an integer. Unless otherwise specified, this value is equal to the largest number of named
|
||||
arguments shown in the subclause headings for the function description. Optional parameters
|
||||
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
|
||||
«...name») are not included in the default argument count.
|
||||
|
||||
Unless otherwise specified, the "length" property of a built-in function object has the
|
||||
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
verifyProperty(Temporal.TimeZone.prototype.getNextTransition, "length", {
|
||||
value: 1,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
|
@ -1,23 +0,0 @@
|
|||
// 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.timezone.prototype.getnexttransition
|
||||
description: Temporal.TimeZone.prototype.getNextTransition.name is "getNextTransition".
|
||||
info: |
|
||||
Every built-in function object, including constructors, that is not identified as an anonymous
|
||||
function has a "name" property whose value is a String. Unless otherwise specified, this value
|
||||
is the name that is given to the function in this specification.
|
||||
|
||||
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
|
||||
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
verifyProperty(Temporal.TimeZone.prototype.getNextTransition, "name", {
|
||||
value: "getNextTransition",
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
|
@ -1,21 +0,0 @@
|
|||
// 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.timezone.prototype.getnexttransition
|
||||
description: >
|
||||
Temporal.TimeZone.prototype.getNextTransition does not implement [[Construct]], is not new-able
|
||||
info: |
|
||||
Built-in function objects that are not identified as constructors do not implement the
|
||||
[[Construct]] internal method unless otherwise specified in the description of a particular
|
||||
function.
|
||||
includes: [isConstructor.js]
|
||||
features: [Reflect.construct, Temporal]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
new Temporal.TimeZone.prototype.getNextTransition();
|
||||
}, "Calling as constructor");
|
||||
|
||||
assert.sameValue(isConstructor(Temporal.TimeZone.prototype.getNextTransition), false,
|
||||
"isConstructor(Temporal.TimeZone.prototype.getNextTransition)");
|
|
@ -1,21 +0,0 @@
|
|||
// 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.timezone.prototype.getnexttransition
|
||||
description: The "getNextTransition" property of Temporal.TimeZone.prototype
|
||||
includes: [propertyHelper.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof Temporal.TimeZone.prototype.getNextTransition,
|
||||
"function",
|
||||
"`typeof TimeZone.prototype.getNextTransition` is `function`"
|
||||
);
|
||||
|
||||
verifyProperty(Temporal.TimeZone.prototype, "getNextTransition", {
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
|
@ -1,24 +0,0 @@
|
|||
// 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.timezone.prototype.getprevioustransition
|
||||
description: Throw a TypeError if the receiver is invalid
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const getPreviousTransition = Temporal.TimeZone.prototype.getPreviousTransition;
|
||||
|
||||
assert.sameValue(typeof getPreviousTransition, "function");
|
||||
|
||||
const args = [new Temporal.Instant(0n)];
|
||||
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply(undefined, args), "undefined");
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply(null, args), "null");
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply(true, args), "true");
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply("", args), "empty string");
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply(Symbol(), args), "symbol");
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply(1, args), "1");
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply({}, args), "plain object");
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply(Temporal.TimeZone, args), "Temporal.TimeZone");
|
||||
assert.throws(TypeError, () => getPreviousTransition.apply(Temporal.TimeZone.prototype, args), "Temporal.TimeZone.prototype");
|
|
@ -1,21 +0,0 @@
|
|||
// 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.timezone.prototype.getprevioustransition
|
||||
description: The "getPreviousTransition" property of Temporal.TimeZone.prototype
|
||||
includes: [propertyHelper.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof Temporal.TimeZone.prototype.getPreviousTransition,
|
||||
"function",
|
||||
"`typeof TimeZone.prototype.getPreviousTransition` is `function`"
|
||||
);
|
||||
|
||||
verifyProperty(Temporal.TimeZone.prototype, "getPreviousTransition", {
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
24
test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/branding.js
vendored
Normal file
24
test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/branding.js
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
// 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.gettimezonetransition
|
||||
description: Throw a TypeError if the receiver is invalid
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const getTimeZoneTransition = Temporal.ZonedDateTime.prototype.getTimeZoneTransition;
|
||||
|
||||
assert.sameValue(typeof getTimeZoneTransition, "function");
|
||||
|
||||
const args = ["next"];
|
||||
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply(undefined, args), "undefined");
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply(null, args), "null");
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply(true, args), "true");
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply("", args), "empty string");
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply(Symbol(), args), "symbol");
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply(1, args), "1");
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply({}, args), "plain object");
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply(Temporal.ZonedDateTime, args), "Temporal.ZonedDateTime");
|
||||
assert.throws(TypeError, () => getTimeZoneTransition.apply(Temporal.ZonedDateTime.prototype, args), "Temporal.ZonedDateTime.prototype");
|
|
@ -2,9 +2,9 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getprevioustransition
|
||||
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
|
||||
description: >
|
||||
Tests that Temporal.TimeZone.prototype.getPreviousTransition
|
||||
Tests that Temporal.ZonedDateTime.prototype.getTimeZoneTransition
|
||||
meets the requirements for built-in objects defined by the
|
||||
introduction of chapter 17 of the ECMAScript Language Specification.
|
||||
info: |
|
||||
|
@ -20,14 +20,14 @@ info: |
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Object.isExtensible(Temporal.TimeZone.prototype.getPreviousTransition),
|
||||
assert.sameValue(Object.isExtensible(Temporal.ZonedDateTime.prototype.getTimeZoneTransition),
|
||||
true, "Built-in objects must be extensible.");
|
||||
|
||||
assert.sameValue(Object.prototype.toString.call(Temporal.TimeZone.prototype.getPreviousTransition),
|
||||
assert.sameValue(Object.prototype.toString.call(Temporal.ZonedDateTime.prototype.getTimeZoneTransition),
|
||||
"[object Function]", "Object.prototype.toString");
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(Temporal.TimeZone.prototype.getPreviousTransition),
|
||||
assert.sameValue(Object.getPrototypeOf(Temporal.ZonedDateTime.prototype.getTimeZoneTransition),
|
||||
Function.prototype, "prototype");
|
||||
|
||||
assert.sameValue(Temporal.TimeZone.prototype.getPreviousTransition.hasOwnProperty("prototype"),
|
||||
assert.sameValue(Temporal.ZonedDateTime.prototype.getTimeZoneTransition.hasOwnProperty("prototype"),
|
||||
false, "prototype property");
|
|
@ -2,8 +2,8 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getprevioustransition
|
||||
description: Temporal.TimeZone.prototype.getPreviousTransition.length is 1
|
||||
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
|
||||
description: Temporal.ZonedDateTime.prototype.getTimeZoneTransition.length is 0
|
||||
info: |
|
||||
Every built-in function object, including constructors, has a "length" property whose value is
|
||||
an integer. Unless otherwise specified, this value is equal to the largest number of named
|
||||
|
@ -17,7 +17,7 @@ includes: [propertyHelper.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
verifyProperty(Temporal.TimeZone.prototype.getPreviousTransition, "length", {
|
||||
verifyProperty(Temporal.ZonedDateTime.prototype.getTimeZoneTransition, "length", {
|
||||
value: 1,
|
||||
writable: false,
|
||||
enumerable: false,
|
|
@ -2,8 +2,8 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getprevioustransition
|
||||
description: Temporal.TimeZone.prototype.getPreviousTransition.name is "getPreviousTransition".
|
||||
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
|
||||
description: Temporal.ZonedDateTime.prototype.getTimeZoneTransition.name is "getTimeZoneTransition".
|
||||
info: |
|
||||
Every built-in function object, including constructors, that is not identified as an anonymous
|
||||
function has a "name" property whose value is a String. Unless otherwise specified, this value
|
||||
|
@ -15,8 +15,8 @@ includes: [propertyHelper.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
verifyProperty(Temporal.TimeZone.prototype.getPreviousTransition, "name", {
|
||||
value: "getPreviousTransition",
|
||||
verifyProperty(Temporal.ZonedDateTime.prototype.getTimeZoneTransition, "name", {
|
||||
value: "getTimeZoneTransition",
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
|
@ -2,9 +2,9 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getprevioustransition
|
||||
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
|
||||
description: >
|
||||
Temporal.TimeZone.prototype.getPreviousTransition does not implement [[Construct]], is not new-able
|
||||
Temporal.ZonedDateTime.prototype.getTimeZoneTransition does not implement [[Construct]], is not new-able
|
||||
info: |
|
||||
Built-in function objects that are not identified as constructors do not implement the
|
||||
[[Construct]] internal method unless otherwise specified in the description of a particular
|
||||
|
@ -14,8 +14,8 @@ features: [Reflect.construct, Temporal]
|
|||
---*/
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
new Temporal.TimeZone.prototype.getPreviousTransition();
|
||||
new Temporal.ZonedDateTime.prototype.getTimeZoneTransition();
|
||||
}, "Calling as constructor");
|
||||
|
||||
assert.sameValue(isConstructor(Temporal.TimeZone.prototype.getPreviousTransition), false,
|
||||
"isConstructor(Temporal.TimeZone.prototype.getPreviousTransition)");
|
||||
assert.sameValue(isConstructor(Temporal.ZonedDateTime.prototype.getTimeZoneTransition), false,
|
||||
"isConstructor(Temporal.ZonedDateTime.prototype.getTimeZoneTransition)");
|
21
test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/prop-desc.js
vendored
Normal file
21
test/built-ins/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/prop-desc.js
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
// 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.gettimezonetransition
|
||||
description: The "getTimeZoneTransition" property of Temporal.ZonedDateTime.prototype
|
||||
includes: [propertyHelper.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof Temporal.ZonedDateTime.prototype.getTimeZoneTransition,
|
||||
"function",
|
||||
"`typeof ZonedDateTime.prototype.getTimeZoneTransition` is `function`"
|
||||
);
|
||||
|
||||
verifyProperty(Temporal.ZonedDateTime.prototype, "getTimeZoneTransition", {
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
|
@ -1,55 +0,0 @@
|
|||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getnexttransition
|
||||
description: >
|
||||
Compute next transition when seconds resp. nanoseconds are subtracted from the last transition.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// From <https://github.com/eggert/tz/blob/main/europe>:
|
||||
//
|
||||
// # Zone NAME STDOFF RULES FORMAT [UNTIL]
|
||||
// Zone Europe/Paris 0:09:21 - LMT 1891 Mar 15 0:01
|
||||
// 0:09:21 - PMT 1911 Mar 11 0:01 # Paris MT
|
||||
|
||||
let tz = new Temporal.TimeZone("Europe/Paris");
|
||||
|
||||
let zdt = new Temporal.PlainDateTime(1800, 1, 1).toZonedDateTime(tz);
|
||||
assert.sameValue(zdt.toString(), "1800-01-01T00:00:00+00:09[Europe/Paris]");
|
||||
assert.sameValue(zdt.offsetNanoseconds, (9 * 60 + 21) * 1_000_000_000);
|
||||
|
||||
// Ensure the first transition was correctly computed.
|
||||
let first = tz.getNextTransition(zdt);
|
||||
assert.sameValue(first.toString(), "1911-03-10T23:50:39Z");
|
||||
assert.sameValue(new Temporal.ZonedDateTime(first.epochNanoseconds, tz).toString(),
|
||||
"1911-03-10T23:50:39+00:00[Europe/Paris]");
|
||||
|
||||
let next;
|
||||
|
||||
// Compute the next transition starting from the first transition minus 1s.
|
||||
let firstMinus1s = first.add({seconds: -1});
|
||||
assert.sameValue(firstMinus1s.toString(), "1911-03-10T23:50:38Z");
|
||||
assert.sameValue(new Temporal.ZonedDateTime(firstMinus1s.epochNanoseconds, tz).toString(),
|
||||
"1911-03-10T23:59:59+00:09[Europe/Paris]");
|
||||
assert.sameValue(new Temporal.ZonedDateTime(firstMinus1s.epochNanoseconds, tz).offsetNanoseconds,
|
||||
(9 * 60 + 21) * 1_000_000_000);
|
||||
|
||||
next = tz.getNextTransition(firstMinus1s);
|
||||
assert.sameValue(next.toString(), "1911-03-10T23:50:39Z");
|
||||
assert.sameValue(new Temporal.ZonedDateTime(next.epochNanoseconds, tz).toString(),
|
||||
"1911-03-10T23:50:39+00:00[Europe/Paris]");
|
||||
|
||||
// Compute the next transition starting from the first transition minus 1ns.
|
||||
let firstMinus1ns = first.add({nanoseconds: -1});
|
||||
assert.sameValue(firstMinus1ns.toString(), "1911-03-10T23:50:38.999999999Z");
|
||||
assert.sameValue(new Temporal.ZonedDateTime(firstMinus1ns.epochNanoseconds, tz).toString(),
|
||||
"1911-03-10T23:59:59.999999999+00:09[Europe/Paris]");
|
||||
assert.sameValue(new Temporal.ZonedDateTime(firstMinus1ns.epochNanoseconds, tz).offsetNanoseconds,
|
||||
(9 * 60 + 21) * 1_000_000_000);
|
||||
|
||||
next = tz.getNextTransition(firstMinus1ns);
|
||||
assert.sameValue(next.toString(), "1911-03-10T23:50:39Z");
|
||||
assert.sameValue(new Temporal.ZonedDateTime(next.epochNanoseconds, tz).toString(),
|
||||
"1911-03-10T23:50:39+00:00[Europe/Paris]");
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getnexttransition
|
||||
description: >
|
||||
Test transitions at the instant boundaries.
|
||||
features: [Temporal, Intl-enumeration]
|
||||
---*/
|
||||
|
||||
const min = new Temporal.Instant(-86_40000_00000_00000_00000n);
|
||||
const max = new Temporal.Instant(86_40000_00000_00000_00000n);
|
||||
|
||||
for (let id of Intl.supportedValuesOf("timeZone")) {
|
||||
let tz = new Temporal.TimeZone(id);
|
||||
|
||||
// If there's any next transition, it should be after |min|.
|
||||
let next = tz.getNextTransition(min);
|
||||
if (next) {
|
||||
assert(next.epochNanoseconds > min.epochNanoseconds);
|
||||
}
|
||||
|
||||
// There shouldn't be any next transition after |max|.
|
||||
next = tz.getNextTransition(max);
|
||||
assert.sameValue(next, null);
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getprevioustransition
|
||||
description: >
|
||||
Test previous transition when nanoseconds are subtracted resp. added to the DST transition.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let tz = new Temporal.TimeZone("Europe/Berlin");
|
||||
let p = Temporal.Instant.from("2021-03-28T01:00:00Z");
|
||||
|
||||
assert.sameValue(tz.getPreviousTransition(p.add({nanoseconds: -1})).toString(),
|
||||
"2020-10-25T01:00:00Z",
|
||||
"DST transition minus one nanosecond");
|
||||
|
||||
assert.sameValue(tz.getPreviousTransition(p).toString(),
|
||||
"2020-10-25T01:00:00Z",
|
||||
"DST transition");
|
||||
|
||||
assert.sameValue(tz.getPreviousTransition(p.add({nanoseconds: +1})).toString(),
|
||||
"2021-03-28T01:00:00Z",
|
||||
"DST transition plus one nanosecond");
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getprevioustransition
|
||||
description: >
|
||||
Test transitions at the instant boundaries.
|
||||
features: [Temporal, Intl-enumeration]
|
||||
---*/
|
||||
|
||||
const min = new Temporal.Instant(-86_40000_00000_00000_00000n);
|
||||
const max = new Temporal.Instant(86_40000_00000_00000_00000n);
|
||||
|
||||
for (let id of Intl.supportedValuesOf("timeZone")) {
|
||||
let tz = new Temporal.TimeZone(id);
|
||||
|
||||
// If there's any previous transition, it should be before |max|.
|
||||
let prev = tz.getPreviousTransition(max);
|
||||
if (prev) {
|
||||
assert(prev.epochNanoseconds < max.epochNanoseconds);
|
||||
}
|
||||
|
||||
// There shouldn't be any previous transition before |min|.
|
||||
prev = tz.getPreviousTransition(min);
|
||||
assert.sameValue(prev, null);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
|
||||
description: >
|
||||
Test previous transition when nanoseconds are subtracted resp. added to the DST transition.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const dt = Temporal.ZonedDateTime.from("2021-03-28T01:00:00Z[Europe/Berlin]");
|
||||
|
||||
assert.sameValue(dt.add({nanoseconds: -1}).getTimeZoneTransition("previous").toString(),
|
||||
"2020-10-25T02:00:00+01:00[Europe/Berlin]",
|
||||
"DST transition minus one nanosecond");
|
||||
|
||||
assert.sameValue(dt.getTimeZoneTransition("previous").toString(),
|
||||
"2020-10-25T02:00:00+01:00[Europe/Berlin]",
|
||||
"DST transition");
|
||||
|
||||
assert.sameValue(dt.add({nanoseconds: +1}).getTimeZoneTransition("previous").toString(),
|
||||
"2021-03-28T03:00:00+02:00[Europe/Berlin]",
|
||||
"DST transition plus one nanosecond");
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
|
||||
description: >
|
||||
Compute next transition when seconds resp. nanoseconds are subtracted from the last transition.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// From <https://github.com/eggert/tz/blob/main/europe>:
|
||||
//
|
||||
// # Zone NAME STDOFF RULES FORMAT [UNTIL]
|
||||
// Zone Europe/Paris 0:09:21 - LMT 1891 Mar 15 0:01
|
||||
// 0:09:21 - PMT 1911 Mar 11 0:01 # Paris MT
|
||||
|
||||
const zdt = new Temporal.PlainDateTime(1800, 1, 1).toZonedDateTime("Europe/Paris");
|
||||
assert.sameValue(zdt.toString(), "1800-01-01T00:00:00+00:09[Europe/Paris]");
|
||||
assert.sameValue(zdt.offsetNanoseconds, (9 * 60 + 21) * 1_000_000_000);
|
||||
|
||||
// Ensure the first transition was correctly computed.
|
||||
const first = zdt.getTimeZoneTransition("next");
|
||||
assert.sameValue(first.toString(), "1911-03-10T23:50:39+00:00[Europe/Paris]");
|
||||
|
||||
let next;
|
||||
|
||||
// Compute the next transition starting from the first transition minus 1s.
|
||||
const firstMinus1s = first.add({seconds: -1});
|
||||
assert.sameValue(firstMinus1s.toString(), "1911-03-10T23:59:59+00:09[Europe/Paris]");
|
||||
assert.sameValue(firstMinus1s.offsetNanoseconds, (9 * 60 + 21) * 1_000_000_000);
|
||||
|
||||
next = firstMinus1s.getTimeZoneTransition("next");
|
||||
assert.sameValue(next.toString(), "1911-03-10T23:50:39+00:00[Europe/Paris]");
|
||||
|
||||
// Compute the next transition starting from the first transition minus 1ns.
|
||||
const firstMinus1ns = first.add({nanoseconds: -1});
|
||||
assert.sameValue(firstMinus1ns.toString(), "1911-03-10T23:59:59.999999999+00:09[Europe/Paris]");
|
||||
assert.sameValue(firstMinus1ns.offsetNanoseconds, (9 * 60 + 21) * 1_000_000_000);
|
||||
|
||||
next = firstMinus1ns.getTimeZoneTransition("next");
|
||||
assert.sameValue(next.toString(), "1911-03-10T23:50:39+00:00[Europe/Paris]");
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
|
||||
description: >
|
||||
Test transitions at the instant boundaries.
|
||||
features: [Temporal, Intl-enumeration]
|
||||
---*/
|
||||
|
||||
for (let id of Intl.supportedValuesOf("timeZone")) {
|
||||
const min = new Temporal.ZonedDateTime(-86_40000_00000_00000_00000n, id);
|
||||
const max = new Temporal.ZonedDateTime(86_40000_00000_00000_00000n, id);
|
||||
|
||||
const next = min.getTimeZoneTransition("next");
|
||||
if (next) {
|
||||
assert(next.epochNanoseconds > min.epochNanoseconds,
|
||||
"If there's any next transition, it should be after |min|");
|
||||
}
|
||||
|
||||
const prev = max.getTimeZoneTransition("previous");
|
||||
if (prev) {
|
||||
assert(prev.epochNanoseconds < max.epochNanoseconds,
|
||||
"If there's any previous transition, it should be before |max|");
|
||||
}
|
||||
|
||||
assert.sameValue(max.getTimeZoneTransition("next"), null, "There shouldn't be any next transition after |max|");
|
||||
assert.sameValue(min.getTimeZoneTransition("previous"), null,
|
||||
"There shouldn't be any previous transition before |min|");
|
||||
}
|
Loading…
Reference in New Issue