mirror of https://github.com/tc39/test262.git
Temporal: Remove calendars and time zones from tests in staging
As much as possible, remove non-ISO calendars and IANA time zones from the Temporal tests in the staging folder. In most cases, the non-ISO calendar can be replaced with the ISO calendar. In other cases, create a custom calendar object with the appropriate return value from toString(), and any other methods needed for that particular test. For time zones, in most cases the time zone can be replaced with UTC or a constant offset time zone. Sometimes a custom time zone object with the appropriate toString() is sufficient. Move timezone-america-la.js to staging/Intl402/Temporal/ since its whole point is to test an IANA time zone. Create a new tzdb-transitions.js in staging/Intl402/Temporal to test behaviour of Temporal.TimeZone's getPreviousTransition and getNextTransition for IANA time zones, since UTC and constant offset time zones always return null for these methods. There are still some cases where specific DST behaviour is tested. These will be addressed in following commits. See: #3649
This commit is contained in:
parent
58b7a23582
commit
42074e7fe7
|
@ -0,0 +1,44 @@
|
|||
// 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");
|
|
@ -15,7 +15,7 @@ var relativeTo = Temporal.PlainDate.from("2017-01-01");
|
|||
assert.sameValue(`${ oneDay.add(hours24, { relativeTo }) }`, "P2D");
|
||||
|
||||
// relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change
|
||||
var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[America/Montevideo]");
|
||||
var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[+04:30]");
|
||||
assert.sameValue(`${ oneDay.add(hours24, { relativeTo }) }`, "P2D");
|
||||
var skippedHourDay = Temporal.ZonedDateTime.from("2019-03-10T00:00[America/Vancouver]");
|
||||
var repeatedHourDay = Temporal.ZonedDateTime.from("2019-11-03T00:00[America/Vancouver]");
|
||||
|
@ -112,10 +112,10 @@ assert.sameValue(`${ oneDay.add(hours24, {
|
|||
}) }`, "P2D");
|
||||
|
||||
// throws on wrong offset for ZonedDateTime relativeTo string
|
||||
assert.throws(RangeError, () => oneDay.add(hours24, { relativeTo: "1971-01-01T00:00+02:00[Africa/Monrovia]" }));
|
||||
assert.throws(RangeError, () => oneDay.add(hours24, { relativeTo: "1971-01-01T00:00+02:00[-00:44:30]" }));
|
||||
|
||||
// does not throw on HH:MM rounded offset for ZonedDateTime relativeTo string
|
||||
assert.sameValue(`${ oneDay.add(hours24, { relativeTo: "1971-01-01T00:00-00:45[Africa/Monrovia]" }) }`, "P2D");
|
||||
assert.sameValue(`${ oneDay.add(hours24, { relativeTo: "1971-01-01T00:00-00:45[-00:44:30]" }) }`, "P2D");
|
||||
|
||||
// throws on HH:MM rounded offset for ZonedDateTime relativeTo property bag
|
||||
assert.throws(RangeError, () => oneDay.add(hours24, {
|
||||
|
@ -124,7 +124,7 @@ assert.throws(RangeError, () => oneDay.add(hours24, {
|
|||
month: 1,
|
||||
day: 1,
|
||||
offset: "-00:45",
|
||||
timeZone: "Africa/Monrovia"
|
||||
timeZone: "-00:44:30"
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ assert.sameValue(`${ hours25.round({
|
|||
}) }`, "P1DT1H");
|
||||
|
||||
// days are 24 hours if relativeTo is ZonedDateTime, and duration encompasses no DST change
|
||||
var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[America/Montevideo]");
|
||||
var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[+04:30]");
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
|
@ -215,13 +215,13 @@ assert.sameValue(`${ hours25.round({
|
|||
// throws on wrong offset for ZonedDateTime relativeTo string
|
||||
assert.throws(RangeError, () => d.round({
|
||||
smallestUnit: "seconds",
|
||||
relativeTo: "1971-01-01T00:00+02:00[Africa/Monrovia]"
|
||||
relativeTo: "1971-01-01T00:00+02:00[-00:44:30]"
|
||||
}));
|
||||
|
||||
// does not throw on HH:MM rounded offset for ZonedDateTime relativeTo string
|
||||
assert.sameValue(`${ d.round({
|
||||
smallestUnit: "seconds",
|
||||
relativeTo: "1971-01-01T00:00-00:45[Africa/Monrovia]"
|
||||
relativeTo: "1971-01-01T00:00-00:45[-00:44:30]"
|
||||
}) }`, "P5Y5M5W5DT5H5M5S");
|
||||
|
||||
// throws on HH:MM rounded offset for ZonedDateTime relativeTo property bag
|
||||
|
@ -232,7 +232,7 @@ assert.throws(RangeError, () => d.round({
|
|||
month: 1,
|
||||
day: 1,
|
||||
offset: "-00:45",
|
||||
timeZone: "Africa/Monrovia"
|
||||
timeZone: "-00:44:30"
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ var relativeTo = Temporal.PlainDate.from("2017-01-01");
|
|||
assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo }) }`, "PT0S");
|
||||
|
||||
// relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change
|
||||
var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[America/Montevideo]");
|
||||
var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[+04:30]");
|
||||
assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo }) }`, "PT0S");
|
||||
var skippedHourDay = Temporal.ZonedDateTime.from("2019-03-10T00:00[America/Vancouver]");
|
||||
var repeatedHourDay = Temporal.ZonedDateTime.from("2019-11-03T00:00[America/Vancouver]");
|
||||
|
@ -86,10 +86,10 @@ assert.sameValue(`${ oneDay.subtract(hours24, {
|
|||
}) }`, "PT0S");
|
||||
|
||||
// throws on wrong offset for ZonedDateTime relativeTo string
|
||||
assert.throws(RangeError, () => oneDay.subtract(hours24, { relativeTo: "1971-01-01T00:00+02:00[Africa/Monrovia]" }));
|
||||
assert.throws(RangeError, () => oneDay.subtract(hours24, { relativeTo: "1971-01-01T00:00+02:00[-00:44:30]" }));
|
||||
|
||||
// does not throw on HH:MM rounded offset for ZonedDateTime relativeTo string
|
||||
assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo: "1971-01-01T00:00-00:45[Africa/Monrovia]" }) }`, "PT0S");
|
||||
assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo: "1971-01-01T00:00-00:45[-00:44:30]" }) }`, "PT0S");
|
||||
|
||||
// throws on HH:MM rounded offset for ZonedDateTime relativeTo property bag
|
||||
assert.throws(RangeError, () => oneDay.subtract(hours24, {
|
||||
|
@ -98,7 +98,7 @@ assert.throws(RangeError, () => oneDay.subtract(hours24, {
|
|||
month: 1,
|
||||
day: 1,
|
||||
offset: "-00:45",
|
||||
timeZone: "Africa/Monrovia"
|
||||
timeZone: "-00:44:30"
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
@ -60,14 +60,14 @@ assert.sameValue(s, 0.002031);
|
|||
// throws on wrong offset for ZonedDateTime relativeTo string
|
||||
assert.throws(RangeError, () => d.total({
|
||||
unit: "months",
|
||||
relativeTo: "1971-01-01T00:00+02:00[Africa/Monrovia]"
|
||||
relativeTo: "1971-01-01T00:00+02:00[-00:44:30]"
|
||||
}));
|
||||
|
||||
// does not throw on HH:MM rounded offset for ZonedDateTime relativeTo string
|
||||
var oneMonth = Temporal.Duration.from({ months: 1 });
|
||||
assert.sameValue(oneMonth.total({
|
||||
unit: "months",
|
||||
relativeTo: "1971-01-01T00:00-00:45[Africa/Monrovia]"
|
||||
relativeTo: "1971-01-01T00:00-00:45[-00:44:30]"
|
||||
}), 1);
|
||||
|
||||
// throws on HH:MM rounded offset for ZonedDateTime relativeTo property bag
|
||||
|
@ -78,7 +78,7 @@ assert.throws(RangeError, () => d.total({
|
|||
month: 1,
|
||||
day: 1,
|
||||
offset: "-00:45",
|
||||
timeZone: "Africa/Monrovia"
|
||||
timeZone: "-00:44:30"
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -251,7 +251,7 @@ assert.sameValue(oneDay.total({
|
|||
}), 24);
|
||||
|
||||
// relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change
|
||||
var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[America/Montevideo]");
|
||||
var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[+04:30]");
|
||||
assert.sameValue(oneDay.total({
|
||||
unit: "hours",
|
||||
relativeTo
|
||||
|
|
|
@ -13,22 +13,24 @@ var inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z");
|
|||
assert.throws(TypeError, () => inst.toZonedDateTime());
|
||||
|
||||
// throws with a string parameter
|
||||
assert.throws(TypeError, () => inst.toZonedDateTime("Asia/Singapore"));
|
||||
assert.throws(TypeError, () => inst.toZonedDateTime("UTC"));
|
||||
|
||||
var fakeGregorian = { toString() { return "gregory"; }};
|
||||
|
||||
// time zone parameter UTC
|
||||
var timeZone = Temporal.TimeZone.from("UTC");
|
||||
var zdt = inst.toZonedDateTime({
|
||||
timeZone,
|
||||
calendar: "gregory"
|
||||
calendar: fakeGregorian,
|
||||
});
|
||||
assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds);
|
||||
assert.sameValue(`${ zdt }`, "1976-11-18T14:23:30.123456789+00:00[UTC][u-ca=gregory]");
|
||||
|
||||
// time zone parameter non-UTC
|
||||
var timeZone = Temporal.TimeZone.from("America/New_York");
|
||||
var timeZone = Temporal.TimeZone.from("-05:00");
|
||||
var zdt = inst.toZonedDateTime({
|
||||
timeZone,
|
||||
calendar: "gregory"
|
||||
calendar: fakeGregorian,
|
||||
});
|
||||
assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds);
|
||||
assert.sameValue(`${ zdt }`, "1976-11-18T09:23:30.123456789-05:00[America/New_York][u-ca=gregory]");
|
||||
assert.sameValue(`${ zdt }`, "1976-11-18T09:23:30.123456789-05:00[-05:00][u-ca=gregory]");
|
||||
|
|
|
@ -19,7 +19,7 @@ assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds);
|
|||
assert.sameValue(`${ zdt }`, "1976-11-18T14:23:30.123456789+00:00[UTC]");
|
||||
|
||||
// time zone parameter non-UTC
|
||||
var tz = Temporal.TimeZone.from("America/New_York");
|
||||
var tz = Temporal.TimeZone.from("-05:00");
|
||||
var zdt = inst.toZonedDateTimeISO(tz);
|
||||
assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds);
|
||||
assert.sameValue(`${ zdt }`, "1976-11-18T09:23:30.123456789-05:00[America/New_York]");
|
||||
assert.sameValue(`${ zdt }`, "1976-11-18T09:23:30.123456789-05:00[-05:00]");
|
||||
|
|
|
@ -17,16 +17,16 @@ function generateTest(dateTimeString, zoneString, expectedName) {
|
|||
test(`${ dateTimeString }:30.123456789${ zoneString }`, expectedName);
|
||||
}
|
||||
[
|
||||
"+01:00",
|
||||
"+01",
|
||||
"+0100",
|
||||
"+01:00:00",
|
||||
"+010000",
|
||||
"+01:00:00.000000000",
|
||||
"+010000.0"
|
||||
"+00:00",
|
||||
"+00",
|
||||
"+0000",
|
||||
"+00:00:00",
|
||||
"+000000",
|
||||
"+00:00:00.000000000",
|
||||
"+000000.0"
|
||||
].forEach(zoneString => {
|
||||
generateTest("1976-11-18T15:23", `${ zoneString }[Europe/Vienna]`, "Europe/Vienna");
|
||||
generateTest("1976-11-18T15:23", `+01:00[${ zoneString }]`, "+01:00");
|
||||
generateTest("1976-11-18T15:23", `${ zoneString }[UTC]`, "UTC");
|
||||
generateTest("1976-11-18T15:23", `+00:00[${ zoneString }]`, "+00:00");
|
||||
});
|
||||
[
|
||||
"-04:00",
|
||||
|
@ -53,7 +53,7 @@ function generateTest(dateTimeString, zoneString, expectedName) {
|
|||
generateTest("1976-11-18T15:23", "z", "UTC");
|
||||
test("1976-11-18T15:23:30,1234Z", "UTC");
|
||||
test("1976-11-18T15:23-04:00:00,000000000", "-04:00");
|
||||
test("1976-11-18T15:23+010000,0[Europe/Vienna]", "Europe/Vienna");
|
||||
test("1976-11-18T15:23+000000,0[UTC]", "UTC");
|
||||
[
|
||||
"\u221204:00",
|
||||
"\u221204",
|
||||
|
@ -68,11 +68,11 @@ test("1976-11-18T15:23+010000,0[Europe/Vienna]", "Europe/Vienna");
|
|||
"1976-11-18T15"
|
||||
].forEach(dateTimeString => {
|
||||
[
|
||||
"+01:00",
|
||||
"+01",
|
||||
"+0100",
|
||||
"+00:00",
|
||||
"+00",
|
||||
"+0000",
|
||||
""
|
||||
].forEach(zoneString => test(`${ dateTimeString }${ zoneString }[Europe/Vienna]`, "Europe/Vienna"));
|
||||
].forEach(zoneString => test(`${ dateTimeString }${ zoneString }[UTC]`, "UTC"));
|
||||
[
|
||||
"-04:00",
|
||||
"-04",
|
||||
|
@ -97,5 +97,5 @@ test("-03:00:00", "-03:00");
|
|||
test("-03:00:00.000000000", "-03:00");
|
||||
test("1976-11-18T15:23:30.123456789Z[u-ca=iso8601]", "UTC");
|
||||
test("1976-11-18T15:23:30.123456789-04:00[u-ca=iso8601]", "-04:00");
|
||||
test("1976-11-18T15:23:30.123456789[Europe/Vienna][u-ca=iso8601]", "Europe/Vienna");
|
||||
test("1976-11-18T15:23:30.123456789+01:00[Europe/Vienna][u-ca=iso8601]", "Europe/Vienna");
|
||||
test("1976-11-18T15:23:30.123456789[UTC][u-ca=iso8601]", "UTC");
|
||||
test("1976-11-18T15:23:30.123456789+00:00[UTC][u-ca=iso8601]", "UTC");
|
||||
|
|
|
@ -10,7 +10,7 @@ features: [Temporal]
|
|||
|
||||
// recent date
|
||||
var dt = Temporal.PlainDateTime.from("2019-10-29T10:46:38.271986102");
|
||||
var tz = Temporal.TimeZone.from("Europe/Amsterdam");
|
||||
var tz = Temporal.TimeZone.from("+01:00");
|
||||
assert.sameValue(`${ tz.getInstantFor(dt) }`, "2019-10-29T09:46:38.271986102Z");
|
||||
|
||||
// year ≤ 99
|
||||
|
@ -31,7 +31,7 @@ assert.sameValue(`${ tz.getInstantFor(dt) }`, "-001000-10-29T04:46:38.271986102Z
|
|||
|
||||
// year 0 leap day
|
||||
var dt = Temporal.PlainDateTime.from("0000-02-29T00:00");
|
||||
var tz = Temporal.TimeZone.from("Europe/London");
|
||||
var tz = Temporal.TimeZone.from("-00:01:15");
|
||||
assert.sameValue(`${ tz.getInstantFor(dt) }`, "0000-02-29T00:01:15Z");
|
||||
dt = Temporal.PlainDateTime.from("+000000-02-29T00:00");
|
||||
assert.sameValue(`${ tz.getInstantFor(dt) }`, "0000-02-29T00:01:15Z");
|
||||
|
@ -40,11 +40,11 @@ assert.sameValue(`${ tz.getInstantFor(dt) }`, "0000-02-29T00:01:15Z");
|
|||
var max = Temporal.PlainDateTime.from("+275760-09-13T23:59:59.999999999");
|
||||
var offsetTz = Temporal.TimeZone.from("-01:00");
|
||||
assert.throws(RangeError, () => offsetTz.getInstantFor(max));
|
||||
var namedTz = Temporal.TimeZone.from("America/Godthab");
|
||||
var namedTz = Temporal.TimeZone.from("Etc/GMT+12");
|
||||
assert.throws(RangeError, () => namedTz.getInstantFor(max));
|
||||
|
||||
// casts argument
|
||||
var tz = Temporal.TimeZone.from("Europe/Amsterdam");
|
||||
var tz = Temporal.TimeZone.from("+01:00");
|
||||
assert.sameValue(`${ tz.getInstantFor("2019-10-29T10:46:38.271986102") }`, "2019-10-29T09:46:38.271986102Z");
|
||||
assert.sameValue(`${ tz.getInstantFor({
|
||||
year: 2019,
|
||||
|
|
|
@ -7,24 +7,11 @@ description: Temporal.TimeZone.prototype.getNextTransition() works as expected
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var nyc = Temporal.TimeZone.from("America/New_York");
|
||||
var noTransitionTZ = Temporal.TimeZone.from("Etc/GMT+10");
|
||||
|
||||
// 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");
|
||||
|
||||
// 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);
|
||||
|
||||
// casts argument
|
||||
assert.sameValue(`${ nyc.getNextTransition("2019-04-16T21:01Z") }`, "2019-11-03T06:00:00Z");
|
||||
|
||||
// accepts string as argument
|
||||
assert.sameValue(noTransitionTZ.getNextTransition("2019-04-16T21:01Z"), null);
|
||||
|
|
|
@ -40,5 +40,5 @@ assert.deepEqual(tz.getPossibleInstantsFor({
|
|||
assert.deepEqual(tz.getPossibleInstantsFor("2019-02-16T23:45:30").map(a => `${ a }`), ["2019-02-16T20:15:30Z"]);
|
||||
|
||||
// object must contain at least the required properties
|
||||
var tz = Temporal.TimeZone.from("Europe/Amsterdam");
|
||||
var tz = Temporal.TimeZone.from("UTC");
|
||||
assert.throws(TypeError, () => tz.getPossibleInstantsFor({ year: 2019 }));
|
||||
|
|
|
@ -7,18 +7,11 @@ description: Temporal.TimeZone.prototype.getPreviousTransition() works
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var london = Temporal.TimeZone.from("Europe/London");
|
||||
var utc = Temporal.TimeZone.from("UTC");
|
||||
|
||||
// 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");
|
||||
// no transitions without a TZDB
|
||||
var instant = Temporal.Instant.from("2020-06-11T21:01Z");
|
||||
assert.sameValue(utc.getPreviousTransition(instant), null);
|
||||
|
||||
// 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");
|
||||
// accepts string as argument
|
||||
assert.sameValue(utc.getPreviousTransition("2020-06-11T21:01Z"), null);
|
||||
|
|
|
@ -114,7 +114,7 @@ assert.sameValue(typeof obj, "object")
|
|||
|
||||
// .id is not available in from()
|
||||
assert.throws(RangeError, () => Temporal.Calendar.from("decimal"));
|
||||
assert.throws(RangeError, () => Temporal.Calendar.from("2020-06-05T09:34-07:00[America/Vancouver][u-ca=decimal]"));
|
||||
assert.throws(RangeError, () => Temporal.Calendar.from("2020-06-05T09:34-00:00[UTC][u-ca=decimal]"));
|
||||
|
||||
// Temporal.PlainDate.from()
|
||||
assert.sameValue(`${ date }`, "2020-06-05[u-ca=decimal]")
|
||||
|
|
|
@ -82,7 +82,7 @@ assert.sameValue(obj.id, "two-based")
|
|||
|
||||
// .id is not available in from()
|
||||
assert.throws(RangeError, () => Temporal.Calendar.from("two-based"));
|
||||
assert.throws(RangeError, () => Temporal.Calendar.from("2020-06-05T09:34-07:00[America/Vancouver][u-ca=two-based]"));
|
||||
assert.throws(RangeError, () => Temporal.Calendar.from("2020-06-05T09:34-00:00[UTC][u-ca=two-based]"));
|
||||
|
||||
// Temporal.PlainDate.from()
|
||||
assert.sameValue(`${ date }`, "2020-04-05[u-ca=two-based]")
|
||||
|
|
|
@ -47,8 +47,9 @@ assert.throws(RangeError, () => Temporal.TimeZone.from("2020-05-26T16:02:46.2511
|
|||
assert.sameValue(obj.getOffsetStringFor(inst), "-00:00:01.111111111")
|
||||
|
||||
// converts to DateTime
|
||||
var fakeGregorian = { toString() { return "gregory"; }};
|
||||
assert.sameValue(`${ obj.getPlainDateTimeFor(inst) }`, "1969-12-31T23:59:58.888888889");
|
||||
assert.sameValue(`${ obj.getPlainDateTimeFor(inst, "gregory") }`, "1969-12-31T23:59:58.888888889[u-ca=gregory]");
|
||||
assert.sameValue(`${ obj.getPlainDateTimeFor(inst, fakeGregorian) }`, "1969-12-31T23:59:58.888888889[u-ca=gregory]");
|
||||
|
||||
// converts to Instant
|
||||
assert.sameValue(`${ obj.getInstantFor(dt) }`, "1976-11-18T15:23:31.2345679Z");
|
||||
|
@ -71,7 +72,7 @@ assert.sameValue(obj.getPreviousTransition(), null)
|
|||
|
||||
// works in Temporal.Now
|
||||
assert(Temporal.Now.plainDateTimeISO(obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateTime("gregory", obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateTime(fakeGregorian, obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateISO(obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainDate("gregory", obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainDate(fakeGregorian, obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainTimeISO(obj) instanceof Temporal.PlainTime);
|
||||
|
|
|
@ -32,8 +32,9 @@ var zdt = new Temporal.ZonedDateTime(0n, obj);
|
|||
assert.sameValue(zdt.toString(), "1970-01-01T00:00:00+00:00[Etc/Custom/UTC_Protocol]");
|
||||
|
||||
// works in Temporal.Now
|
||||
var fakeGregorian = { toString() { return "gregory"; }};
|
||||
assert(Temporal.Now.plainDateTimeISO(obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateTime("gregory", obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateTime(fakeGregorian, obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateISO(obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainDate("gregory", obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainDate(fakeGregorian, obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainTimeISO(obj) instanceof Temporal.PlainTime);
|
||||
|
|
|
@ -85,8 +85,9 @@ assert.throws(RangeError, () => Temporal.TimeZone.from("2020-05-26T16:02:46.2511
|
|||
assert.sameValue(obj.getOffsetStringFor(inst), "+00:00")
|
||||
|
||||
// converts to DateTime
|
||||
var fakeGregorian = { toString() { return "gregory"; }};
|
||||
assert.sameValue(`${ obj.getPlainDateTimeFor(inst) }`, "1970-01-01T00:00:00");
|
||||
assert.sameValue(`${ obj.getPlainDateTimeFor(inst, "gregory") }`, "1970-01-01T00:00:00[u-ca=gregory]");
|
||||
assert.sameValue(`${ obj.getPlainDateTimeFor(inst, fakeGregorian) }`, "1970-01-01T00:00:00[u-ca=gregory]");
|
||||
|
||||
// converts to Instant
|
||||
assert.sameValue(`${ obj.getInstantFor(dt) }`, "1976-11-18T15:23:30.123456789Z");
|
||||
|
@ -109,7 +110,7 @@ assert.sameValue(obj.getPreviousTransition(), null)
|
|||
|
||||
// works in Temporal.Now
|
||||
assert(Temporal.Now.plainDateTimeISO(obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateTime("gregory", obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateTime(fakeGregorian, obj) instanceof Temporal.PlainDateTime);
|
||||
assert(Temporal.Now.plainDateISO(obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainDate("gregory", obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainDate(fakeGregorian, obj) instanceof Temporal.PlainDate);
|
||||
assert(Temporal.Now.plainTimeISO(obj) instanceof Temporal.PlainTime);
|
||||
|
|
|
@ -36,15 +36,15 @@ assert.sameValue(`${ later }`, "1970-01-04T12:23:45.678902034+00:00[UTC]");
|
|||
|
||||
// casts argument
|
||||
assert.sameValue(`${ zdt.add("PT240H0.000000800S") }`, "1970-01-04T12:23:45.678902034+00:00[UTC]");
|
||||
var jan31 = Temporal.ZonedDateTime.from("2020-01-31T15:00-08:00[America/Vancouver]");
|
||||
var jan31 = Temporal.ZonedDateTime.from("2020-01-31T15:00-08:00[-08:00]");
|
||||
|
||||
// constrain when ambiguous result
|
||||
assert.sameValue(`${ jan31.add({ months: 1 }) }`, "2020-02-29T15:00:00-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ jan31.add({ months: 1 }, { overflow: "constrain" }) }`, "2020-02-29T15:00:00-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ jan31.add({ months: 1 }) }`, "2020-02-29T15:00:00-08:00[-08:00]");
|
||||
assert.sameValue(`${ jan31.add({ months: 1 }, { overflow: "constrain" }) }`, "2020-02-29T15:00:00-08:00[-08:00]");
|
||||
|
||||
// symmetrical with regard to negative durations in the time part
|
||||
assert.sameValue(`${ jan31.add({ minutes: -30 }) }`, "2020-01-31T14:30:00-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ jan31.add({ seconds: -30 }) }`, "2020-01-31T14:59:30-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ jan31.add({ minutes: -30 }) }`, "2020-01-31T14:30:00-08:00[-08:00]");
|
||||
assert.sameValue(`${ jan31.add({ seconds: -30 }) }`, "2020-01-31T14:59:30-08:00[-08:00]");
|
||||
|
||||
// throw when ambiguous result with reject
|
||||
assert.throws(RangeError, () => jan31.add({ months: 1 }, { overflow: "reject" }));
|
||||
|
|
|
@ -7,8 +7,8 @@ description: Temporal.ZonedDateTime.compare()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[Europe/Vienna]");
|
||||
var zdt2 = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102+01:00[Europe/Vienna]");
|
||||
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]");
|
||||
|
||||
// equal
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1), 0)
|
||||
|
@ -25,9 +25,9 @@ assert.sameValue(Temporal.ZonedDateTime.compare({
|
|||
month: 11,
|
||||
day: 18,
|
||||
hour: 15,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}, zdt2), -1);
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare("1976-11-18T15:23:30.123456789+01:00[Europe/Vienna]", 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, {
|
||||
|
@ -35,31 +35,31 @@ assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, {
|
|||
month: 10,
|
||||
day: 29,
|
||||
hour: 10,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}), -1);
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, "2019-10-29T10:46:38.271986102+01:00[Europe/Vienna]"), -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
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}, zdt2), -1);
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare({
|
||||
month: 11,
|
||||
day: 18,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}, zdt2));
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare({
|
||||
year: 1976,
|
||||
day: 18,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}, zdt2));
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}, zdt2));
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare({
|
||||
year: 1976,
|
||||
|
@ -71,28 +71,28 @@ assert.throws(TypeError, () => Temporal.ZonedDateTime.compare({
|
|||
months: 11,
|
||||
days: 19,
|
||||
hours: 15,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}, zdt2));
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, {
|
||||
year: 2019,
|
||||
month: 10,
|
||||
day: 29,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}), -1);
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(zdt1, {
|
||||
month: 10,
|
||||
day: 29,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}));
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(zdt1, {
|
||||
year: 2019,
|
||||
day: 29,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}));
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(zdt1, {
|
||||
year: 2019,
|
||||
month: 10,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}));
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(zdt1, {
|
||||
year: 2019,
|
||||
|
@ -104,17 +104,18 @@ assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(zdt1, {
|
|||
months: 10,
|
||||
days: 29,
|
||||
hours: 10,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}));
|
||||
|
||||
// disregards time zone IDs if exact times are equal
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withTimeZone("Asia/Kolkata")), 0);
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withTimeZone("+05:30")), 0);
|
||||
|
||||
// disregards calendar IDs if exact times and time zones are equal
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withCalendar("japanese")), 0);
|
||||
var fakeJapanese = { toString() { return "japanese"; }};
|
||||
assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withCalendar(fakeJapanese)), 0);
|
||||
|
||||
// compares exact time, not clock time
|
||||
var clockBefore = Temporal.ZonedDateTime.from("1999-12-31T23:30-08:00[America/Vancouver]");
|
||||
var clockAfter = Temporal.ZonedDateTime.from("2000-01-01T01:30-04:00[America/Halifax]");
|
||||
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);
|
||||
|
|
|
@ -7,7 +7,7 @@ description: Construction and properties
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = new Temporal.TimeZone("America/Los_Angeles");
|
||||
var tz = new Temporal.TimeZone("-08:00");
|
||||
var epochMillis = Date.UTC(1976, 10, 18, 15, 23, 30, 123);
|
||||
var epochNanos = BigInt(epochMillis) * BigInt(1000000) + BigInt(456789);
|
||||
|
||||
|
@ -50,10 +50,29 @@ assert.sameValue(zdt.offset, "+00:00");
|
|||
assert.sameValue(zdt.offsetNanoseconds, 0);
|
||||
assert.sameValue(`${ zdt }`, "1976-11-18T15:23:30.123456789+00:00[UTC]");
|
||||
|
||||
// Temporal.ZonedDateTime with non-UTC time zone and non-ISO calendar"
|
||||
var zdt = new Temporal.ZonedDateTime(epochNanos, Temporal.TimeZone.from("Europe/Vienna"), Temporal.Calendar.from("gregory"));
|
||||
|
||||
// can be constructed"
|
||||
// Temporal.ZonedDateTime with non-UTC time zone and non-ISO calendar
|
||||
// can be constructed
|
||||
var fakeGregorian = {
|
||||
era() { return "ce"; },
|
||||
year(date) { return date.withCalendar("iso8601").year; },
|
||||
month(date) { return date.withCalendar("iso8601").month; },
|
||||
monthCode(date) { return date.withCalendar("iso8601").monthCode; },
|
||||
day(date) { return date.withCalendar("iso8601").day; },
|
||||
dayOfWeek(date) { return date.withCalendar("iso8601").dayOfWeek; },
|
||||
dayOfYear(date) { return date.withCalendar("iso8601").dayOfYear; },
|
||||
weekOfYear(date) { return date.withCalendar("iso8601").weekOfYear; },
|
||||
daysInWeek(date) { return date.withCalendar("iso8601").daysInWeek; },
|
||||
daysInMonth(date) { return date.withCalendar("iso8601").daysInMonth; },
|
||||
daysInYear(date) { return date.withCalendar("iso8601").daysInYear; },
|
||||
monthsInYear(date) { return date.withCalendar("iso8601").monthsInYear; },
|
||||
inLeapYear(date) { return date.withCalendar("iso8601").inLeapYear; },
|
||||
toString() { return "gregory"; },
|
||||
};
|
||||
var fakeVienna = {
|
||||
getOffsetNanosecondsFor() { return 3600_000_000_000; },
|
||||
toString() { return "Europe/Vienna"; },
|
||||
}
|
||||
var zdt = new Temporal.ZonedDateTime(epochNanos, fakeVienna, fakeGregorian);
|
||||
assert(zdt instanceof Temporal.ZonedDateTime);
|
||||
assert.sameValue(typeof zdt, "object");
|
||||
|
||||
|
|
|
@ -9,15 +9,15 @@ features: [Temporal]
|
|||
|
||||
|
||||
// subtract result
|
||||
var later = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102-03:00[America/Santiago]");
|
||||
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[America/Santiago]");
|
||||
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[America/Santiago]");
|
||||
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[America/Santiago]");
|
||||
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[America/Santiago]").add({ hours: -12 }) }`, "2019-10-28T22:46:38.271986102-03:00[America/Santiago]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2020-05-31T23:12:38.271986102-04:00[America/Santiago]").subtract({ hours: -2 }) }`, "2020-06-01T01:12:38.271986102-04:00[America/Santiago]");
|
||||
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]");
|
||||
|
|
|
@ -243,8 +243,8 @@ var diff = start.until(end, { largestUnit: "days" });
|
|||
assert.sameValue(`${ diff }`, "P1DT19H");
|
||||
|
||||
// Rounding up to hours causes one more day of overflow (positive)
|
||||
var start = Temporal.ZonedDateTime.from("2020-01-01T00:00-08:00[America/Los_Angeles]");
|
||||
var end = Temporal.ZonedDateTime.from("2020-01-03T23:59-08:00[America/Los_Angeles]");
|
||||
var start = Temporal.ZonedDateTime.from("2020-01-01T00:00-08:00[-08:00]");
|
||||
var end = Temporal.ZonedDateTime.from("2020-01-03T23:59-08:00[-08:00]");
|
||||
var diff = start.until(end, {
|
||||
largestUnit: "days",
|
||||
smallestUnit: "hours",
|
||||
|
@ -253,8 +253,8 @@ var diff = start.until(end, {
|
|||
assert.sameValue(`${ diff }`, "P3D");
|
||||
|
||||
// Rounding up to hours causes one more day of overflow (negative)
|
||||
var start = Temporal.ZonedDateTime.from("2020-01-01T00:00-08:00[America/Los_Angeles]");
|
||||
var end = Temporal.ZonedDateTime.from("2020-01-03T23:59-08:00[America/Los_Angeles]");
|
||||
var start = Temporal.ZonedDateTime.from("2020-01-01T00:00-08:00[-08:00]");
|
||||
var end = Temporal.ZonedDateTime.from("2020-01-03T23:59-08:00[-08:00]");
|
||||
var diff = end.until(start, {
|
||||
largestUnit: "days",
|
||||
smallestUnit: "hours",
|
||||
|
|
|
@ -7,12 +7,25 @@ description: Temporal.ZonedDateTime.prototype.equals()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = Temporal.TimeZone.from("America/New_York");
|
||||
var cal = Temporal.Calendar.from("gregory");
|
||||
var tz = {
|
||||
getPossibleInstantsFor(pdt) { return Temporal.TimeZone.from("-05:00").getPossibleInstantsFor(pdt); },
|
||||
toString() { return "America/New_York"; },
|
||||
};
|
||||
var cal = {
|
||||
dateFromFields(...args) { return Temporal.Calendar.from("iso8601").dateFromFields(...args); },
|
||||
toString() { return "gregory"; },
|
||||
};
|
||||
var zdt = new Temporal.ZonedDateTime(0n, tz, cal);
|
||||
|
||||
// constructed from equivalent parameters are equal
|
||||
var zdt2 = Temporal.ZonedDateTime.from("1969-12-31T19:00-05:00[America/New_York][u-ca=gregory]");
|
||||
var zdt2 = Temporal.ZonedDateTime.from({
|
||||
year: 1969,
|
||||
month: 12,
|
||||
day: 31,
|
||||
hour: 19,
|
||||
timeZone: tz,
|
||||
calendar: cal,
|
||||
});
|
||||
assert(zdt.equals(zdt2));
|
||||
assert(zdt2.equals(zdt));
|
||||
|
||||
|
@ -21,7 +34,7 @@ var zdt2 = new Temporal.ZonedDateTime(1n, tz, cal);
|
|||
assert(!zdt.equals(zdt2));
|
||||
|
||||
// different time zone not equal
|
||||
var zdt2 = new Temporal.ZonedDateTime(0n, "America/Chicago", cal);
|
||||
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", cal);
|
||||
assert(!zdt.equals(zdt2));
|
||||
|
||||
// different calendar not equal
|
||||
|
@ -29,14 +42,14 @@ var zdt2 = new Temporal.ZonedDateTime(0n, tz, "iso8601");
|
|||
assert(!zdt.equals(zdt2));
|
||||
|
||||
// casts its argument
|
||||
assert(zdt.equals("1969-12-31T19:00-05:00[America/New_York][u-ca=gregory]"));
|
||||
assert(zdt.equals({
|
||||
year: 1969,
|
||||
month: 12,
|
||||
day: 31,
|
||||
hour: 19,
|
||||
timeZone: "America/New_York",
|
||||
calendar: "gregory"
|
||||
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
|
||||
|
@ -44,22 +57,22 @@ assert(!zdt.equals({
|
|||
year: 1969,
|
||||
month: 12,
|
||||
day: 31,
|
||||
timeZone: "America/New_York"
|
||||
timeZone: tz
|
||||
}));
|
||||
assert.throws(TypeError, () => zdt.equals({
|
||||
month: 12,
|
||||
day: 31,
|
||||
timeZone: "America/New_York"
|
||||
timeZone: tz
|
||||
}));
|
||||
assert.throws(TypeError, () => zdt.equals({
|
||||
year: 1969,
|
||||
day: 31,
|
||||
timeZone: "America/New_York"
|
||||
timeZone: tz
|
||||
}));
|
||||
assert.throws(TypeError, () => zdt.equals({
|
||||
year: 1969,
|
||||
month: 12,
|
||||
timeZone: "America/New_York"
|
||||
timeZone: tz
|
||||
}));
|
||||
assert.throws(TypeError, () => zdt.equals({
|
||||
year: 1969,
|
||||
|
@ -70,6 +83,6 @@ assert.throws(TypeError, () => zdt.equals({
|
|||
years: 1969,
|
||||
months: 12,
|
||||
days: 31,
|
||||
timeZone: "America/New_York",
|
||||
timeZone: tz,
|
||||
calendarName: "gregory"
|
||||
}));
|
||||
|
|
|
@ -17,29 +17,29 @@ var breakoutUnits = (op, zdt, d, options) => zdt[op]({ years: d.years }, options
|
|||
}, options);
|
||||
|
||||
// order of operations: add / none
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[America/Los_Angeles]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
|
||||
var d = Temporal.Duration.from({
|
||||
months: 1,
|
||||
days: 1
|
||||
});
|
||||
var options = undefined;
|
||||
var result = zdt.add(d, options);
|
||||
assert.sameValue(result.toString(), "2020-03-01T00:00:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(result.toString(), "2020-03-01T00:00:00-08:00[-08:00]");
|
||||
assert.sameValue(breakoutUnits("add", zdt, d, options).toString(), result.toString());
|
||||
|
||||
// order of operations: add / constrain
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[America/Los_Angeles]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
|
||||
var d = Temporal.Duration.from({
|
||||
months: 1,
|
||||
days: 1
|
||||
});
|
||||
var options = { overflow: "constrain" };
|
||||
var result = zdt.add(d, options);
|
||||
assert.sameValue(result.toString(), "2020-03-01T00:00:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(result.toString(), "2020-03-01T00:00:00-08:00[-08:00]");
|
||||
assert.sameValue(breakoutUnits("add", zdt, d, options).toString(), result.toString());
|
||||
|
||||
// order of operations: add / reject
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[America/Los_Angeles]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
|
||||
var d = Temporal.Duration.from({
|
||||
months: 1,
|
||||
days: 1
|
||||
|
@ -48,29 +48,29 @@ var options = { overflow: "reject" };
|
|||
assert.throws(RangeError, () => zdt.add(d, options));
|
||||
|
||||
// order of operations: subtract / none
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-07:00[America/Los_Angeles]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
|
||||
var d = Temporal.Duration.from({
|
||||
months: 1,
|
||||
days: 1
|
||||
});
|
||||
var options = undefined;
|
||||
var result = zdt.subtract(d, options);
|
||||
assert.sameValue(result.toString(), "2020-02-28T00:00:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(result.toString(), "2020-02-28T00:00:00-08:00[-08:00]");
|
||||
assert.sameValue(breakoutUnits("subtract", zdt, d, options).toString(), result.toString());
|
||||
|
||||
// order of operations: subtract / constrain
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-07:00[America/Los_Angeles]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
|
||||
var d = Temporal.Duration.from({
|
||||
months: 1,
|
||||
days: 1
|
||||
});
|
||||
var options = { overflow: "constrain" };
|
||||
var result = zdt.subtract(d, options);
|
||||
assert.sameValue(result.toString(), "2020-02-28T00:00:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(result.toString(), "2020-02-28T00:00:00-08:00[-08:00]");
|
||||
assert.sameValue(breakoutUnits("subtract", zdt, d, options).toString(), result.toString());
|
||||
|
||||
// order of operations: subtract / reject
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-07:00[America/Los_Angeles]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
|
||||
var d = Temporal.Duration.from({
|
||||
months: 1,
|
||||
days: 1
|
||||
|
|
|
@ -7,7 +7,7 @@ description: property bags
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var lagos = Temporal.TimeZone.from("Africa/Lagos");
|
||||
var lagos = Temporal.TimeZone.from("+01:00");
|
||||
|
||||
// can be constructed with monthCode and without month
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
||||
|
@ -15,7 +15,7 @@ assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
|||
monthCode: "M11",
|
||||
day: 18,
|
||||
timeZone: lagos
|
||||
}) }`, "1976-11-18T00:00:00+01:00[Africa/Lagos]");
|
||||
}) }`, "1976-11-18T00:00:00+01:00[+01:00]");
|
||||
|
||||
// can be constructed with month and without monthCode
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
||||
|
@ -23,7 +23,7 @@ assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
|||
month: 11,
|
||||
day: 18,
|
||||
timeZone: lagos
|
||||
}) }`, "1976-11-18T00:00:00+01:00[Africa/Lagos]");
|
||||
}) }`, "1976-11-18T00:00:00+01:00[+01:00]");
|
||||
|
||||
// month and monthCode must agree
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from({
|
||||
|
@ -53,7 +53,7 @@ assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
|||
day: 18,
|
||||
timeZone: lagos
|
||||
}, () => {
|
||||
}) }`, "1976-11-18T00:00:00+01:00[Africa/Lagos]");
|
||||
}) }`, "1976-11-18T00:00:00+01:00[+01:00]");
|
||||
|
||||
// object must contain at least the required correctly-spelled properties
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||
|
@ -70,7 +70,7 @@ assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
|||
day: 18,
|
||||
timeZone: lagos,
|
||||
hours: 12
|
||||
}) }`, "1976-11-18T00:00:00+01:00[Africa/Lagos]");
|
||||
}) }`, "1976-11-18T00:00:00+01:00[+01:00]");
|
||||
|
||||
// casts offset property
|
||||
var zdt = Temporal.ZonedDateTime.from({
|
||||
|
@ -90,12 +90,12 @@ var bad = {
|
|||
timeZone: lagos
|
||||
};
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(bad, { overflow: "reject" }));
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(bad) }`, "2019-01-31T00:00:00+01:00[Africa/Lagos]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(bad, { overflow: "constrain" }) }`, "2019-01-31T00:00:00+01:00[Africa/Lagos]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(bad) }`, "2019-01-31T00:00:00+01:00[+01:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(bad, { overflow: "constrain" }) }`, "2019-01-31T00:00:00+01:00[+01:00]");
|
||||
|
||||
// Offset options
|
||||
|
||||
// { offset: 'reject' } throws if offset does not match offset time zone
|
||||
// { offset: 'reject' } throws if offset does not match offset time zone
|
||||
var obj = {
|
||||
year: 2020,
|
||||
month: 3,
|
||||
|
@ -107,14 +107,14 @@ var obj = {
|
|||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" }));
|
||||
|
||||
// { offset: 'reject' } throws if offset does not match IANA time zone
|
||||
// { offset: 'reject' } throws if offset does not match IANA time zone
|
||||
var obj = {
|
||||
year: 2020,
|
||||
month: 3,
|
||||
day: 8,
|
||||
hour: 1,
|
||||
offset: "-04:00",
|
||||
timeZone: "America/Chicago"
|
||||
timeZone: "UTC"
|
||||
};
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" }));
|
||||
|
@ -266,17 +266,17 @@ assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, {
|
|||
3,
|
||||
null
|
||||
].forEach(disambiguation => {
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-11-01T04:00[America/Los_Angeles]", { disambiguation }));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-11-01T04:00[UTC]", { disambiguation }));
|
||||
});
|
||||
|
||||
// sub-minute time zone offsets
|
||||
|
||||
// does not truncate offset property to minutes
|
||||
// does not truncate offset property to minutes
|
||||
var zdt = Temporal.ZonedDateTime.from({
|
||||
year: 1971,
|
||||
month: 1,
|
||||
day: 1,
|
||||
hour: 12,
|
||||
timeZone: "Africa/Monrovia"
|
||||
timeZone: "-00:44:30"
|
||||
});
|
||||
assert.sameValue(zdt.offset, "-00:44:30");
|
||||
|
|
|
@ -7,8 +7,8 @@ description: Reversibility of differences
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var earlier = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-03:00[America/Santiago]");
|
||||
var later = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102-03:00[America/Santiago]");
|
||||
var earlier = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-03:00[-03:00]");
|
||||
var later = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102-03:00[-03:00]");
|
||||
[
|
||||
"hours",
|
||||
"minutes",
|
||||
|
|
|
@ -7,7 +7,7 @@ description: Temporal.ZonedDateTime.prototype.round()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[Europe/Vienna]");
|
||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||
|
||||
// throws without parameter
|
||||
assert.throws(TypeError, () => zdt.round());
|
||||
|
@ -37,43 +37,43 @@ assert.throws(RangeError, () => zdt.round({
|
|||
assert.sameValue(`${ zdt.round({
|
||||
smallestUnit: "hour",
|
||||
roundingIncrement: 4
|
||||
}) }`, "1976-11-18T16:00:00+01:00[Europe/Vienna]");
|
||||
}) }`, "1976-11-18T16:00:00+01:00[+01:00]");
|
||||
|
||||
// rounds to an increment of minutes
|
||||
assert.sameValue(`${ zdt.round({
|
||||
smallestUnit: "minute",
|
||||
roundingIncrement: 15
|
||||
}) }`, "1976-11-18T15:30:00+01:00[Europe/Vienna]");
|
||||
}) }`, "1976-11-18T15:30:00+01:00[+01:00]");
|
||||
|
||||
// rounds to an increment of seconds
|
||||
assert.sameValue(`${ zdt.round({
|
||||
smallestUnit: "second",
|
||||
roundingIncrement: 30
|
||||
}) }`, "1976-11-18T15:23:30+01:00[Europe/Vienna]");
|
||||
}) }`, "1976-11-18T15:23:30+01:00[+01:00]");
|
||||
|
||||
// rounds to an increment of milliseconds
|
||||
assert.sameValue(`${ zdt.round({
|
||||
smallestUnit: "millisecond",
|
||||
roundingIncrement: 10
|
||||
}) }`, "1976-11-18T15:23:30.12+01:00[Europe/Vienna]");
|
||||
}) }`, "1976-11-18T15:23:30.12+01:00[+01:00]");
|
||||
|
||||
// rounds to an increment of microseconds
|
||||
assert.sameValue(`${ zdt.round({
|
||||
smallestUnit: "microsecond",
|
||||
roundingIncrement: 10
|
||||
}) }`, "1976-11-18T15:23:30.12346+01:00[Europe/Vienna]");
|
||||
}) }`, "1976-11-18T15:23:30.12346+01:00[+01:00]");
|
||||
|
||||
// rounds to an increment of nanoseconds
|
||||
assert.sameValue(`${ zdt.round({
|
||||
smallestUnit: "nanosecond",
|
||||
roundingIncrement: 10
|
||||
}) }`, "1976-11-18T15:23:30.12345679+01:00[Europe/Vienna]");
|
||||
}) }`, "1976-11-18T15:23:30.12345679+01:00[+01:00]");
|
||||
|
||||
// 1 day is a valid increment
|
||||
assert.sameValue(`${ zdt.round({
|
||||
smallestUnit: "day",
|
||||
roundingIncrement: 1
|
||||
}) }`, "1976-11-19T00:00:00+01:00[Europe/Vienna]");
|
||||
}) }`, "1976-11-19T00:00:00+01:00[+01:00]");
|
||||
|
||||
// valid hour increments divide into 24
|
||||
var smallestUnit = "hour";
|
||||
|
@ -200,7 +200,7 @@ assert.throws(RangeError, () => zdt.round({
|
|||
smallestUnit: "nanosecond",
|
||||
roundingIncrement: 1000
|
||||
}));
|
||||
var bal = Temporal.ZonedDateTime.from("1976-11-18T23:59:59.999999999+01:00[Europe/Vienna]");
|
||||
var bal = Temporal.ZonedDateTime.from("1976-11-18T23:59:59.999999999+01:00[+01:00]");
|
||||
[
|
||||
"day",
|
||||
"hour",
|
||||
|
@ -209,7 +209,7 @@ var bal = Temporal.ZonedDateTime.from("1976-11-18T23:59:59.999999999+01:00[Europ
|
|||
"millisecond",
|
||||
"microsecond"
|
||||
].forEach(smallestUnit => {
|
||||
assert.sameValue(`${ bal.round({ smallestUnit }) }`, "1976-11-19T00:00:00+01:00[Europe/Vienna]");
|
||||
assert.sameValue(`${ bal.round({ smallestUnit }) }`, "1976-11-19T00:00:00+01:00[+01:00]");
|
||||
});
|
||||
|
||||
// rounds correctly to a 25-hour day
|
||||
|
|
|
@ -7,7 +7,7 @@ description: Temporal.ZonedDateTime.prototype.since()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[Europe/Vienna]");
|
||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||
|
||||
// zdt.since(earlier) === earlier.until(zdt) with default options
|
||||
var earlier = Temporal.ZonedDateTime.from({
|
||||
|
@ -15,7 +15,7 @@ var earlier = Temporal.ZonedDateTime.from({
|
|||
month: 3,
|
||||
day: 3,
|
||||
hour: 18,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
});
|
||||
assert.sameValue(`${ zdt.since(earlier) }`, `${ earlier.until(zdt) }`);
|
||||
|
||||
|
@ -25,18 +25,18 @@ assert.sameValue(`${ zdt.since({
|
|||
month: 10,
|
||||
day: 29,
|
||||
hour: 10,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}) }`, "-PT376434H36M29.876543211S");
|
||||
assert.sameValue(`${ zdt.since("2019-10-29T10:46:38.271986102+01:00[Europe/Vienna]") }`, "-PT376435H23M8.148529313S");
|
||||
var feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[Europe/Vienna]");
|
||||
var feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[Europe/Vienna]");
|
||||
assert.sameValue(`${ zdt.since("2019-10-29T10:46:38.271986102+01:00[+01:00]") }`, "-PT376435H23M8.148529313S");
|
||||
var feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
||||
var feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
||||
|
||||
// defaults to returning hours
|
||||
assert.sameValue(`${ feb21.since(feb20) }`, "PT8784H");
|
||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "auto" }) }`, "PT8784H");
|
||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "hours" }) }`, "PT8784H");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2021-02-01T00:00:00.000000001+01:00[Europe/Vienna]").since(feb20) }`, "PT8784H0.000000001S");
|
||||
assert.sameValue(`${ feb21.since(Temporal.ZonedDateTime.from("2020-02-01T00:00:00.000000001+01:00[Europe/Vienna]")) }`, "PT8783H59M59.999999999S");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2021-02-01T00:00:00.000000001+01:00[+01:00]").since(feb20) }`, "PT8784H0.000000001S");
|
||||
assert.sameValue(`${ feb21.since(Temporal.ZonedDateTime.from("2020-02-01T00:00:00.000000001+01:00[+01:00]")) }`, "PT8783H59M59.999999999S");
|
||||
|
||||
// can return lower or higher units
|
||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "years" }) }`, "P1Y");
|
||||
|
@ -67,8 +67,8 @@ assert.sameValue(nsDiff.microseconds, 0);
|
|||
assert.sameValue(nsDiff.nanoseconds, 86400250250250);
|
||||
|
||||
// does not include higher units than necessary
|
||||
var lastFeb20 = Temporal.ZonedDateTime.from("2020-02-29T00:00+01:00[Europe/Vienna]");
|
||||
var lastFeb21 = Temporal.ZonedDateTime.from("2021-02-28T00:00+01:00[Europe/Vienna]");
|
||||
var lastFeb20 = Temporal.ZonedDateTime.from("2020-02-29T00:00+01:00[+01:00]");
|
||||
var lastFeb21 = Temporal.ZonedDateTime.from("2021-02-28T00:00+01:00[+01:00]");
|
||||
assert.sameValue(`${ lastFeb21.since(lastFeb20) }`, "PT8760H");
|
||||
assert.sameValue(`${ lastFeb21.since(lastFeb20, { largestUnit: "months" }) }`, "P11M28D");
|
||||
assert.sameValue(`${ lastFeb21.since(lastFeb20, { largestUnit: "years" }) }`, "P11M28D");
|
||||
|
@ -87,11 +87,12 @@ assert.notSameValue(monthsDifference.months, 0);
|
|||
|
||||
// no two different calendars
|
||||
var zdt1 = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", Temporal.Calendar.from("japanese"));
|
||||
var fakeJapanese = { toString() { return "japanese"; }};
|
||||
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", fakeJapanese);
|
||||
assert.throws(RangeError, () => zdt1.since(zdt2));
|
||||
|
||||
var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[Europe/Vienna]');
|
||||
var later = Temporal.ZonedDateTime.from('2021-09-07T14:39:40.987654321+02:00[Europe/Vienna]');
|
||||
var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
||||
var later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
||||
// assumes a different default for largestUnit if smallestUnit is larger than days
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
smallestUnit: "years",
|
||||
|
|
|
@ -7,151 +7,62 @@ description: string parsing
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// parses with an IANA zone but no offset (with disambiguation)
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-03-08T02:30[America/Los_Angeles]", { disambiguation: "earlier" });
|
||||
assert.sameValue(zdt.toString(), "2020-03-08T01:30:00-08:00[America/Los_Angeles]");
|
||||
|
||||
// "Z" means preserve the exact time in the given IANA time zone
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-03-08T09:00:00Z[America/Los_Angeles]");
|
||||
assert.sameValue(zdt.toString(), "2020-03-08T01:00:00-08:00[America/Los_Angeles]");
|
||||
|
||||
// any number of decimal places
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.1-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.12-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.123-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1234-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.1234-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12345-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.12345-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.123456-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1234567-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.1234567-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12345678-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.12345678-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.123456789-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1-08:00[-08:00]") }`, "1976-11-18T15:23:30.1-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12-08:00[-08:00]") }`, "1976-11-18T15:23:30.12-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123-08:00[-08:00]") }`, "1976-11-18T15:23:30.123-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1234-08:00[-08:00]") }`, "1976-11-18T15:23:30.1234-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12345-08:00[-08:00]") }`, "1976-11-18T15:23:30.12345-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456-08:00[-08:00]") }`, "1976-11-18T15:23:30.123456-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1234567-08:00[-08:00]") }`, "1976-11-18T15:23:30.1234567-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12345678-08:00[-08:00]") }`, "1976-11-18T15:23:30.12345678-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-08:00[-08:00]") }`, "1976-11-18T15:23:30.123456789-08:00[-08:00]");
|
||||
|
||||
// variant decimal separator
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30,12-08:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.12-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30,12-08:00[-08:00]") }`, "1976-11-18T15:23:30.12-08:00[-08:00]");
|
||||
|
||||
// variant minus sign
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12\u221208:00[America/Los_Angeles]") }`, "1976-11-18T15:23:30.12-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12\u221208:00[-08:00]") }`, "1976-11-18T15:23:30.12-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("\u2212009999-11-18T15:23:30.12+00:00[UTC]") }`, "-009999-11-18T15:23:30.12+00:00[UTC]");
|
||||
|
||||
// mixture of basic and extended format
|
||||
[
|
||||
"1976-11-18T152330.1-08:00[America/Los_Angeles]",
|
||||
"19761118T15:23:30.1-08:00[America/Los_Angeles]",
|
||||
"1976-11-18T15:23:30.1-0800[America/Los_Angeles]",
|
||||
"1976-11-18T152330.1-0800[America/Los_Angeles]",
|
||||
"19761118T15:23:30.1-0800[America/Los_Angeles]",
|
||||
"19761118T152330.1-08:00[America/Los_Angeles]",
|
||||
"19761118T152330.1-0800[America/Los_Angeles]",
|
||||
"+001976-11-18T152330.1-08:00[America/Los_Angeles]",
|
||||
"+0019761118T15:23:30.1-08:00[America/Los_Angeles]",
|
||||
"+001976-11-18T15:23:30.1-0800[America/Los_Angeles]",
|
||||
"+001976-11-18T152330.1-0800[America/Los_Angeles]",
|
||||
"+0019761118T15:23:30.1-0800[America/Los_Angeles]",
|
||||
"+0019761118T152330.1-08:00[America/Los_Angeles]",
|
||||
"+0019761118T152330.1-0800[America/Los_Angeles]"
|
||||
].forEach(input => assert.sameValue(`${ Temporal.ZonedDateTime.from(input) }`, "1976-11-18T15:23:30.1-08:00[America/Los_Angeles]"));
|
||||
"1976-11-18T152330.1-08:00[-08:00]",
|
||||
"19761118T15:23:30.1-08:00[-08:00]",
|
||||
"1976-11-18T15:23:30.1-0800[-08:00]",
|
||||
"1976-11-18T152330.1-0800[-08:00]",
|
||||
"19761118T15:23:30.1-0800[-08:00]",
|
||||
"19761118T152330.1-08:00[-08:00]",
|
||||
"19761118T152330.1-0800[-08:00]",
|
||||
"+001976-11-18T152330.1-08:00[-08:00]",
|
||||
"+0019761118T15:23:30.1-08:00[-08:00]",
|
||||
"+001976-11-18T15:23:30.1-0800[-08:00]",
|
||||
"+001976-11-18T152330.1-0800[-08:00]",
|
||||
"+0019761118T15:23:30.1-0800[-08:00]",
|
||||
"+0019761118T152330.1-08:00[-08:00]",
|
||||
"+0019761118T152330.1-0800[-08:00]"
|
||||
].forEach(input => assert.sameValue(`${ Temporal.ZonedDateTime.from(input) }`, "1976-11-18T15:23:30.1-08:00[-08:00]"));
|
||||
|
||||
// optional parts
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30-08[America/Los_Angeles]") }`, "1976-11-18T15:23:30-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15-08:00[America/Los_Angeles]") }`, "1976-11-18T15:00:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2020-01-01[Asia/Tokyo]") }`, "2020-01-01T00:00:00+09:00[Asia/Tokyo]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30-08[-08:00]") }`, "1976-11-18T15:23:30-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15-08:00[-08:00]") }`, "1976-11-18T15:00:00-08:00[-08:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2020-01-01[+09:00]") }`, "2020-01-01T00:00:00+09:00[+09:00]");
|
||||
|
||||
// no junk at end of string
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-08:00[America/Los_Angeles]junk"))
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-08:00[-08:00]junk"))
|
||||
|
||||
// constrain has no effect on invalid ISO string
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-13-34T24:60[America/Los_Angeles]", { overflow: "constrain" }));
|
||||
// Offset options
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-13-34T24:60[-08:00]", { overflow: "constrain" }));
|
||||
|
||||
// { offset: 'reject' } throws if offset does not match IANA time zone
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-03-08T01:00-04:00[America/Chicago]"));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-03-08T01:00-04:00[America/Chicago]", { offset: "reject" }));
|
||||
// { offset: 'reject' } throws if offset does not match IANA time zone
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-03-08T01:00-04:00[UTC]"));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-03-08T01:00-04:00[UTC]", { offset: "reject" }));
|
||||
|
||||
// { offset: 'prefer' } if offset matches time zone (first 1:30 when DST ends)
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-11-01T01:30-07:00[America/Los_Angeles]", { offset: "prefer" });
|
||||
assert.sameValue(zdt.toString(), "2020-11-01T01:30:00-07:00[America/Los_Angeles]");
|
||||
|
||||
// { offset: 'prefer' } if offset matches time zone (second 1:30 when DST ends)
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-11-01T01:30-08:00[America/Los_Angeles]", { offset: "prefer" });
|
||||
assert.sameValue(zdt.toString(), "2020-11-01T01:30:00-08:00[America/Los_Angeles]");
|
||||
|
||||
// { offset: 'prefer' } if offset does not match time zone
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-11-01T04:00-07:00[America/Los_Angeles]", { offset: "prefer" });
|
||||
assert.sameValue(zdt.toString(), "2020-11-01T04:00:00-08:00[America/Los_Angeles]");
|
||||
|
||||
// { offset: 'ignore' } uses time zone only
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-11-01T04:00-12:00[America/Los_Angeles]", { offset: "ignore" });
|
||||
assert.sameValue(zdt.toString(), "2020-11-01T04:00:00-08:00[America/Los_Angeles]");
|
||||
|
||||
// { offset: 'use' } uses offset only
|
||||
var zdt = Temporal.ZonedDateTime.from("2020-11-01T04:00-07:00[America/Los_Angeles]", { offset: "use" });
|
||||
assert.sameValue(zdt.toString(), "2020-11-01T03:00:00-08:00[America/Los_Angeles]");
|
||||
|
||||
// Disambiguation options
|
||||
|
||||
// plain datetime with multiple instants - Fall DST in Brazil
|
||||
var str = "2019-02-16T23:45[America/Sao_Paulo]";
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str) }`, "2019-02-16T23:45:00-02:00[America/Sao_Paulo]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, { disambiguation: "compatible" }) }`, "2019-02-16T23:45:00-02:00[America/Sao_Paulo]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, { disambiguation: "earlier" }) }`, "2019-02-16T23:45:00-02:00[America/Sao_Paulo]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, { disambiguation: "later" }) }`, "2019-02-16T23:45:00-03:00[America/Sao_Paulo]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(str, { disambiguation: "reject" }));
|
||||
|
||||
// plain datetime with multiple instants - Spring DST in Los Angeles
|
||||
var str = "2020-03-08T02:30[America/Los_Angeles]";
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, { disambiguation: "compatible" }) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, { disambiguation: "earlier" }) }`, "2020-03-08T01:30:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, { disambiguation: "later" }) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(str, { disambiguation: "reject" }));
|
||||
|
||||
// uses disambiguation if offset is ignored
|
||||
var str = "2020-03-08T02:30[America/Los_Angeles]";
|
||||
var offset = "ignore";
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, { offset }) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2020-03-08T01:30:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(str, {
|
||||
offset,
|
||||
disambiguation: "reject"
|
||||
}));
|
||||
|
||||
// uses disambiguation if offset is wrong and option is prefer
|
||||
var str = "2020-03-08T02:30-23:59[America/Los_Angeles]";
|
||||
var offset = "prefer";
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, { offset }) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2020-03-08T01:30:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(str, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2020-03-08T03:30:00-07:00[America/Los_Angeles]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(str, {
|
||||
offset,
|
||||
disambiguation: "reject"
|
||||
}));
|
||||
|
||||
// throw when bad disambiguation
|
||||
// throw when bad disambiguation
|
||||
[
|
||||
"",
|
||||
"EARLIER",
|
||||
"balance"
|
||||
].forEach(disambiguation => {
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-11-01T04:00[America/Los_Angeles]", { disambiguation }));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-11-01T04:00[-08:00]", { disambiguation }));
|
||||
});
|
||||
|
|
|
@ -15,15 +15,15 @@ assert.sameValue(`${ earlier }`, "1969-12-15T12:23:45.678900434+00:00[UTC]");
|
|||
|
||||
// casts argument
|
||||
assert.sameValue(`${ zdt.subtract("PT240H0.000000800S") }`, "1969-12-15T12:23:45.678900434+00:00[UTC]");
|
||||
var mar31 = Temporal.ZonedDateTime.from("2020-03-31T15:00-07:00[America/Vancouver]");
|
||||
var mar31 = Temporal.ZonedDateTime.from("2020-03-31T15:00+00:00[UTC]");
|
||||
|
||||
// constrain when ambiguous result
|
||||
assert.sameValue(`${ mar31.subtract({ months: 1 }) }`, "2020-02-29T15:00:00-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ mar31.subtract({ months: 1 }, { overflow: "constrain" }) }`, "2020-02-29T15:00:00-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ mar31.subtract({ months: 1 }) }`, "2020-02-29T15:00:00+00:00[UTC]");
|
||||
assert.sameValue(`${ mar31.subtract({ months: 1 }, { overflow: "constrain" }) }`, "2020-02-29T15:00:00+00:00[UTC]");
|
||||
|
||||
// symmetrical with regard to negative durations in the time part
|
||||
assert.sameValue(`${ mar31.subtract({ minutes: -30 }) }`, "2020-03-31T15:30:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ mar31.subtract({ seconds: -30 }) }`, "2020-03-31T15:00:30-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ mar31.subtract({ minutes: -30 }) }`, "2020-03-31T15:30:00+00:00[UTC]");
|
||||
assert.sameValue(`${ mar31.subtract({ seconds: -30 }) }`, "2020-03-31T15:00:30+00:00[UTC]");
|
||||
|
||||
// throw when ambiguous result with reject
|
||||
assert.throws(RangeError, () => mar31.subtract({ months: 1 }, { overflow: "reject" }));
|
||||
|
|
|
@ -9,7 +9,7 @@ features: [Temporal]
|
|||
|
||||
|
||||
// recent date
|
||||
var zdt = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102+01:00[Europe/Amsterdam]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102+01:00[+01:00]");
|
||||
assert.sameValue(`${ zdt.toInstant() }`, "2019-10-29T09:46:38.271986102Z");
|
||||
|
||||
// year ≤ 99
|
||||
|
@ -27,7 +27,7 @@ zdt = Temporal.ZonedDateTime.from("-001000-10-29T10:46:38.271986102+00:00[UTC]")
|
|||
assert.sameValue(`${ zdt.toInstant() }`, "-001000-10-29T10:46:38.271986102Z");
|
||||
|
||||
// year 0 leap day
|
||||
var zdt = Temporal.ZonedDateTime.from("0000-02-29T00:00-00:01:15[Europe/London]");
|
||||
var zdt = Temporal.ZonedDateTime.from("0000-02-29T00:00-00:01:15[-00:01:15]");
|
||||
assert.sameValue(`${ zdt.toInstant() }`, "0000-02-29T00:01:15Z");
|
||||
zdt = Temporal.ZonedDateTime.from("+000000-02-29T00:00-00:01:15[Europe/London]");
|
||||
zdt = Temporal.ZonedDateTime.from("+000000-02-29T00:00-00:01:15[-00:01:15]");
|
||||
assert.sameValue(`${ zdt.toInstant() }`, "0000-02-29T00:01:15Z");
|
||||
|
|
|
@ -7,15 +7,16 @@ description: Temporal.ZonedDateTime.prototype.toPlainDate()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = new Temporal.TimeZone("America/Los_Angeles");
|
||||
var tz = new Temporal.TimeZone("-07:00");
|
||||
|
||||
// works
|
||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO(tz);
|
||||
assert.sameValue(`${ zdt.toPlainDate() }`, "2019-10-29");
|
||||
|
||||
// preserves the calendar
|
||||
const fakeGregorian = { toString() { return "gregory" }};
|
||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTime({
|
||||
timeZone: tz,
|
||||
calendar: "gregory"
|
||||
calendar: fakeGregorian
|
||||
});
|
||||
assert.sameValue(zdt.toPlainDate().calendar.id, "gregory");
|
||||
assert.sameValue(zdt.toPlainDate().calendar, fakeGregorian);
|
||||
|
|
|
@ -7,15 +7,25 @@ description: Temporal.ZonedDateTime.prototype.toPlainMonthDay()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = new Temporal.TimeZone("America/Los_Angeles");
|
||||
var tz = new Temporal.TimeZone("-08:00");
|
||||
|
||||
// works
|
||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO(tz);
|
||||
assert.sameValue(`${ zdt.toPlainMonthDay() }`, "10-29");
|
||||
|
||||
// preserves the calendar
|
||||
var fakeGregorian = {
|
||||
monthDayFromFields(fields) {
|
||||
var md = Temporal.Calendar.from("iso8601").monthDayFromFields(fields);
|
||||
var {isoYear, isoMonth, isoDay} = md.getISOFields();
|
||||
return new Temporal.PlainMonthDay(isoMonth, isoDay, this, isoYear);
|
||||
},
|
||||
monthCode(date) { return date.withCalendar("iso8601").monthCode; },
|
||||
day(date) { return date.withCalendar("iso8601").day; },
|
||||
toString() { return "gregory"; },
|
||||
};
|
||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTime({
|
||||
timeZone: tz,
|
||||
calendar: "gregory"
|
||||
calendar: fakeGregorian
|
||||
});
|
||||
assert.sameValue(zdt.toPlainMonthDay().calendar.id, "gregory");
|
||||
assert.sameValue(zdt.toPlainMonthDay().calendar, fakeGregorian);
|
||||
|
|
|
@ -7,7 +7,7 @@ description: Temporal.ZonedDateTime.prototype.toPlainTime()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = new Temporal.TimeZone("America/Los_Angeles");
|
||||
var tz = new Temporal.TimeZone("-07:00");
|
||||
|
||||
// works
|
||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO(tz);
|
||||
|
|
|
@ -7,15 +7,25 @@ description: Temporal.ZonedDateTime.prototype.toPlainYearMonth()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = new Temporal.TimeZone("America/Los_Angeles");
|
||||
var tz = new Temporal.TimeZone("-08:00");
|
||||
|
||||
// works
|
||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO(tz);
|
||||
assert.sameValue(`${ zdt.toPlainYearMonth() }`, "2019-10");
|
||||
|
||||
// preserves the calendar
|
||||
var fakeGregorian = {
|
||||
yearMonthFromFields(fields) {
|
||||
var ym = Temporal.Calendar.from("iso8601").yearMonthFromFields(fields);
|
||||
var {isoYear, isoMonth, isoDay} = ym.getISOFields();
|
||||
return new Temporal.PlainYearMonth(isoYear, isoMonth, this, isoDay);
|
||||
},
|
||||
year(date) { return date.withCalendar("iso8601").year; },
|
||||
monthCode(date) { return date.withCalendar("iso8601").monthCode; },
|
||||
toString() { return "gregory"; },
|
||||
};
|
||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTime({
|
||||
timeZone: tz,
|
||||
calendar: "gregory"
|
||||
calendar: fakeGregorian
|
||||
});
|
||||
assert.sameValue(zdt.toPlainYearMonth().calendar.id, "gregory");
|
||||
assert.sameValue(zdt.toPlainYearMonth().calendar, fakeGregorian);
|
||||
|
|
|
@ -7,17 +7,18 @@ description: Temporal.ZonedDateTime.prototype.toString()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23+01:00[Europe/Vienna]");
|
||||
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23+00:00[UTC]");
|
||||
var fakeGregorian = { toString() { return "gregory" }};
|
||||
|
||||
// shows only non-ISO calendar if calendarName = auto
|
||||
assert.sameValue(zdt1.toString({ calendarName: "auto" }), "1976-11-18T15:23:00+01:00[Europe/Vienna]");
|
||||
assert.sameValue(zdt1.withCalendar("gregory").toString({ calendarName: "auto" }), "1976-11-18T15:23:00+01:00[Europe/Vienna][u-ca=gregory]");
|
||||
assert.sameValue(zdt1.toString({ calendarName: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");
|
||||
assert.sameValue(zdt1.withCalendar(fakeGregorian).toString({ calendarName: "auto" }), "1976-11-18T15:23:00+00:00[UTC][u-ca=gregory]");
|
||||
|
||||
// shows ISO calendar if calendarName = always
|
||||
assert.sameValue(zdt1.toString({ calendarName: "always" }), "1976-11-18T15:23:00+01:00[Europe/Vienna][u-ca=iso8601]");
|
||||
assert.sameValue(zdt1.toString({ calendarName: "always" }), "1976-11-18T15:23:00+00:00[UTC][u-ca=iso8601]");
|
||||
|
||||
// omits non-ISO calendar if calendarName = never
|
||||
assert.sameValue(zdt1.withCalendar("gregory").toString({ calendarName: "never" }), "1976-11-18T15:23:00+01:00[Europe/Vienna]");
|
||||
assert.sameValue(zdt1.withCalendar(fakeGregorian).toString({ calendarName: "never" }), "1976-11-18T15:23:00+00:00[UTC]");
|
||||
|
||||
// throws on invalid calendar
|
||||
[
|
||||
|
@ -29,27 +30,27 @@ assert.sameValue(zdt1.withCalendar("gregory").toString({ calendarName: "never" }
|
|||
});
|
||||
|
||||
// shows time zone if timeZoneName = auto
|
||||
assert.sameValue(zdt1.toString({ timeZoneName: "auto" }), "1976-11-18T15:23:00+01:00[Europe/Vienna]");
|
||||
assert.sameValue(zdt1.toString({ timeZoneName: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");
|
||||
|
||||
// omits time zone if timeZoneName = never
|
||||
assert.sameValue(zdt1.toString({ timeZoneName: "never" }), "1976-11-18T15:23:00+01:00");
|
||||
assert.sameValue(zdt1.toString({ timeZoneName: "never" }), "1976-11-18T15:23:00+00:00");
|
||||
|
||||
// shows offset if offset = auto
|
||||
assert.sameValue(zdt1.toString({ offset: "auto" }), "1976-11-18T15:23:00+01:00[Europe/Vienna]");
|
||||
assert.sameValue(zdt1.toString({ offset: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");
|
||||
|
||||
// omits offset if offset = never
|
||||
assert.sameValue(zdt1.toString({ offset: "never" }), "1976-11-18T15:23:00[Europe/Vienna]");
|
||||
assert.sameValue(zdt1.toString({ offset: "never" }), "1976-11-18T15:23:00[UTC]");
|
||||
|
||||
// combinations of calendar, time zone, and offset
|
||||
var zdt = zdt1.withCalendar("gregory");
|
||||
var zdt = zdt1.withCalendar(fakeGregorian);
|
||||
assert.sameValue(zdt.toString({
|
||||
timeZoneName: "never",
|
||||
calendarName: "never"
|
||||
}), "1976-11-18T15:23:00+01:00");
|
||||
}), "1976-11-18T15:23:00+00:00");
|
||||
assert.sameValue(zdt.toString({
|
||||
offset: "never",
|
||||
calendarName: "never"
|
||||
}), "1976-11-18T15:23:00[Europe/Vienna]");
|
||||
}), "1976-11-18T15:23:00[UTC]");
|
||||
assert.sameValue(zdt.toString({
|
||||
offset: "never",
|
||||
timeZoneName: "never"
|
||||
|
|
|
@ -7,7 +7,7 @@ description: Temporal.ZonedDateTime.prototype.until()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[Europe/Vienna]");
|
||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||
|
||||
// zdt.until(later) === later.since(zdt) with default options
|
||||
var later = Temporal.ZonedDateTime.from({
|
||||
|
@ -15,7 +15,7 @@ var later = Temporal.ZonedDateTime.from({
|
|||
month: 3,
|
||||
day: 3,
|
||||
hour: 18,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
});
|
||||
assert.sameValue(`${ zdt.until(later) }`, `${ later.since(zdt) }`);
|
||||
|
||||
|
@ -25,18 +25,18 @@ assert.sameValue(`${ zdt.until({
|
|||
month: 10,
|
||||
day: 29,
|
||||
hour: 10,
|
||||
timeZone: "Europe/Vienna"
|
||||
timeZone: "+01:00"
|
||||
}) }`, "PT376434H36M29.876543211S");
|
||||
assert.sameValue(`${ zdt.until("2019-10-29T10:46:38.271986102+01:00[Europe/Vienna]") }`, "PT376435H23M8.148529313S");
|
||||
var feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[Europe/Vienna]");
|
||||
var feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[Europe/Vienna]");
|
||||
assert.sameValue(`${ zdt.until("2019-10-29T10:46:38.271986102+01:00[+01:00]") }`, "PT376435H23M8.148529313S");
|
||||
var feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
||||
var feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
||||
|
||||
// defaults to returning hours
|
||||
assert.sameValue(`${ feb20.until(feb21) }`, "PT8784H");
|
||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "auto" }) }`, "PT8784H");
|
||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "hours" }) }`, "PT8784H");
|
||||
assert.sameValue(`${ feb20.until(Temporal.ZonedDateTime.from("2021-02-01T00:00:00.000000001+01:00[Europe/Vienna]")) }`, "PT8784H0.000000001S");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2020-02-01T00:00:00.000000001+01:00[Europe/Vienna]").until(feb21) }`, "PT8783H59M59.999999999S");
|
||||
assert.sameValue(`${ feb20.until(Temporal.ZonedDateTime.from("2021-02-01T00:00:00.000000001+01:00[+01:00]")) }`, "PT8784H0.000000001S");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2020-02-01T00:00:00.000000001+01:00[+01:00]").until(feb21) }`, "PT8783H59M59.999999999S");
|
||||
|
||||
// can return lower or higher units
|
||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "years" }) }`, "P1Y");
|
||||
|
@ -67,8 +67,8 @@ assert.sameValue(nsDiff.microseconds, 0);
|
|||
assert.sameValue(nsDiff.nanoseconds, 86400250250250);
|
||||
|
||||
// does not include higher units than necessary
|
||||
var lastFeb20 = Temporal.ZonedDateTime.from("2020-02-29T00:00+01:00[Europe/Vienna]");
|
||||
var lastJan21 = Temporal.ZonedDateTime.from("2021-01-31T00:00+01:00[Europe/Vienna]");
|
||||
var lastFeb20 = Temporal.ZonedDateTime.from("2020-02-29T00:00+01:00[+01:00]");
|
||||
var lastJan21 = Temporal.ZonedDateTime.from("2021-01-31T00:00+01:00[+01:00]");
|
||||
assert.sameValue(`${ lastFeb20.until(lastJan21) }`, "PT8088H");
|
||||
assert.sameValue(`${ lastFeb20.until(lastJan21, { largestUnit: "months" }) }`, "P11M2D");
|
||||
assert.sameValue(`${ lastFeb20.until(lastJan21, { largestUnit: "years" }) }`, "P11M2D");
|
||||
|
@ -87,11 +87,12 @@ assert.notSameValue(monthsDifference.months, 0);
|
|||
|
||||
// no two different calendars
|
||||
var zdt1 = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", Temporal.Calendar.from("japanese"));
|
||||
var fakeJapanese = { toString() { return "japanese"; }};
|
||||
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", fakeJapanese);
|
||||
assert.throws(RangeError, () => zdt1.until(zdt2));
|
||||
|
||||
var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[Europe/Vienna]');
|
||||
var later = Temporal.ZonedDateTime.from('2021-09-07T14:39:40.987654321+02:00[Europe/Vienna]');
|
||||
var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
||||
var later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
||||
// assumes a different default for largestUnit if smallestUnit is larger than hours
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
smallestUnit: "years",
|
||||
|
|
|
@ -240,7 +240,7 @@ assert.sameValue(`${ zdt.with({
|
|||
// throws if timeZone is included
|
||||
assert.throws(TypeError, () => zdt.with({
|
||||
month: 2,
|
||||
timeZone: "Asia/Ulaanbaatar"
|
||||
timeZone: "UTC"
|
||||
}));
|
||||
|
||||
// throws if given a Temporal object with a time zone
|
||||
|
@ -249,7 +249,7 @@ assert.throws(TypeError, () => zdt.with(dstStartDay));
|
|||
// throws if calendarName is included
|
||||
assert.throws(TypeError, () => zdt.with({
|
||||
month: 2,
|
||||
calendar: "japanese"
|
||||
calendar: "iso8601"
|
||||
}));
|
||||
|
||||
// throws if given a Temporal object with a calendar
|
||||
|
|
|
@ -7,15 +7,15 @@ description: Temporal.ZonedDateTime.prototype.withCalendar()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789-08:00[America/Los_Angeles]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789-08:00[-08:00]");
|
||||
|
||||
// zonedDateTime.withCalendar(japanese) works
|
||||
var cal = Temporal.Calendar.from("japanese");
|
||||
assert.sameValue(`${ zdt.withCalendar(cal) }`, "2019-11-18T15:23:30.123456789-08:00[America/Los_Angeles][u-ca=japanese]");
|
||||
var cal = { toString() { return "japanese"; }};
|
||||
assert.sameValue(`${ zdt.withCalendar(cal) }`, "2019-11-18T15:23:30.123456789-08:00[-08:00][u-ca=japanese]");
|
||||
|
||||
// keeps instant and time zone the same
|
||||
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[Europe/Madrid][u-ca=gregory]");
|
||||
var zdt2 = zdt.withCalendar("japanese");
|
||||
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00][u-ca=iso8601]");
|
||||
var zdt2 = zdt.withCalendar(cal);
|
||||
assert.sameValue(zdt.epochNanoseconds, zdt2.epochNanoseconds);
|
||||
assert.sameValue(zdt2.calendar.id, "japanese");
|
||||
assert.sameValue(zdt2.timeZone.id, "Europe/Madrid");
|
||||
assert.sameValue(zdt2.calendar, cal);
|
||||
assert.sameValue(zdt2.timeZone.id, "+01:00");
|
||||
|
|
|
@ -7,20 +7,20 @@ description: .withPlainTime manipulation
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt = Temporal.ZonedDateTime.from("2015-12-07T03:24:30.000003500[America/Los_Angeles]");
|
||||
var zdt = Temporal.ZonedDateTime.from("2015-12-07T03:24:30.000003500[-08:00]");
|
||||
|
||||
// withPlainTime({ hour: 10 }) works
|
||||
assert.sameValue(`${ zdt.withPlainTime({ hour: 10 }) }`, "2015-12-07T10:00:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ zdt.withPlainTime({ hour: 10 }) }`, "2015-12-07T10:00:00-08:00[-08:00]");
|
||||
|
||||
// withPlainTime(time) works
|
||||
var time = Temporal.PlainTime.from("11:22");
|
||||
assert.sameValue(`${ zdt.withPlainTime(time) }`, "2015-12-07T11:22:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ zdt.withPlainTime(time) }`, "2015-12-07T11:22:00-08:00[-08:00]");
|
||||
|
||||
// withPlainTime('12:34') works
|
||||
assert.sameValue(`${ zdt.withPlainTime("12:34") }`, "2015-12-07T12:34:00-08:00[America/Los_Angeles]");
|
||||
assert.sameValue(`${ zdt.withPlainTime("12:34") }`, "2015-12-07T12:34:00-08:00[-08:00]");
|
||||
|
||||
// incorrectly-spelled properties are ignored
|
||||
assert.sameValue(`${ zdt.withPlainTime({
|
||||
hour: 10,
|
||||
seconds: 55
|
||||
}) }`, "2015-12-07T10:00:00-08:00[America/Los_Angeles]");
|
||||
}) }`, "2015-12-07T10:00:00-08:00[-08:00]");
|
||||
|
|
|
@ -7,14 +7,11 @@ description: Temporal.ZonedDateTime.prototype.withTimeZone()
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = new Temporal.TimeZone("America/Los_Angeles");
|
||||
var instant = Temporal.Instant.from("2019-11-18T15:23:30.123456789-08:00[America/Los_Angeles]");
|
||||
var zdt = instant.toZonedDateTimeISO("UTC");
|
||||
|
||||
// keeps instant and calendar the same
|
||||
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[Europe/Madrid][u-ca=gregory]");
|
||||
var zdt2 = zdt.withTimeZone("America/Vancouver");
|
||||
var fakeGregorian = { toString() { return "gregory"; }};
|
||||
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00]").withCalendar(fakeGregorian);
|
||||
var zdt2 = zdt.withTimeZone("-08:00");
|
||||
assert.sameValue(zdt.epochNanoseconds, zdt2.epochNanoseconds);
|
||||
assert.sameValue(zdt2.calendar.id, "gregory");
|
||||
assert.sameValue(zdt2.timeZone.id, "America/Vancouver");
|
||||
assert.sameValue(zdt2.calendar, fakeGregorian);
|
||||
assert.sameValue(zdt2.timeZone.id, "-08:00");
|
||||
assert.notSameValue(`${ zdt.toPlainDateTime() }`, `${ zdt2.toPlainDateTime() }`);
|
||||
|
|
Loading…
Reference in New Issue