mirror of https://github.com/tc39/test262.git
Temporal: Remove fake West Coast and Samoa time zones from TemporalHelpers
It's no longer possible to fake built-in time zones using custom objects. So testing DST shifts will have to use real built-in time zones. Replace TemporalHelpers.springForwardFallBackTimeZone with America/Vancouver (it was modelled on the DST transitions in 2000) and TemporalHelpers.crossDateLineTimeZone with Pacific/Apia (it was modelled on the 2011 switch to the other side of the international date line.) These tests have to move to the intl402/ folder since non-Intl-aware implementations are allowed (but not required) to support any built-in time zones other than UTC.
This commit is contained in:
parent
c728e6d89e
commit
7d970fbe4e
|
@ -1389,66 +1389,6 @@ var TemporalHelpers = {
|
|||
return new CalendarWithExtraFields(fields);
|
||||
},
|
||||
|
||||
/*
|
||||
* crossDateLineTimeZone():
|
||||
*
|
||||
* This returns an instance of a custom time zone class that implements one
|
||||
* single transition where the time zone moves from one side of the
|
||||
* International Date Line to the other, for the purpose of testing time zone
|
||||
* calculations without depending on system time zone data.
|
||||
*
|
||||
* The transition occurs at epoch second 1325239200 and goes from offset
|
||||
* -10:00 to +14:00. In other words, the time zone skips the whole calendar
|
||||
* day of 2011-12-30. This is the same as the real-life transition in the
|
||||
* Pacific/Apia time zone.
|
||||
*/
|
||||
crossDateLineTimeZone() {
|
||||
const { compare } = Temporal.PlainDate;
|
||||
const skippedDay = new Temporal.PlainDate(2011, 12, 30);
|
||||
const transitionEpoch = 1325239200_000_000_000n;
|
||||
const beforeOffset = new Temporal.TimeZone("-10:00");
|
||||
const afterOffset = new Temporal.TimeZone("+14:00");
|
||||
|
||||
class CrossDateLineTimeZone extends Temporal.TimeZone {
|
||||
constructor() {
|
||||
super("+14:00");
|
||||
}
|
||||
|
||||
getOffsetNanosecondsFor(instant) {
|
||||
if (instant.epochNanoseconds < transitionEpoch) {
|
||||
return beforeOffset.getOffsetNanosecondsFor(instant);
|
||||
}
|
||||
return afterOffset.getOffsetNanosecondsFor(instant);
|
||||
}
|
||||
|
||||
getPossibleInstantsFor(datetime) {
|
||||
const comparison = compare(datetime.toPlainDate(), skippedDay);
|
||||
if (comparison === 0) {
|
||||
return [];
|
||||
}
|
||||
if (comparison < 0) {
|
||||
return [beforeOffset.getInstantFor(datetime)];
|
||||
}
|
||||
return [afterOffset.getInstantFor(datetime)];
|
||||
}
|
||||
|
||||
getPreviousTransition(instant) {
|
||||
if (instant.epochNanoseconds > transitionEpoch) return new Temporal.Instant(transitionEpoch);
|
||||
return null;
|
||||
}
|
||||
|
||||
getNextTransition(instant) {
|
||||
if (instant.epochNanoseconds < transitionEpoch) return new Temporal.Instant(transitionEpoch);
|
||||
return null;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return "Custom/Date_Line";
|
||||
}
|
||||
}
|
||||
return new CrossDateLineTimeZone();
|
||||
},
|
||||
|
||||
/*
|
||||
* observeProperty(calls, object, propertyName, value):
|
||||
*
|
||||
|
@ -1846,77 +1786,6 @@ var TemporalHelpers = {
|
|||
return new SpecificOffsetTimeZone(offsetValue);
|
||||
},
|
||||
|
||||
/*
|
||||
* springForwardFallBackTimeZone():
|
||||
*
|
||||
* This returns an instance of a custom time zone class that implements one
|
||||
* single spring-forward/fall-back transition, for the purpose of testing the
|
||||
* disambiguation option, without depending on system time zone data.
|
||||
*
|
||||
* The spring-forward occurs at epoch second 954669600 (2000-04-02T02:00
|
||||
* local) and goes from offset -08:00 to -07:00.
|
||||
*
|
||||
* The fall-back occurs at epoch second 972810000 (2000-10-29T02:00 local) and
|
||||
* goes from offset -07:00 to -08:00.
|
||||
*/
|
||||
springForwardFallBackTimeZone() {
|
||||
const { compare } = Temporal.PlainDateTime;
|
||||
const springForwardLocal = new Temporal.PlainDateTime(2000, 4, 2, 2);
|
||||
const springForwardEpoch = 954669600_000_000_000n;
|
||||
const fallBackLocal = new Temporal.PlainDateTime(2000, 10, 29, 1);
|
||||
const fallBackEpoch = 972810000_000_000_000n;
|
||||
const winterOffset = new Temporal.TimeZone('-08:00');
|
||||
const summerOffset = new Temporal.TimeZone('-07:00');
|
||||
|
||||
class SpringForwardFallBackTimeZone extends Temporal.TimeZone {
|
||||
constructor() {
|
||||
super("-08:00");
|
||||
}
|
||||
|
||||
getOffsetNanosecondsFor(instant) {
|
||||
if (instant.epochNanoseconds < springForwardEpoch ||
|
||||
instant.epochNanoseconds >= fallBackEpoch) {
|
||||
return winterOffset.getOffsetNanosecondsFor(instant);
|
||||
}
|
||||
return summerOffset.getOffsetNanosecondsFor(instant);
|
||||
}
|
||||
|
||||
getPossibleInstantsFor(datetime) {
|
||||
if (compare(datetime, springForwardLocal) >= 0 && compare(datetime, springForwardLocal.add({ hours: 1 })) < 0) {
|
||||
return [];
|
||||
}
|
||||
if (compare(datetime, fallBackLocal) >= 0 && compare(datetime, fallBackLocal.add({ hours: 1 })) < 0) {
|
||||
return [summerOffset.getInstantFor(datetime), winterOffset.getInstantFor(datetime)];
|
||||
}
|
||||
if (compare(datetime, springForwardLocal) < 0 || compare(datetime, fallBackLocal) >= 0) {
|
||||
return [winterOffset.getInstantFor(datetime)];
|
||||
}
|
||||
return [summerOffset.getInstantFor(datetime)];
|
||||
}
|
||||
|
||||
getPreviousTransition(instant) {
|
||||
if (instant.epochNanoseconds > fallBackEpoch) return new Temporal.Instant(fallBackEpoch);
|
||||
if (instant.epochNanoseconds > springForwardEpoch) return new Temporal.Instant(springForwardEpoch);
|
||||
return null;
|
||||
}
|
||||
|
||||
getNextTransition(instant) {
|
||||
if (instant.epochNanoseconds < springForwardEpoch) return new Temporal.Instant(springForwardEpoch);
|
||||
if (instant.epochNanoseconds < fallBackEpoch) return new Temporal.Instant(fallBackEpoch);
|
||||
return null;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return "Custom/Spring_Fall";
|
||||
}
|
||||
|
||||
toString() {
|
||||
return "Custom/Spring_Fall";
|
||||
}
|
||||
}
|
||||
return new SpringForwardFallBackTimeZone();
|
||||
},
|
||||
|
||||
/*
|
||||
* timeZoneObserver:
|
||||
* A custom calendar that behaves exactly like the UTC time zone but tracks
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
/*---
|
||||
esid: sec-temporal.duration.compare
|
||||
description: relativeTo with hours.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -23,19 +22,3 @@ assert.sameValue(Temporal.Duration.compare(oneDay, hours24, { relativeTo: "2019-
|
|||
assert.sameValue(Temporal.Duration.compare(oneDay, hours24, { relativeTo: { year: 2019, month: 11, day: 3 } }),
|
||||
0,
|
||||
"casts relativeTo to PlainDate from object");
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
assert.sameValue(
|
||||
Temporal.Duration.compare(oneDay, hours24, { relativeTo: new Temporal.ZonedDateTime(0n, timeZone) }),
|
||||
0,
|
||||
'relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change');
|
||||
assert.sameValue(
|
||||
Temporal.Duration.compare(oneDay, hours24, { relativeTo: new Temporal.ZonedDateTime(972802800_000_000_000n, timeZone) }),
|
||||
1,
|
||||
'relativeTo does affect days if ZonedDateTime, and duration encompasses DST change');
|
||||
assert.sameValue(
|
||||
Temporal.Duration.compare(oneDay, hours24, {
|
||||
relativeTo: { year: 2000, month: 10, day: 29, timeZone }
|
||||
}),
|
||||
1,
|
||||
'casts relativeTo to ZonedDateTime from object');
|
||||
|
|
|
@ -5,17 +5,14 @@
|
|||
esid: sec-temporal.duration.compare
|
||||
description: Unbalancing handles DST days with more than 24 hours
|
||||
features: [Temporal]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const tz = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
// 2000-10-29 is a 25-hour day according to this time zone...
|
||||
|
||||
const relativeTo = new Temporal.ZonedDateTime(941187600_000_000_000n, tz);
|
||||
const relativeTo = new Temporal.ZonedDateTime(941184000_000_000_000n, "America/Vancouver");
|
||||
|
||||
// confirm that we have rewound one year and one day:
|
||||
assert.sameValue('1999-10-29T01:00:00-08:00[Custom/Spring_Fall]', relativeTo.toString());
|
||||
assert.sameValue('1999-10-29T01:00:00-07:00[America/Vancouver]', relativeTo.toString());
|
||||
|
||||
const d1 = new Temporal.Duration(1, 0, 0, 1);
|
||||
const d2 = new Temporal.Duration(1, 0, 0, 0, 25);
|
|
@ -9,14 +9,12 @@ includes: [temporalHelpers.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
// Based on a test case by Adam Shaw
|
||||
{
|
||||
const duration = new Temporal.Duration(1, 0, 0, 0, 24);
|
||||
const relativeTo = new Temporal.ZonedDateTime(
|
||||
941184000_000_000_000n /* = 1999-10-29T08Z */,
|
||||
timeZone); /* = 1999-10-29T00-08 in local time */
|
||||
"America/Vancouver"); /* = 1999-10-29T00-08 in local time */
|
||||
|
||||
const result = duration.round({ largestUnit: "years", relativeTo });
|
||||
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0,
|
||||
|
@ -27,7 +25,7 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
|||
const duration = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 24, 0, 0, 0, 0, /* ns = */ 5);
|
||||
const relativeTo = new Temporal.ZonedDateTime(
|
||||
972802800_000_000_000n /* = 2000-10-29T07Z */,
|
||||
timeZone); /* = 2000-10-29T00-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-29T00-07 in local time */
|
||||
|
||||
const result = duration.round({
|
||||
largestUnit: "days",
|
|
@ -9,8 +9,6 @@ includes: [temporalHelpers.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
// Based on a test case by Adam Shaw
|
||||
|
||||
{
|
||||
|
@ -18,7 +16,7 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
|||
const duration = new Temporal.Duration(0, 1, 0, 15, 11, 30);
|
||||
const relativeTo = new Temporal.ZonedDateTime(
|
||||
950868000_000_000_000n /* = 2000-02-18T10Z */,
|
||||
timeZone); /* = 2000-02-18T02-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-02-18T02-08 in local time */
|
||||
|
||||
TemporalHelpers.assertDuration(duration.round({ smallestUnit: "months", relativeTo }),
|
||||
0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -33,7 +31,7 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
|||
const duration = new Temporal.Duration(0, 1, 0, 15, 0, 30);
|
||||
const relativeTo = new Temporal.ZonedDateTime(
|
||||
951991200_000_000_000n /* = 2000-03-02T10Z */,
|
||||
timeZone); /* = 2000-03-02T02-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-03-02T02-08 in local time */
|
||||
|
||||
TemporalHelpers.assertDuration(duration.round({ smallestUnit: "months", relativeTo }),
|
||||
0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -48,8 +46,7 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
|||
// DST spring-forward hour skipped at 2000-04-02T02:00 (23 hour day)
|
||||
// 11.5 hours is 0.5
|
||||
const duration = new Temporal.Duration(0, 0, 0, 0, 11, 30);
|
||||
const instant = timeZone.getPossibleInstantsFor(Temporal.PlainDateTime.from("2000-04-02T00:00:00"))[0];
|
||||
const relativeTo = instant.toZonedDateTimeISO(timeZone);
|
||||
const relativeTo = new Temporal.PlainDateTime(2000, 4, 2).toZonedDateTime("America/Vancouver");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
duration.round({ relativeTo, smallestUnit: "days" }),
|
|
@ -5,17 +5,15 @@ esid: sec-temporal.duration.prototype.total
|
|||
description: >
|
||||
Balancing the resulting duration takes the time zone's UTC offset shifts
|
||||
into account
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// Based on a test case by Adam Shaw
|
||||
|
||||
const duration = new Temporal.Duration(1, 0, 0, 0, 24);
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
const relativeTo = new Temporal.ZonedDateTime(
|
||||
941184000_000_000_000n /* = 1999-10-29T08Z */,
|
||||
timeZone); /* = 1999-10-29T00-08 in local time */
|
||||
"America/Vancouver"); /* = 1999-10-29T00-08 in local time */
|
||||
|
||||
const result = duration.total({ unit: "days", relativeTo });
|
||||
assert.sameValue(result, 366.96, "24 hours does not balance to 1 day in 25-hour day");
|
|
@ -5,7 +5,6 @@ esid: sec-temporal.duration.prototype.total
|
|||
description: >
|
||||
ZonedDateTime relativeTo affects day length when the duration encompasses a
|
||||
DST change
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -17,38 +16,36 @@ const hours25 = new Temporal.Duration(0, 0, 0, 0, 25);
|
|||
const hours25Neg = new Temporal.Duration(0, 0, 0, 0, -25);
|
||||
const hours48 = new Temporal.Duration(0, 0, 0, 0, 48);
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
const skippedHourDay = new Temporal.ZonedDateTime(
|
||||
954662400_000_000_000n /* = 2000-04-02T08Z */,
|
||||
timeZone); /* = 2000-04-02T00-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-04-02T00-08 in local time */
|
||||
const repeatedHourDay = new Temporal.ZonedDateTime(
|
||||
972802800_000_000_000n /* = 2000-10-29T07Z */,
|
||||
timeZone); /* = 2000-10-29T00-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-29T00-07 in local time */
|
||||
const inRepeatedHour = new Temporal.ZonedDateTime(
|
||||
972806400_000_000_000n /* = 2000-10-29T08Z */,
|
||||
timeZone); /* = 2000-10-29T01-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-29T01-07 in local time */
|
||||
const oneDayAfterRepeatedHour = new Temporal.ZonedDateTime(
|
||||
972896400_000_000_000n /* = 2000-10-30T09Z */,
|
||||
timeZone); /* = 2000-10-30T01-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-30T01-08 in local time */
|
||||
const beforeSkippedHour = new Temporal.ZonedDateTime(
|
||||
954585000_000_000_000n /* = 2000-04-01T10:30Z */,
|
||||
timeZone); /* = 2000-04-01T02:30-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-04-01T02:30-08 in local time */
|
||||
const dayAfterSkippedHour = new Temporal.ZonedDateTime(
|
||||
954745200_000_000_000n /* = 2000-04-03T07Z */,
|
||||
timeZone); /* = 2000-04-03T00-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-04-03T00-07 in local time */
|
||||
const afterSkippedHour = new Temporal.ZonedDateTime(
|
||||
954702000_000_000_000n /* = 2000-04-02T19Z */,
|
||||
timeZone); /* = 2000-04-02T12-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-04-02T12-07 in local time */
|
||||
const afterRepeatedHour = new Temporal.ZonedDateTime(
|
||||
972892800_000_000_000n /* = 2000-10-30T08Z */,
|
||||
timeZone); /* = 2000-10-30T00-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-30T00-08 in local time */
|
||||
const afterRepeatedHourSameDay = new Temporal.ZonedDateTime(
|
||||
972849600_000_000_000n /* = 2000-10-29T20Z */,
|
||||
timeZone); /* = 2000-10-29T12-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-29T12-08 in local time */
|
||||
const beforeRepeatedHour = new Temporal.ZonedDateTime(
|
||||
972716400_000_000_000n /* = 2000-10-28T07Z */,
|
||||
timeZone); /* = 2000-10-28T00-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-28T00-07 in local time */
|
||||
|
||||
assert.sameValue(hours25.total({
|
||||
unit: "days",
|
|
@ -5,12 +5,9 @@ esid: sec-temporal.duration.prototype.total
|
|||
description: >
|
||||
Rounding the resulting duration takes the time zone's UTC offset shifts
|
||||
into account
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
// Based on a test case by Adam Shaw
|
||||
|
||||
{
|
||||
|
@ -18,7 +15,7 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
|||
const duration = new Temporal.Duration(0, 1, 0, 15, 11, 30);
|
||||
const relativeTo = new Temporal.ZonedDateTime(
|
||||
950868000_000_000_000n /* = 2000-02-18T10Z */,
|
||||
timeZone); /* = 2000-02-18T02-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-02-18T02-08 in local time */
|
||||
|
||||
assert.sameValue(duration.total({ unit: "months", relativeTo }), 1.5,
|
||||
"1 month 15 days 11:30 should be exactly 1.5 months");
|
||||
|
@ -30,7 +27,7 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
|||
const duration = new Temporal.Duration(0, 1, 0, 15, 0, 30);
|
||||
const relativeTo = new Temporal.ZonedDateTime(
|
||||
951991200_000_000_000n /* = 2000-03-02T10Z */,
|
||||
timeZone); /* = 2000-03-02T02-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-03-02T02-08 in local time */
|
||||
|
||||
assert.sameValue(duration.total({ unit: "months", relativeTo }), 1.5,
|
||||
"1 month 15 days 00:30 should be exactly 1.5 months");
|
|
@ -11,11 +11,10 @@ info: |
|
|||
1. Return ? GetOption(_normalizedOptions_, *"disambiguation"*, « String », « *"compatible"*, *"earlier"*, *"later"*, *"reject"* », *"compatible"*).
|
||||
sec-temporal.plaindatetime.prototype.tozoneddatetime step 5:
|
||||
5. Let _disambiguation_ be ? ToTemporalDisambiguation(_options_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
const timeZone = "America/Vancouver";
|
||||
const springForwardDatetime = new Temporal.PlainDateTime(2000, 4, 2, 2, 30);
|
||||
const fallBackDatetime = new Temporal.PlainDateTime(2000, 10, 29, 1, 30);
|
||||
|
|
@ -5,10 +5,9 @@
|
|||
esid: sec-temporal.plaindatetime.prototype.tozoneddatetime
|
||||
description: Checking disambiguation options for daylight savings time changes
|
||||
features: [Temporal]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const tz = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
const tz = "America/Vancouver";
|
||||
|
||||
const dt1 = new Temporal.PlainDateTime(2000, 4, 2, 2);
|
||||
|
|
@ -3,14 +3,13 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.tozoneddatetime
|
||||
includes: [temporalHelpers.js]
|
||||
description: Verify that undefined options are handled correctly.
|
||||
features: [BigInt, Temporal]
|
||||
---*/
|
||||
|
||||
const datetimeEarlier = new Temporal.PlainDateTime(2000, 10, 29, 1, 34, 56, 987, 654, 321);
|
||||
const datetimeLater = new Temporal.PlainDateTime(2000, 4, 2, 2, 34, 56, 987, 654, 321);
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
const timeZone = "America/Vancouver";
|
||||
|
||||
[
|
||||
[datetimeEarlier, 972808496987654321n],
|
|
@ -16,13 +16,11 @@ info: |
|
|||
...
|
||||
d. Return ...
|
||||
3. Return ? ToTemporalZonedDateTime(_item_, _options_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
const springForwardFields = { timeZone, year: 2000, month: 4, day: 2, hour: 2, minute: 30 };
|
||||
const fallBackFields = { timeZone, year: 2000, month: 10, day: 29, hour: 1, minute: 30 };
|
||||
const springForwardFields = { timeZone: "America/Vancouver", year: 2000, month: 4, day: 2, hour: 2, minute: 30 };
|
||||
const fallBackFields = { timeZone: "America/Vancouver", year: 2000, month: 10, day: 29, hour: 1, minute: 30 };
|
||||
|
||||
[
|
||||
[springForwardFields, 954671400_000_000_000n],
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
includes: [temporalHelpers.js]
|
||||
description: Verify that undefined options are handled correctly.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
@ -19,7 +18,7 @@ assert.sameValue(overflowPropertyImplicit.month, 12, "default overflow is constr
|
|||
const overflowImplicit = Temporal.ZonedDateTime.from(overflowFields);
|
||||
assert.sameValue(overflowImplicit.month, 12, "default overflow is constrain");
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
const timeZone = "America/Vancouver";
|
||||
const disambiguationEarlierFields = { timeZone, year: 2000, month: 10, day: 29, hour: 1, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 };
|
||||
const disambiguationLaterFields = { timeZone, year: 2000, month: 4, day: 2, hour: 2, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 };
|
||||
|
|
@ -9,18 +9,16 @@ includes: [temporalHelpers.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
// Based on a test case by Adam Shaw
|
||||
{
|
||||
const start = new Temporal.ZonedDateTime(
|
||||
941184000_000_000_000n /* = 1999-10-29T08Z */,
|
||||
timeZone); /* = 1999-10-29T00-08 in local time */
|
||||
949132800_000_000_000n /* = 2000-01-29T08Z */,
|
||||
"America/Vancouver"); /* = 2000-01-29T00-08 in local time */
|
||||
const end = new Temporal.ZonedDateTime(
|
||||
972889200_000_000_000n /* = 2000-10-30T07Z */,
|
||||
timeZone); /* = 2000-10-29T23-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-29T23-08 in local time */
|
||||
|
||||
const duration = start.since(end, { largestUnit: "years" });
|
||||
TemporalHelpers.assertDuration(duration, -1, 0, 0, 0, -24, 0, 0, 0, 0, 0,
|
||||
TemporalHelpers.assertDuration(duration, 0, -9, 0, 0, -24, 0, 0, 0, 0, 0,
|
||||
"24 hours does not balance to 1 day in 25-hour day");
|
||||
}
|
|
@ -12,10 +12,8 @@ features: [Temporal]
|
|||
|
||||
// Based on a test case by Adam Shaw
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
const d1 = new Temporal.ZonedDateTime(957258000_000_000_000n /* = 2000-05-02T02:00-07:00 */, timeZone);
|
||||
const d2 = new Temporal.ZonedDateTime(954669600_000_000_000n /* = 2000-04-02T03:00-07:00 */, timeZone);
|
||||
const d1 = new Temporal.ZonedDateTime(957258000_000_000_000n /* = 2000-05-02T02:00-07:00 */, "America/Vancouver");
|
||||
const d2 = new Temporal.ZonedDateTime(954669600_000_000_000n /* = 2000-04-02T03:00-07:00 */, "America/Vancouver");
|
||||
// NOTE: nonexistent hour just before d2
|
||||
|
||||
const result = d1.since(d2, { largestUnit: "months" });
|
|
@ -11,17 +11,15 @@ features: [Temporal]
|
|||
|
||||
// Based on a test case by Adam Shaw
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
{
|
||||
// Month-only part of duration lands on skipped DST hour, should not cause
|
||||
// disambiguation
|
||||
const start = new Temporal.ZonedDateTime(
|
||||
950868000_000_000_000n /* = 2000-02-18T10Z */,
|
||||
timeZone); /* = 2000-02-18T02-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-02-18T02-08 in local time */
|
||||
const end = new Temporal.ZonedDateTime(
|
||||
954709200_000_000_000n /* = 2000-04-02T21Z */,
|
||||
timeZone); /* = 2000-04-02T14-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-04-02T14-07 in local time */
|
||||
|
||||
const duration = start.since(end, { largestUnit: "months" });
|
||||
TemporalHelpers.assertDuration(duration, 0, -1, 0, -15, -11, 0, 0, 0, 0, 0,
|
||||
|
@ -34,10 +32,10 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
|||
// disambiguation
|
||||
const start = new Temporal.ZonedDateTime(
|
||||
951991200_000_000_000n /* = 2000-03-02T10Z */,
|
||||
timeZone); /* = 2000-03-02T02-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-03-02T02-08 in local time */
|
||||
const end = new Temporal.ZonedDateTime(
|
||||
956005200_000_000_000n /* = 2000-04-17T21Z */,
|
||||
timeZone); /* = 2000-04-17T14-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-04-17T14-07 in local time */
|
||||
|
||||
const duration = start.since(end, { largestUnit: "months" });
|
||||
TemporalHelpers.assertDuration(duration, 0, -1, 0, -15, -12, 0, 0, 0, 0, 0,
|
|
@ -9,18 +9,16 @@ includes: [temporalHelpers.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
// Based on a test case by Adam Shaw
|
||||
{
|
||||
const start = new Temporal.ZonedDateTime(
|
||||
941184000_000_000_000n /* = 1999-10-29T08Z */,
|
||||
timeZone); /* = 1999-10-29T00-08 in local time */
|
||||
949132800_000_000_000n /* = 2000-01-29T08Z */,
|
||||
"America/Vancouver"); /* = 2000-01-29T00-08 in local time */
|
||||
const end = new Temporal.ZonedDateTime(
|
||||
972889200_000_000_000n /* = 2000-10-30T07Z */,
|
||||
timeZone); /* = 2000-10-29T23-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-10-29T23-08 in local time */
|
||||
|
||||
const duration = start.until(end, { largestUnit: "years" });
|
||||
TemporalHelpers.assertDuration(duration, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0,
|
||||
TemporalHelpers.assertDuration(duration, 0, 9, 0, 0, 24, 0, 0, 0, 0, 0,
|
||||
"24 hours does not balance to 1 day in 25-hour day");
|
||||
}
|
|
@ -12,10 +12,8 @@ features: [Temporal]
|
|||
|
||||
// Based on a test case by Adam Shaw
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
const d1 = new Temporal.ZonedDateTime(957258000_000_000_000n /* = 2000-05-02T02:00-07:00 */, timeZone);
|
||||
const d2 = new Temporal.ZonedDateTime(954669600_000_000_000n /* = 2000-04-02T03:00-07:00 */, timeZone);
|
||||
const d1 = new Temporal.ZonedDateTime(957258000_000_000_000n /* = 2000-05-02T02:00-07:00 */, "America/Vancouver");
|
||||
const d2 = new Temporal.ZonedDateTime(954669600_000_000_000n /* = 2000-04-02T03:00-07:00 */, "America/Vancouver");
|
||||
// NOTE: nonexistent hour just before d2
|
||||
|
||||
const result = d1.until(d2, { largestUnit: "months" });
|
|
@ -11,17 +11,15 @@ features: [Temporal]
|
|||
|
||||
// Based on a test case by Adam Shaw
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
{
|
||||
// Month-only part of duration lands on skipped DST hour, should not cause
|
||||
// disambiguation
|
||||
const start = new Temporal.ZonedDateTime(
|
||||
950868000_000_000_000n /* = 2000-02-18T10Z */,
|
||||
timeZone); /* = 2000-02-18T02-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-02-18T02-08 in local time */
|
||||
const end = new Temporal.ZonedDateTime(
|
||||
954709200_000_000_000n /* = 2000-04-02T21Z */,
|
||||
timeZone); /* = 2000-04-02T14-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-04-02T14-07 in local time */
|
||||
|
||||
const duration = start.until(end, { largestUnit: "months" });
|
||||
TemporalHelpers.assertDuration(duration, 0, 1, 0, 15, 11, 0, 0, 0, 0, 0,
|
||||
|
@ -34,10 +32,10 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
|||
// disambiguation
|
||||
const start = new Temporal.ZonedDateTime(
|
||||
951991200_000_000_000n /* = 2000-03-02T10Z */,
|
||||
timeZone); /* = 2000-03-02T02-08 in local time */
|
||||
"America/Vancouver"); /* = 2000-03-02T02-08 in local time */
|
||||
const end = new Temporal.ZonedDateTime(
|
||||
956005200_000_000_000n /* = 2000-04-17T21Z */,
|
||||
timeZone); /* = 2000-04-17T14-07 in local time */
|
||||
"America/Vancouver"); /* = 2000-04-17T14-07 in local time */
|
||||
|
||||
const duration = start.until(end, { largestUnit: "months" });
|
||||
TemporalHelpers.assertDuration(duration, 0, 1, 0, 15, 12, 0, 0, 0, 0, 0,
|
|
@ -11,13 +11,11 @@ info: |
|
|||
1. Return ? GetOption(_normalizedOptions_, *"disambiguation"*, « String », « *"compatible"*, *"earlier"*, *"later"*, *"reject"* », *"compatible"*).
|
||||
sec-temporal.zoneddatetime.protoype.with step 14:
|
||||
14. Let _disambiguation_ be ? ToTemporalDisambiguation(_options_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
const springForwardDatetime = new Temporal.ZonedDateTime(954702001_000_000_000n, timeZone);
|
||||
const fallBackDatetime = new Temporal.ZonedDateTime(972849601_000_000_000n, timeZone);
|
||||
const springForwardDatetime = new Temporal.ZonedDateTime(954702001_000_000_000n, "America/Vancouver");
|
||||
const fallBackDatetime = new Temporal.ZonedDateTime(972849601_000_000_000n, "America/Vancouver");
|
||||
const offset = "ignore";
|
||||
|
||||
[
|
|
@ -4,13 +4,11 @@
|
|||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: math around DST
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
var hourBeforeDstStart = new Temporal.PlainDateTime(2000, 4, 2, 1).toZonedDateTime(tz);
|
||||
var dayBeforeDstStart = new Temporal.PlainDateTime(2000, 4, 1, 2, 30).toZonedDateTime(tz);
|
||||
var hourBeforeDstStart = new Temporal.PlainDateTime(2000, 4, 2, 1).toZonedDateTime("America/Vancouver");
|
||||
var dayBeforeDstStart = new Temporal.PlainDateTime(2000, 4, 1, 2, 30).toZonedDateTime("America/Vancouver");
|
||||
|
||||
// add 1 hour to get to DST start
|
||||
var added = hourBeforeDstStart.add({ hours: 1 });
|
||||
|
@ -44,9 +42,7 @@ var undo = added.subtract(diff);
|
|||
assert.sameValue(`${ undo }`, `${ hourBeforeDstStart }`);
|
||||
|
||||
// Samoa date line change (add): 10:00PM 29 Dec 2011 -> 11:00PM 31 Dec 2011
|
||||
var timeZone = TemporalHelpers.crossDateLineTimeZone();
|
||||
var dayBeforeSamoaDateLineChangeAbs = timeZone.getInstantFor(new Temporal.PlainDateTime(2011, 12, 29, 22));
|
||||
var start = dayBeforeSamoaDateLineChangeAbs.toZonedDateTimeISO(timeZone);
|
||||
var start = new Temporal.PlainDateTime(2011, 12, 29, 22).toZonedDateTime("Pacific/Apia");
|
||||
var added = start.add({
|
||||
days: 1,
|
||||
hours: 1
|
||||
|
@ -60,8 +56,7 @@ var undo = added.subtract(diff);
|
|||
assert.sameValue(`${ undo }`, `${ start }`);
|
||||
|
||||
// Samoa date line change (subtract): 11:00PM 31 Dec 2011 -> 10:00PM 29 Dec 2011
|
||||
var dayAfterSamoaDateLineChangeAbs = timeZone.getInstantFor(new Temporal.PlainDateTime(2011, 12, 31, 23));
|
||||
var start = dayAfterSamoaDateLineChangeAbs.toZonedDateTimeISO(timeZone);
|
||||
var start = new Temporal.PlainDateTime(2011, 12, 31, 23).toZonedDateTime("Pacific/Apia");
|
||||
var skipped = start.subtract({
|
||||
days: 1,
|
||||
hours: 1
|
||||
|
@ -147,16 +142,16 @@ var undo = added.subtract(diff);
|
|||
assert.sameValue(`${ undo }`, `${ start }`);
|
||||
|
||||
// Difference can return day length > 24 hours
|
||||
var start = Temporal.PlainDateTime.from("2000-10-27T01:45").toZonedDateTime(tz);
|
||||
var end = Temporal.PlainDateTime.from("2000-10-30T01:15").toZonedDateTime(tz);
|
||||
var start = Temporal.PlainDateTime.from("2000-10-27T01:45").toZonedDateTime("America/Vancouver");
|
||||
var end = Temporal.PlainDateTime.from("2000-10-30T01:15").toZonedDateTime("America/Vancouver");
|
||||
var diff = start.until(end, { largestUnit: "days" });
|
||||
assert.sameValue(`${ diff }`, "P2DT24H30M");
|
||||
var undo = start.add(diff);
|
||||
assert.sameValue(`${ undo }`, `${ end }`);
|
||||
|
||||
// Difference rounding (nearest day) is DST-aware
|
||||
var start = Temporal.PlainDateTime.from("2000-04-04T02:30").toZonedDateTime(tz);
|
||||
var end = Temporal.PlainDateTime.from("2000-04-01T14:15").toZonedDateTime(tz);
|
||||
var start = Temporal.PlainDateTime.from("2000-04-04T02:30").toZonedDateTime("America/Vancouver");
|
||||
var end = Temporal.PlainDateTime.from("2000-04-01T14:15").toZonedDateTime("America/Vancouver");
|
||||
var diff = start.until(end, {
|
||||
smallestUnit: "days",
|
||||
roundingMode: "halfExpand"
|
||||
|
@ -217,14 +212,14 @@ var diff = start.until(end, {
|
|||
assert.sameValue(`${ diff }`, "-P2DT13H");
|
||||
|
||||
// Difference when date portion ends inside a DST-skipped period
|
||||
var start = Temporal.PlainDateTime.from("2000-04-01T02:30").toZonedDateTime(tz);
|
||||
var end = Temporal.PlainDateTime.from("2000-04-02T03:15").toZonedDateTime(tz);
|
||||
var start = Temporal.PlainDateTime.from("2000-04-01T02:30").toZonedDateTime("America/Vancouver");
|
||||
var end = Temporal.PlainDateTime.from("2000-04-02T03:15").toZonedDateTime("America/Vancouver");
|
||||
var diff = start.until(end, { largestUnit: "days" });
|
||||
assert.sameValue(`${ diff }`, "PT23H45M");
|
||||
|
||||
// Difference when date portion ends inside day skipped by Samoa's 24hr 2011 transition
|
||||
var end = Temporal.PlainDateTime.from("2011-12-31T05:00").toZonedDateTime(timeZone);
|
||||
var start = Temporal.PlainDateTime.from("2011-12-28T10:00").toZonedDateTime(timeZone);
|
||||
var end = Temporal.PlainDateTime.from("2011-12-31T05:00").toZonedDateTime("Pacific/Apia");
|
||||
var start = Temporal.PlainDateTime.from("2011-12-28T10:00").toZonedDateTime("Pacific/Apia");
|
||||
var diff = start.until(end, { largestUnit: "days" });
|
||||
assert.sameValue(`${ diff }`, "P1DT19H");
|
||||
|
|
@ -4,13 +4,11 @@
|
|||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: properties around DST
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var tz = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
var hourBeforeDstStart = new Temporal.PlainDateTime(2000, 4, 2, 1).toZonedDateTime(tz);
|
||||
var dayBeforeDstStart = new Temporal.PlainDateTime(2000, 4, 1, 2, 30).toZonedDateTime(tz);
|
||||
var hourBeforeDstStart = new Temporal.PlainDateTime(2000, 4, 2, 1).toZonedDateTime("America/Vancouver");
|
||||
var dayBeforeDstStart = new Temporal.PlainDateTime(2000, 4, 1, 2, 30).toZonedDateTime("America/Vancouver");
|
||||
|
||||
// hoursInDay works with DST start
|
||||
assert.sameValue(hourBeforeDstStart.hoursInDay, 23);
|
||||
|
@ -19,7 +17,7 @@ assert.sameValue(hourBeforeDstStart.hoursInDay, 23);
|
|||
assert.sameValue(dayBeforeDstStart.hoursInDay, 24);
|
||||
|
||||
// hoursInDay works with DST end
|
||||
var dstEnd = Temporal.PlainDateTime.from("2000-10-29T01:00").toZonedDateTime(tz);
|
||||
var dstEnd = Temporal.PlainDateTime.from("2000-10-29T01:00").toZonedDateTime("America/Vancouver");
|
||||
assert.sameValue(dstEnd.hoursInDay, 25);
|
||||
|
||||
// startOfDay works
|
||||
|
@ -27,9 +25,8 @@ var start = dayBeforeDstStart.startOfDay();
|
|||
assert.sameValue(`${ start.toPlainDate() }`, `${ dayBeforeDstStart.toPlainDate() }`);
|
||||
assert.sameValue(`${ start.toPlainTime() }`, "00:00:00");
|
||||
|
||||
var samoa = TemporalHelpers.crossDateLineTimeZone();
|
||||
var dayAfterSamoaDateLineChange = Temporal.PlainDateTime.from("2011-12-31T22:00").toZonedDateTime(samoa);
|
||||
var dayBeforeSamoaDateLineChange = Temporal.PlainDateTime.from("2011-12-29T22:00").toZonedDateTime(samoa);
|
||||
var dayAfterSamoaDateLineChange = Temporal.PlainDateTime.from("2011-12-31T22:00").toZonedDateTime("Pacific/Apia");
|
||||
var dayBeforeSamoaDateLineChange = Temporal.PlainDateTime.from("2011-12-29T22:00").toZonedDateTime("Pacific/Apia");
|
||||
|
||||
// startOfDay works after Samoa date line change
|
||||
var start = dayAfterSamoaDateLineChange.startOfDay();
|
|
@ -0,0 +1,155 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-duration-objects
|
||||
description: Temporal.Duration.prototype.round() works as expected
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// relativeTo affects days if ZonedDateTime, and duration encompasses DST change
|
||||
var timeZone = "America/Vancouver";
|
||||
var skippedHourDay = Temporal.PlainDateTime.from("2000-04-02").toZonedDateTime(timeZone);
|
||||
var repeatedHourDay = Temporal.PlainDateTime.from("2000-10-29").toZonedDateTime(timeZone);
|
||||
var inRepeatedHour = new Temporal.ZonedDateTime(972806400_000_000_000n, timeZone);
|
||||
var oneDay = new Temporal.Duration(0, 0, 0, 1);
|
||||
var hours12 = new Temporal.Duration(0, 0, 0, 0, 12);
|
||||
var hours25 = new Temporal.Duration(0, 0, 0, 0, 25);
|
||||
|
||||
// start inside repeated hour, end after
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: inRepeatedHour
|
||||
}) }`, "P1D");
|
||||
assert.sameValue(`${ oneDay.round({
|
||||
largestUnit: "hours",
|
||||
relativeTo: inRepeatedHour
|
||||
}) }`, "PT25H");
|
||||
|
||||
// start after repeated hour, end inside (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-10-30T01:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours25.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-P1D");
|
||||
assert.sameValue(`${ oneDay.negated().round({
|
||||
largestUnit: "hours",
|
||||
relativeTo
|
||||
}) }`, "-PT25H");
|
||||
|
||||
// start inside repeated hour, end in skipped hour
|
||||
assert.sameValue(`${ Temporal.Duration.from({
|
||||
days: 126,
|
||||
hours: 1
|
||||
}).round({
|
||||
largestUnit: "days",
|
||||
relativeTo: inRepeatedHour
|
||||
}) }`, "P126DT1H");
|
||||
assert.sameValue(`${ Temporal.Duration.from({
|
||||
days: 126,
|
||||
hours: 1
|
||||
}).round({
|
||||
largestUnit: "hours",
|
||||
relativeTo: inRepeatedHour
|
||||
}) }`, "PT3026H");
|
||||
|
||||
// start in normal hour, end in skipped hour
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-04-01T02:30").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "P1DT1H");
|
||||
assert.sameValue(`${ oneDay.round({
|
||||
largestUnit: "hours",
|
||||
relativeTo
|
||||
}) }`, "PT24H");
|
||||
|
||||
// start before skipped hour, end >1 day after
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: skippedHourDay
|
||||
}) }`, "P1DT2H");
|
||||
assert.sameValue(`${ oneDay.round({
|
||||
largestUnit: "hours",
|
||||
relativeTo: skippedHourDay
|
||||
}) }`, "PT23H");
|
||||
|
||||
// start after skipped hour, end >1 day before (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-04-03T00:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours25.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-P1DT2H");
|
||||
assert.sameValue(`${ oneDay.negated().round({
|
||||
largestUnit: "hours",
|
||||
relativeTo
|
||||
}) }`, "-PT23H");
|
||||
|
||||
// start before skipped hour, end <1 day after
|
||||
assert.sameValue(`${ hours12.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: skippedHourDay
|
||||
}) }`, "PT12H");
|
||||
|
||||
// start after skipped hour, end <1 day before (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-04-02T12:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours12.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-PT12H");
|
||||
|
||||
// start before repeated hour, end >1 day after
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: repeatedHourDay
|
||||
}) }`, "P1D");
|
||||
assert.sameValue(`${ oneDay.round({
|
||||
largestUnit: "hours",
|
||||
relativeTo: repeatedHourDay
|
||||
}) }`, "PT25H");
|
||||
|
||||
// start after repeated hour, end >1 day before (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-10-30T00:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours25.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-P1D");
|
||||
assert.sameValue(`${ oneDay.negated().round({
|
||||
largestUnit: "hours",
|
||||
relativeTo
|
||||
}) }`, "-PT25H");
|
||||
|
||||
// start before repeated hour, end <1 day after
|
||||
assert.sameValue(`${ hours12.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: repeatedHourDay
|
||||
}) }`, "PT12H");
|
||||
|
||||
// start after repeated hour, end <1 day before (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-10-29T12:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours12.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-PT12H");
|
||||
|
||||
// Samoa skipped 24 hours
|
||||
var relativeTo = Temporal.PlainDateTime.from("2011-12-29T12:00").toZonedDateTime("Pacific/Apia");
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "P2DT1H");
|
||||
assert.sameValue(`${ Temporal.Duration.from({ hours: 48 }).round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "P3D");
|
||||
|
||||
// casts relativeTo to ZonedDateTime if possible
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: {
|
||||
year: 2000,
|
||||
month: 10,
|
||||
day: 29,
|
||||
timeZone
|
||||
}
|
||||
}) }`, "P1D");
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-duration-objects
|
||||
description: Temporal.Duration.prototype.total()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var oneDay = new Temporal.Duration(0, 0, 0, 1);
|
||||
var hours25 = new Temporal.Duration(0, 0, 0, 0, 25);
|
||||
|
||||
// Samoa skipped 24 hours
|
||||
var relativeTo = Temporal.PlainDateTime.from("2011-12-29T12:00").toZonedDateTime("Pacific/Apia");
|
||||
var totalDays = hours25.total({
|
||||
unit: "days",
|
||||
relativeTo
|
||||
});
|
||||
assert(Math.abs(totalDays - (2 + 1 / 24)) < Number.EPSILON);
|
||||
assert.sameValue(Temporal.Duration.from({ hours: 48 }).total({
|
||||
unit: "days",
|
||||
relativeTo
|
||||
}), 3);
|
||||
assert.sameValue(Temporal.Duration.from({ days: 2 }).total({
|
||||
unit: "hours",
|
||||
relativeTo
|
||||
}), 24);
|
||||
assert.sameValue(Temporal.Duration.from({ days: 3 }).total({
|
||||
unit: "hours",
|
||||
relativeTo
|
||||
}), 48);
|
||||
|
||||
// casts relativeTo to ZonedDateTime if possible
|
||||
assert.sameValue(oneDay.total({
|
||||
unit: "hours",
|
||||
relativeTo: {
|
||||
year: 2000,
|
||||
month: 10,
|
||||
day: 29,
|
||||
timeZone: "America/Vancouver"
|
||||
}
|
||||
}), 25);
|
|
@ -0,0 +1,154 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: property bags
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var date = {
|
||||
year: 2000,
|
||||
month: 10,
|
||||
day: 29,
|
||||
timeZone: "America/Vancouver"
|
||||
};
|
||||
// { offset: 'prefer' } if offset matches time zone (first 1:30 when DST ends)
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 1,
|
||||
minute: 30,
|
||||
offset: "-07:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "prefer" }) }`, "2000-10-29T01:30:00-07:00[America/Vancouver]");
|
||||
|
||||
// { offset: 'prefer' } if offset matches time zone (second 1:30 when DST ends)
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 1,
|
||||
minute: 30,
|
||||
offset: "-08:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "prefer" }) }`, "2000-10-29T01:30:00-08:00[America/Vancouver]");
|
||||
|
||||
// { offset: 'prefer' } if offset does not match time zone"
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 4,
|
||||
offset: "-07:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "prefer" }) }`, "2000-10-29T04:00:00-08:00[America/Vancouver]");
|
||||
|
||||
// { offset: 'ignore' } uses time zone only
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 4,
|
||||
offset: "-12:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "ignore" }) }`, "2000-10-29T04:00:00-08:00[America/Vancouver]");
|
||||
|
||||
// { offset: 'use' } uses offset only
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 4,
|
||||
offset: "-07:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "use" }) }`, "2000-10-29T03:00:00-08:00[America/Vancouver]");
|
||||
|
||||
// Disambiguation options
|
||||
|
||||
// plain datetime with multiple instants - Fall DST
|
||||
var obj = {
|
||||
year: 2000,
|
||||
month: 10,
|
||||
day: 29,
|
||||
hour: 1,
|
||||
minute: 45,
|
||||
timeZone: "America/Vancouver"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj) }`, "2000-10-29T01:45:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "compatible" }) }`, "2000-10-29T01:45:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "earlier" }) }`, "2000-10-29T01:45:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "later" }) }`, "2000-10-29T01:45:00-08:00[America/Vancouver]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { disambiguation: "reject" }));
|
||||
|
||||
// plain datetime with multiple instants - Spring DST
|
||||
var obj = {
|
||||
year: 2000,
|
||||
month: 4,
|
||||
day: 2,
|
||||
hour: 2,
|
||||
minute: 30,
|
||||
timeZone: "America/Vancouver"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "compatible" }) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "earlier" }) }`, "2000-04-02T01:30:00-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "later" }) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { disambiguation: "reject" }));
|
||||
|
||||
// uses disambiguation if offset is ignored
|
||||
var obj = {
|
||||
year: 2000,
|
||||
month: 4,
|
||||
day: 2,
|
||||
hour: 2,
|
||||
minute: 30,
|
||||
timeZone: "America/Vancouver"
|
||||
};
|
||||
var offset = "ignore";
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset }) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:00-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { disambiguation: "reject" }));
|
||||
|
||||
// uses disambiguation if offset is wrong and option is prefer
|
||||
var obj = {
|
||||
year: 2000,
|
||||
month: 4,
|
||||
day: 2,
|
||||
hour: 2,
|
||||
minute: 30,
|
||||
offset: "-23:59",
|
||||
timeZone: "America/Vancouver"
|
||||
};
|
||||
var offset = "prefer";
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset }) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:00-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:00-07:00[America/Vancouver]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "reject"
|
||||
}));
|
||||
|
||||
// sub-minute time zone offsets
|
||||
|
||||
// does not truncate offset property to minutes
|
||||
var zdt = Temporal.ZonedDateTime.from({
|
||||
year: 1971,
|
||||
month: 1,
|
||||
day: 1,
|
||||
hour: 12,
|
||||
timeZone: "Africa/Monrovia"
|
||||
});
|
||||
assert.sameValue(zdt.offset, "-00:44:30");
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: Temporal.ZonedDateTime.prototype.round()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// rounds correctly to a 25-hour day
|
||||
// (the 12.5 hour is the halfway point, which is 11:30 local time, since 2:00-2:59 repeats)
|
||||
var roundTo = { smallestUnit: "day" };
|
||||
var roundMeDown = Temporal.PlainDateTime.from("2000-10-29T11:29:59").toZonedDateTime("America/Vancouver");
|
||||
assert.sameValue(`${ roundMeDown.round(roundTo) }`, "2000-10-29T00:00:00-07:00[America/Vancouver]");
|
||||
var roundMeUp = Temporal.PlainDateTime.from("2000-10-29T11:30:01").toZonedDateTime("America/Vancouver");
|
||||
assert.sameValue(`${ roundMeUp.round(roundTo) }`, "2000-10-30T00:00:00-08:00[America/Vancouver]");
|
||||
|
||||
// rounds correctly to a 23-hour day
|
||||
// (the 11.5 hour is the halfway point, which is 12:30 local time, since 2:00-2:59 skips)
|
||||
var roundTo = { smallestUnit: "day" };
|
||||
var roundMeDown = Temporal.PlainDateTime.from("2000-04-02T12:29:59").toZonedDateTime("America/Vancouver");
|
||||
assert.sameValue(`${ roundMeDown.round(roundTo) }`, "2000-04-02T00:00:00-08:00[America/Vancouver]");
|
||||
var roundMeUp = Temporal.PlainDateTime.from("2000-04-02T12:30:01").toZonedDateTime("America/Vancouver");
|
||||
assert.sameValue(`${ roundMeUp.round(roundTo) }`, "2000-04-03T00:00:00-07:00[America/Vancouver]");
|
||||
|
||||
// rounding up to a nonexistent wall-clock time
|
||||
var almostSkipped = Temporal.PlainDateTime.from("2000-04-02T01:59:59.999999999").toZonedDateTime("America/Vancouver");
|
||||
var rounded = almostSkipped.round({
|
||||
smallestUnit: "microsecond",
|
||||
roundingMode: "halfExpand"
|
||||
});
|
||||
assert.sameValue(`${ rounded }`, "2000-04-02T03:00:00-07:00[America/Vancouver]");
|
||||
assert.sameValue(rounded.epochNanoseconds - almostSkipped.epochNanoseconds, 1n);
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: Temporal.ZonedDateTime.prototype.toString()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23+00:00[UTC]");
|
||||
|
||||
// combinations of calendar, time zone, and offset
|
||||
var zdt = zdt1.withCalendar("gregory");
|
||||
assert.sameValue(zdt.toString({
|
||||
timeZoneName: "never",
|
||||
calendarName: "never"
|
||||
}), "1976-11-18T15:23:00+00:00");
|
||||
assert.sameValue(zdt.toString({
|
||||
offset: "never",
|
||||
calendarName: "never"
|
||||
}), "1976-11-18T15:23:00[UTC]");
|
||||
assert.sameValue(zdt.toString({
|
||||
offset: "never",
|
||||
timeZoneName: "never"
|
||||
}), "1976-11-18T15:23:00[u-ca=gregory]");
|
||||
assert.sameValue(zdt.toString({
|
||||
offset: "never",
|
||||
timeZoneName: "never",
|
||||
calendarName: "never"
|
||||
}), "1976-11-18T15:23:00");
|
||||
|
||||
// rounding up to a nonexistent wall-clock time
|
||||
var zdt5 = Temporal.PlainDateTime.from("2000-04-02T01:59:59.999999999").toZonedDateTime("America/Vancouver");
|
||||
var roundedString = zdt5.toString({
|
||||
fractionalSecondDigits: 8,
|
||||
roundingMode: "halfExpand"
|
||||
});
|
||||
assert.sameValue(roundedString, "2000-04-02T03:00:00.00000000-07:00[America/Vancouver]");
|
||||
var zdt6 = Temporal.Instant.from(roundedString);
|
||||
assert.sameValue(zdt6.epochNanoseconds - zdt5.epochNanoseconds, 1n);
|
|
@ -0,0 +1,155 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: Temporal.ZonedDateTime.prototype.with()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var dstStartDay = Temporal.PlainDateTime.from("2000-04-02T12:00:01").toZonedDateTime("America/Vancouver");
|
||||
var dstEndDay = Temporal.PlainDateTime.from("2000-10-29T12:00:01").toZonedDateTime("America/Vancouver");
|
||||
var oneThirty = {
|
||||
hour: 1,
|
||||
minute: 30
|
||||
};
|
||||
var twoThirty = {
|
||||
hour: 2,
|
||||
minute: 30
|
||||
};
|
||||
|
||||
// Disambiguation options
|
||||
var offset = "ignore";
|
||||
// compatible, skipped wall time
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2000-04-02T03:30:01-07:00[America/Vancouver]");
|
||||
|
||||
// earlier, skipped wall time
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:01-08:00[America/Vancouver]");
|
||||
|
||||
// later, skipped wall time
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:01-07:00[America/Vancouver]");
|
||||
|
||||
// compatible, repeated wall time
|
||||
assert.sameValue(`${ dstEndDay.with(oneThirty, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2000-10-29T01:30:01-07:00[America/Vancouver]");
|
||||
|
||||
// earlier, repeated wall time
|
||||
assert.sameValue(`${ dstEndDay.with(oneThirty, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-10-29T01:30:01-07:00[America/Vancouver]");
|
||||
|
||||
// later, repeated wall time
|
||||
assert.sameValue(`${ dstEndDay.with(oneThirty, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-10-29T01:30:01-08:00[America/Vancouver]");
|
||||
|
||||
// reject
|
||||
assert.throws(RangeError, () => dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "reject"
|
||||
}));
|
||||
assert.throws(RangeError, () => dstEndDay.with(oneThirty, {
|
||||
offset,
|
||||
disambiguation: "reject"
|
||||
}));
|
||||
|
||||
// compatible is the default
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty, { offset }) }`, `${ dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`);
|
||||
assert.sameValue(`${ dstEndDay.with(twoThirty, { offset }) }`, `${ dstEndDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`);
|
||||
|
||||
// Offset options
|
||||
var bogus = {
|
||||
...twoThirty,
|
||||
offset: "+23:59"
|
||||
};
|
||||
// use, with bogus offset, changes to the exact time with the offset
|
||||
var preserveExact = dstStartDay.with(bogus, { offset: "use" });
|
||||
assert.sameValue(`${ preserveExact }`, "2000-03-31T18:31:01-08:00[America/Vancouver]");
|
||||
assert.sameValue(preserveExact.epochNanoseconds, Temporal.Instant.from("2000-04-02T02:30:01+23:59").epochNanoseconds);
|
||||
|
||||
// ignore, with bogus offset, defers to disambiguation option
|
||||
var offset = "ignore";
|
||||
assert.sameValue(`${ dstStartDay.with(bogus, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:01-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ dstStartDay.with(bogus, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:01-07:00[America/Vancouver]");
|
||||
|
||||
// prefer, with bogus offset, defers to disambiguation option
|
||||
var offset = "prefer";
|
||||
assert.sameValue(`${ dstStartDay.with(bogus, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:01-08:00[America/Vancouver]");
|
||||
assert.sameValue(`${ dstStartDay.with(bogus, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:01-07:00[America/Vancouver]");
|
||||
|
||||
// reject, with bogus offset, throws
|
||||
assert.throws(RangeError, () => dstStartDay.with({
|
||||
...twoThirty,
|
||||
offset: "+23:59"
|
||||
}, { offset: "reject" }));
|
||||
|
||||
var doubleTime = new Temporal.ZonedDateTime(972811801_000_000_000n, "America/Vancouver");
|
||||
// use changes to the exact time with the offset
|
||||
var preserveExact = doubleTime.with({ offset: "-07:00" }, { offset: "use" });
|
||||
assert.sameValue(preserveExact.offset, "-07:00");
|
||||
assert.sameValue(preserveExact.epochNanoseconds, Temporal.Instant.from("2000-10-29T01:30:01-07:00").epochNanoseconds);
|
||||
|
||||
// ignore defers to disambiguation option
|
||||
var offset = "ignore";
|
||||
assert.sameValue(doubleTime.with({ offset: "-07:00" }, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}).offset, "-07:00");
|
||||
assert.sameValue(doubleTime.with({ offset: "-07:00" }, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}).offset, "-08:00");
|
||||
|
||||
// prefer adjusts offset of repeated clock time
|
||||
assert.sameValue(doubleTime.with({ offset: "-07:00" }, { offset: "prefer" }).offset, "-07:00");
|
||||
|
||||
// reject adjusts offset of repeated clock time
|
||||
assert.sameValue(doubleTime.with({ offset: "-07:00" }, { offset: "reject" }).offset, "-07:00");
|
||||
|
||||
// use does not cause the offset to change when adjusting repeated clock time
|
||||
assert.sameValue(doubleTime.with({ minute: 31 }, { offset: "use" }).offset, "-08:00");
|
||||
|
||||
// ignore may cause the offset to change when adjusting repeated clock time
|
||||
assert.sameValue(doubleTime.with({ minute: 31 }, { offset: "ignore" }).offset, "-07:00");
|
||||
|
||||
// prefer does not cause the offset to change when adjusting repeated clock time
|
||||
assert.sameValue(doubleTime.with({ minute: 31 }, { offset: "prefer" }).offset, "-08:00");
|
||||
|
||||
// reject does not cause the offset to change when adjusting repeated clock time
|
||||
assert.sameValue(doubleTime.with({ minute: 31 }, { offset: "reject" }).offset, "-08:00");
|
||||
|
||||
// prefer is the default
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty) }`, `${ dstStartDay.with(twoThirty, { offset: "prefer" }) }`);
|
||||
assert.sameValue(`${ dstEndDay.with(twoThirty) }`, `${ dstEndDay.with(twoThirty, { offset: "prefer" }) }`);
|
||||
assert.sameValue(`${ doubleTime.with({ minute: 31 }) }`, `${ doubleTime.with({ minute: 31 }, { offset: "prefer" }) }`);
|
|
@ -4,7 +4,6 @@
|
|||
/*---
|
||||
esid: sec-temporal-duration-objects
|
||||
description: Temporal.Duration.prototype.round() works as expected
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -33,153 +32,6 @@ assert.sameValue(`${ hours25.round({
|
|||
relativeTo
|
||||
}) }`, "P1DT1H");
|
||||
|
||||
// relativeTo affects days if ZonedDateTime, and duration encompasses DST change
|
||||
var timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
var skippedHourDay = Temporal.PlainDateTime.from("2000-04-02").toZonedDateTime(timeZone);
|
||||
var repeatedHourDay = Temporal.PlainDateTime.from("2000-10-29").toZonedDateTime(timeZone);
|
||||
var inRepeatedHour = new Temporal.ZonedDateTime(972806400_000_000_000n, timeZone);
|
||||
var oneDay = new Temporal.Duration(0, 0, 0, 1);
|
||||
var hours12 = new Temporal.Duration(0, 0, 0, 0, 12);
|
||||
|
||||
// start inside repeated hour, end after
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: inRepeatedHour
|
||||
}) }`, "P1D");
|
||||
assert.sameValue(`${ oneDay.round({
|
||||
largestUnit: "hours",
|
||||
relativeTo: inRepeatedHour
|
||||
}) }`, "PT25H");
|
||||
|
||||
// start after repeated hour, end inside (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-10-30T01:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours25.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-P1D");
|
||||
assert.sameValue(`${ oneDay.negated().round({
|
||||
largestUnit: "hours",
|
||||
relativeTo
|
||||
}) }`, "-PT25H");
|
||||
|
||||
// start inside repeated hour, end in skipped hour
|
||||
assert.sameValue(`${ Temporal.Duration.from({
|
||||
days: 126,
|
||||
hours: 1
|
||||
}).round({
|
||||
largestUnit: "days",
|
||||
relativeTo: inRepeatedHour
|
||||
}) }`, "P126DT1H");
|
||||
assert.sameValue(`${ Temporal.Duration.from({
|
||||
days: 126,
|
||||
hours: 1
|
||||
}).round({
|
||||
largestUnit: "hours",
|
||||
relativeTo: inRepeatedHour
|
||||
}) }`, "PT3026H");
|
||||
|
||||
// start in normal hour, end in skipped hour
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-04-01T02:30").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "P1DT1H");
|
||||
assert.sameValue(`${ oneDay.round({
|
||||
largestUnit: "hours",
|
||||
relativeTo
|
||||
}) }`, "PT24H");
|
||||
|
||||
// start before skipped hour, end >1 day after
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: skippedHourDay
|
||||
}) }`, "P1DT2H");
|
||||
assert.sameValue(`${ oneDay.round({
|
||||
largestUnit: "hours",
|
||||
relativeTo: skippedHourDay
|
||||
}) }`, "PT23H");
|
||||
|
||||
// start after skipped hour, end >1 day before (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-04-03T00:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours25.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-P1DT2H");
|
||||
assert.sameValue(`${ oneDay.negated().round({
|
||||
largestUnit: "hours",
|
||||
relativeTo
|
||||
}) }`, "-PT23H");
|
||||
|
||||
// start before skipped hour, end <1 day after
|
||||
assert.sameValue(`${ hours12.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: skippedHourDay
|
||||
}) }`, "PT12H");
|
||||
|
||||
// start after skipped hour, end <1 day before (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-04-02T12:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours12.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-PT12H");
|
||||
|
||||
// start before repeated hour, end >1 day after
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: repeatedHourDay
|
||||
}) }`, "P1D");
|
||||
assert.sameValue(`${ oneDay.round({
|
||||
largestUnit: "hours",
|
||||
relativeTo: repeatedHourDay
|
||||
}) }`, "PT25H");
|
||||
|
||||
// start after repeated hour, end >1 day before (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-10-30T00:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours25.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-P1D");
|
||||
assert.sameValue(`${ oneDay.negated().round({
|
||||
largestUnit: "hours",
|
||||
relativeTo
|
||||
}) }`, "-PT25H");
|
||||
|
||||
// start before repeated hour, end <1 day after
|
||||
assert.sameValue(`${ hours12.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: repeatedHourDay
|
||||
}) }`, "PT12H");
|
||||
|
||||
// start after repeated hour, end <1 day before (negative)
|
||||
var relativeTo = Temporal.PlainDateTime.from("2000-10-29T12:00").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ hours12.negated().round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "-PT12H");
|
||||
|
||||
// Samoa skipped 24 hours
|
||||
var fakeSamoa = TemporalHelpers.crossDateLineTimeZone();
|
||||
var relativeTo = Temporal.PlainDateTime.from("2011-12-29T12:00").toZonedDateTime(fakeSamoa);
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "P2DT1H");
|
||||
assert.sameValue(`${ Temporal.Duration.from({ hours: 48 }).round({
|
||||
largestUnit: "days",
|
||||
relativeTo
|
||||
}) }`, "P3D");
|
||||
|
||||
// casts relativeTo to ZonedDateTime if possible
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
relativeTo: {
|
||||
year: 2000,
|
||||
month: 10,
|
||||
day: 29,
|
||||
timeZone
|
||||
}
|
||||
}) }`, "P1D");
|
||||
|
||||
// casts relativeTo to PlainDate if possible
|
||||
assert.sameValue(`${ hours25.round({
|
||||
largestUnit: "days",
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
/*---
|
||||
esid: sec-temporal-duration-objects
|
||||
description: Temporal.Duration.prototype.total()
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -195,42 +194,6 @@ assert.sameValue(negativeFortyDays.total({
|
|||
relativeTo: "2020-04-01"
|
||||
}).toPrecision(16), (-(1 + 9 / 29)).toPrecision(16));
|
||||
|
||||
var oneDay = new Temporal.Duration(0, 0, 0, 1);
|
||||
var timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
var hours25 = new Temporal.Duration(0, 0, 0, 0, 25);
|
||||
|
||||
// Samoa skipped 24 hours
|
||||
var fakeSamoa = TemporalHelpers.crossDateLineTimeZone();
|
||||
var relativeTo = Temporal.PlainDateTime.from("2011-12-29T12:00").toZonedDateTime(fakeSamoa);
|
||||
var totalDays = hours25.total({
|
||||
unit: "days",
|
||||
relativeTo
|
||||
});
|
||||
assert(Math.abs(totalDays - (2 + 1 / 24)) < Number.EPSILON);
|
||||
assert.sameValue(Temporal.Duration.from({ hours: 48 }).total({
|
||||
unit: "days",
|
||||
relativeTo
|
||||
}), 3);
|
||||
assert.sameValue(Temporal.Duration.from({ days: 2 }).total({
|
||||
unit: "hours",
|
||||
relativeTo
|
||||
}), 24);
|
||||
assert.sameValue(Temporal.Duration.from({ days: 3 }).total({
|
||||
unit: "hours",
|
||||
relativeTo
|
||||
}), 48);
|
||||
|
||||
// casts relativeTo to ZonedDateTime if possible
|
||||
assert.sameValue(oneDay.total({
|
||||
unit: "hours",
|
||||
relativeTo: {
|
||||
year: 2000,
|
||||
month: 10,
|
||||
day: 29,
|
||||
timeZone
|
||||
}
|
||||
}), 25);
|
||||
|
||||
// balances up to the next unit after rounding
|
||||
var almostWeek = Temporal.Duration.from({
|
||||
days: 6,
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: property bags
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -131,142 +130,6 @@ var obj = {
|
|||
};
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" }));
|
||||
|
||||
var cali = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
var date = {
|
||||
year: 2000,
|
||||
month: 10,
|
||||
day: 29,
|
||||
timeZone: cali
|
||||
};
|
||||
// { offset: 'prefer' } if offset matches time zone (first 1:30 when DST ends)
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 1,
|
||||
minute: 30,
|
||||
offset: "-07:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "prefer" }) }`, "2000-10-29T01:30:00-07:00[Custom/Spring_Fall]");
|
||||
|
||||
// { offset: 'prefer' } if offset matches time zone (second 1:30 when DST ends)
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 1,
|
||||
minute: 30,
|
||||
offset: "-08:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "prefer" }) }`, "2000-10-29T01:30:00-08:00[Custom/Spring_Fall]");
|
||||
|
||||
// { offset: 'prefer' } if offset does not match time zone"
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 4,
|
||||
offset: "-07:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "prefer" }) }`, "2000-10-29T04:00:00-08:00[Custom/Spring_Fall]");
|
||||
|
||||
// { offset: 'ignore' } uses time zone only
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 4,
|
||||
offset: "-12:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "ignore" }) }`, "2000-10-29T04:00:00-08:00[Custom/Spring_Fall]");
|
||||
|
||||
// { offset: 'use' } uses offset only
|
||||
var obj = {
|
||||
...date,
|
||||
hour: 4,
|
||||
offset: "-07:00"
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset: "use" }) }`, "2000-10-29T03:00:00-08:00[Custom/Spring_Fall]");
|
||||
|
||||
// Disambiguation options
|
||||
|
||||
// plain datetime with multiple instants - Fall DST
|
||||
var obj = {
|
||||
year: 2000,
|
||||
month: 10,
|
||||
day: 29,
|
||||
hour: 1,
|
||||
minute: 45,
|
||||
timeZone: cali
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj) }`, "2000-10-29T01:45:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "compatible" }) }`, "2000-10-29T01:45:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "earlier" }) }`, "2000-10-29T01:45:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "later" }) }`, "2000-10-29T01:45:00-08:00[Custom/Spring_Fall]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { disambiguation: "reject" }));
|
||||
|
||||
// plain datetime with multiple instants - Spring DST
|
||||
var obj = {
|
||||
year: 2000,
|
||||
month: 4,
|
||||
day: 2,
|
||||
hour: 2,
|
||||
minute: 30,
|
||||
timeZone: cali
|
||||
};
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "compatible" }) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "earlier" }) }`, "2000-04-02T01:30:00-08:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { disambiguation: "later" }) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { disambiguation: "reject" }));
|
||||
|
||||
// uses disambiguation if offset is ignored
|
||||
var obj = {
|
||||
year: 2000,
|
||||
month: 4,
|
||||
day: 2,
|
||||
hour: 2,
|
||||
minute: 30,
|
||||
timeZone: cali
|
||||
};
|
||||
var offset = "ignore";
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset }) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:00-08:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { disambiguation: "reject" }));
|
||||
|
||||
// uses disambiguation if offset is wrong and option is prefer
|
||||
var obj = {
|
||||
year: 2000,
|
||||
month: 4,
|
||||
day: 2,
|
||||
hour: 2,
|
||||
minute: 30,
|
||||
offset: "-23:59",
|
||||
timeZone: cali
|
||||
};
|
||||
var offset = "prefer";
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, { offset }) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:00-08:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:00-07:00[Custom/Spring_Fall]");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, {
|
||||
offset,
|
||||
disambiguation: "reject"
|
||||
}));
|
||||
|
||||
// throw when bad disambiguation
|
||||
[
|
||||
"",
|
||||
|
@ -277,15 +140,3 @@ assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, {
|
|||
].forEach(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
|
||||
var zdt = Temporal.ZonedDateTime.from({
|
||||
year: 1971,
|
||||
month: 1,
|
||||
day: 1,
|
||||
hour: 12,
|
||||
timeZone: TemporalHelpers.specificOffsetTimeZone(-2.67e12) // -00:44:30 in nanoseconds
|
||||
});
|
||||
assert.sameValue(zdt.offset, "-00:44:30");
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: Temporal.ZonedDateTime.prototype.round()
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -212,30 +211,3 @@ var bal = Temporal.ZonedDateTime.from("1976-11-18T23:59:59.999999999+01:00[+01:0
|
|||
].forEach(smallestUnit => {
|
||||
assert.sameValue(`${ bal.round({ smallestUnit }) }`, "1976-11-19T00:00:00+01:00[+01:00]");
|
||||
});
|
||||
|
||||
var timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
|
||||
// rounds correctly to a 25-hour day
|
||||
// (the 12.5 hour is the halfway point, which is 11:30 local time, since 2:00-2:59 repeats)
|
||||
var roundTo = { smallestUnit: "day" };
|
||||
var roundMeDown = Temporal.PlainDateTime.from("2000-10-29T11:29:59").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ roundMeDown.round(roundTo) }`, "2000-10-29T00:00:00-07:00[Custom/Spring_Fall]");
|
||||
var roundMeUp = Temporal.PlainDateTime.from("2000-10-29T11:30:01").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ roundMeUp.round(roundTo) }`, "2000-10-30T00:00:00-08:00[Custom/Spring_Fall]");
|
||||
|
||||
// rounds correctly to a 23-hour day
|
||||
// (the 11.5 hour is the halfway point, which is 12:30 local time, since 2:00-2:59 skips)
|
||||
var roundTo = { smallestUnit: "day" };
|
||||
var roundMeDown = Temporal.PlainDateTime.from("2000-04-02T12:29:59").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ roundMeDown.round(roundTo) }`, "2000-04-02T00:00:00-08:00[Custom/Spring_Fall]");
|
||||
var roundMeUp = Temporal.PlainDateTime.from("2000-04-02T12:30:01").toZonedDateTime(timeZone);
|
||||
assert.sameValue(`${ roundMeUp.round(roundTo) }`, "2000-04-03T00:00:00-07:00[Custom/Spring_Fall]");
|
||||
|
||||
// rounding up to a nonexistent wall-clock time
|
||||
var almostSkipped = Temporal.PlainDateTime.from("2000-04-02T01:59:59.999999999").toZonedDateTime(timeZone);
|
||||
var rounded = almostSkipped.round({
|
||||
smallestUnit: "microsecond",
|
||||
roundingMode: "halfExpand"
|
||||
});
|
||||
assert.sameValue(`${ rounded }`, "2000-04-02T03:00:00-07:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(rounded.epochNanoseconds - almostSkipped.epochNanoseconds, 1n);
|
||||
|
|
|
@ -38,34 +38,3 @@ assert.sameValue(zdt1.toString({ offset: "auto" }), "1976-11-18T15:23:00+00:00[U
|
|||
|
||||
// omits offset if offset = never
|
||||
assert.sameValue(zdt1.toString({ offset: "never" }), "1976-11-18T15:23:00[UTC]");
|
||||
|
||||
// combinations of calendar, time zone, and offset
|
||||
var zdt = zdt1.withCalendar(fakeGregorian);
|
||||
assert.sameValue(zdt.toString({
|
||||
timeZoneName: "never",
|
||||
calendarName: "never"
|
||||
}), "1976-11-18T15:23:00+00:00");
|
||||
assert.sameValue(zdt.toString({
|
||||
offset: "never",
|
||||
calendarName: "never"
|
||||
}), "1976-11-18T15:23:00[UTC]");
|
||||
assert.sameValue(zdt.toString({
|
||||
offset: "never",
|
||||
timeZoneName: "never"
|
||||
}), "1976-11-18T15:23:00[u-ca=gregory]");
|
||||
assert.sameValue(zdt.toString({
|
||||
offset: "never",
|
||||
timeZoneName: "never",
|
||||
calendarName: "never"
|
||||
}), "1976-11-18T15:23:00");
|
||||
|
||||
// rounding up to a nonexistent wall-clock time
|
||||
var dst = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
var zdt5 = Temporal.PlainDateTime.from("2000-04-02T01:59:59.999999999").toZonedDateTime(dst);
|
||||
var roundedString = zdt5.toString({
|
||||
fractionalSecondDigits: 8,
|
||||
roundingMode: "halfExpand"
|
||||
});
|
||||
assert.sameValue(roundedString, "2000-04-02T03:00:00.00000000-07:00[Custom/Spring_Fall]");
|
||||
var zdt6 = Temporal.Instant.from(roundedString);
|
||||
assert.sameValue(zdt6.epochNanoseconds - zdt5.epochNanoseconds, 1n);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: Temporal.ZonedDateTime.prototype.with()
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
@ -67,76 +66,6 @@ assert.throws(RangeError, () => zdt.with({ day: 31 }, { overflow }));
|
|||
assert.throws(RangeError, () => zdt.with({ hour: 29 }, { overflow }));
|
||||
assert.throws(RangeError, () => zdt.with({ nanosecond: 9000 }, { overflow }));
|
||||
|
||||
var dst = TemporalHelpers.springForwardFallBackTimeZone();
|
||||
var dstStartDay = Temporal.PlainDateTime.from("2000-04-02T12:00:01").toZonedDateTime(dst);
|
||||
var dstEndDay = Temporal.PlainDateTime.from("2000-10-29T12:00:01").toZonedDateTime(dst);
|
||||
var oneThirty = {
|
||||
hour: 1,
|
||||
minute: 30
|
||||
};
|
||||
var twoThirty = {
|
||||
hour: 2,
|
||||
minute: 30
|
||||
};
|
||||
|
||||
// Disambiguation options
|
||||
var offset = "ignore";
|
||||
// compatible, skipped wall time
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2000-04-02T03:30:01-07:00[Custom/Spring_Fall]");
|
||||
|
||||
// earlier, skipped wall time
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:01-08:00[Custom/Spring_Fall]");
|
||||
|
||||
// later, skipped wall time
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:01-07:00[Custom/Spring_Fall]");
|
||||
|
||||
// compatible, repeated wall time
|
||||
assert.sameValue(`${ dstEndDay.with(oneThirty, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`, "2000-10-29T01:30:01-07:00[Custom/Spring_Fall]");
|
||||
|
||||
// earlier, repeated wall time
|
||||
assert.sameValue(`${ dstEndDay.with(oneThirty, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-10-29T01:30:01-07:00[Custom/Spring_Fall]");
|
||||
|
||||
// later, repeated wall time
|
||||
assert.sameValue(`${ dstEndDay.with(oneThirty, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-10-29T01:30:01-08:00[Custom/Spring_Fall]");
|
||||
|
||||
// reject
|
||||
assert.throws(RangeError, () => dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "reject"
|
||||
}));
|
||||
assert.throws(RangeError, () => dstEndDay.with(oneThirty, {
|
||||
offset,
|
||||
disambiguation: "reject"
|
||||
}));
|
||||
|
||||
// compatible is the default
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty, { offset }) }`, `${ dstStartDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`);
|
||||
assert.sameValue(`${ dstEndDay.with(twoThirty, { offset }) }`, `${ dstEndDay.with(twoThirty, {
|
||||
offset,
|
||||
disambiguation: "compatible"
|
||||
}) }`);
|
||||
|
||||
// invalid disambiguation
|
||||
[
|
||||
"",
|
||||
|
@ -144,84 +73,6 @@ assert.sameValue(`${ dstEndDay.with(twoThirty, { offset }) }`, `${ dstEndDay.wit
|
|||
"balance"
|
||||
].forEach(disambiguation => assert.throws(RangeError, () => zdt.with({ day: 5 }, { disambiguation })));
|
||||
|
||||
// Offset options
|
||||
var bogus = {
|
||||
...twoThirty,
|
||||
offset: "+23:59"
|
||||
};
|
||||
// use, with bogus offset, changes to the exact time with the offset
|
||||
var preserveExact = dstStartDay.with(bogus, { offset: "use" });
|
||||
assert.sameValue(`${ preserveExact }`, "2000-03-31T18:31:01-08:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(preserveExact.epochNanoseconds, Temporal.Instant.from("2000-04-02T02:30:01+23:59").epochNanoseconds);
|
||||
|
||||
// ignore, with bogus offset, defers to disambiguation option
|
||||
var offset = "ignore";
|
||||
assert.sameValue(`${ dstStartDay.with(bogus, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:01-08:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ dstStartDay.with(bogus, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:01-07:00[Custom/Spring_Fall]");
|
||||
|
||||
// prefer, with bogus offset, defers to disambiguation option
|
||||
var offset = "prefer";
|
||||
assert.sameValue(`${ dstStartDay.with(bogus, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}) }`, "2000-04-02T01:30:01-08:00[Custom/Spring_Fall]");
|
||||
assert.sameValue(`${ dstStartDay.with(bogus, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}) }`, "2000-04-02T03:30:01-07:00[Custom/Spring_Fall]");
|
||||
|
||||
// reject, with bogus offset, throws
|
||||
assert.throws(RangeError, () => dstStartDay.with({
|
||||
...twoThirty,
|
||||
offset: "+23:59"
|
||||
}, { offset: "reject" }));
|
||||
|
||||
var doubleTime = new Temporal.ZonedDateTime(972811801_000_000_000n, dst);
|
||||
// use changes to the exact time with the offset
|
||||
var preserveExact = doubleTime.with({ offset: "-07:00" }, { offset: "use" });
|
||||
assert.sameValue(preserveExact.offset, "-07:00");
|
||||
assert.sameValue(preserveExact.epochNanoseconds, Temporal.Instant.from("2000-10-29T01:30:01-07:00").epochNanoseconds);
|
||||
|
||||
// ignore defers to disambiguation option
|
||||
var offset = "ignore";
|
||||
assert.sameValue(doubleTime.with({ offset: "-07:00" }, {
|
||||
offset,
|
||||
disambiguation: "earlier"
|
||||
}).offset, "-07:00");
|
||||
assert.sameValue(doubleTime.with({ offset: "-07:00" }, {
|
||||
offset,
|
||||
disambiguation: "later"
|
||||
}).offset, "-08:00");
|
||||
|
||||
// prefer adjusts offset of repeated clock time
|
||||
assert.sameValue(doubleTime.with({ offset: "-07:00" }, { offset: "prefer" }).offset, "-07:00");
|
||||
|
||||
// reject adjusts offset of repeated clock time
|
||||
assert.sameValue(doubleTime.with({ offset: "-07:00" }, { offset: "reject" }).offset, "-07:00");
|
||||
|
||||
// use does not cause the offset to change when adjusting repeated clock time
|
||||
assert.sameValue(doubleTime.with({ minute: 31 }, { offset: "use" }).offset, "-08:00");
|
||||
|
||||
// ignore may cause the offset to change when adjusting repeated clock time
|
||||
assert.sameValue(doubleTime.with({ minute: 31 }, { offset: "ignore" }).offset, "-07:00");
|
||||
|
||||
// prefer does not cause the offset to change when adjusting repeated clock time
|
||||
assert.sameValue(doubleTime.with({ minute: 31 }, { offset: "prefer" }).offset, "-08:00");
|
||||
|
||||
// reject does not cause the offset to change when adjusting repeated clock time
|
||||
assert.sameValue(doubleTime.with({ minute: 31 }, { offset: "reject" }).offset, "-08:00");
|
||||
|
||||
// prefer is the default
|
||||
assert.sameValue(`${ dstStartDay.with(twoThirty) }`, `${ dstStartDay.with(twoThirty, { offset: "prefer" }) }`);
|
||||
assert.sameValue(`${ dstEndDay.with(twoThirty) }`, `${ dstEndDay.with(twoThirty, { offset: "prefer" }) }`);
|
||||
assert.sameValue(`${ doubleTime.with({ minute: 31 }) }`, `${ doubleTime.with({ minute: 31 }, { offset: "prefer" }) }`);
|
||||
|
||||
// invalid offset
|
||||
[
|
||||
"",
|
||||
|
@ -246,7 +97,7 @@ assert.throws(TypeError, () => zdt.with({
|
|||
}));
|
||||
|
||||
// throws if given a Temporal object with a time zone
|
||||
assert.throws(TypeError, () => zdt.with(dstStartDay));
|
||||
assert.throws(TypeError, () => zdt.with(zdt));
|
||||
|
||||
// throws if calendarName is included
|
||||
assert.throws(TypeError, () => zdt.with({
|
||||
|
|
Loading…
Reference in New Issue