-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Use TemporalHelpers.springForwardFallBackTimeZone in staging
Some tests in staging used various IANA time zones in order to test DST behaviour. Since implementations are technically not required to understand IANA time zones, we have a fake DST time zone in TemporalHelpers. Use that instead. For a few cases where it's not practical to use the fake DST time zone (because it only has one spring-forward and one fall-back transition, for example), move a few tests into staging/Intl402/Temporal/. See: #3649
- Loading branch information
Showing
17 changed files
with
482 additions
and
333 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
test/staging/Intl402/Temporal/old/duration-arithmetic-dst.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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: > | ||
Various DST arithmetic tests that it's impractical to do without a time zone | ||
database in the implementation | ||
features: [Temporal] | ||
---*/ | ||
|
||
// Tests for arithmetic that start inside a repeated hour, and end in a skipped | ||
// hour. We have TemporalHelpers.springForwardFallBackTimeZone which is | ||
// sufficient to test this for Temporal.Duration.prototype.add, and | ||
// Temporal.Duration.prototype.round, but it's impractical to replicate all the | ||
// TZDB data for testing it with other methods such as subtract() where we need | ||
// to calculate to the _next_ transition | ||
|
||
var skippedHourDay = Temporal.ZonedDateTime.from("2019-03-10T00:00[America/Vancouver]"); | ||
var repeatedHourDay = Temporal.ZonedDateTime.from("2019-11-03T00:00[America/Vancouver]"); | ||
var inRepeatedHour = Temporal.ZonedDateTime.from("2019-11-03T01:00-07:00[America/Vancouver]"); | ||
|
||
// subtract() | ||
|
||
var oneDay = new Temporal.Duration(0, 0, 0, 1); | ||
assert.sameValue(`${ Temporal.Duration.from({ | ||
days: 127, | ||
hours: 1 | ||
}).subtract(oneDay, { relativeTo: inRepeatedHour }) }`, "P126DT1H"); | ||
var hours24 = new Temporal.Duration(0, 0, 0, 0, 24); | ||
assert.sameValue(`${ Temporal.Duration.from({ | ||
days: 127, | ||
hours: 1 | ||
}).subtract(hours24, { relativeTo: inRepeatedHour }) }`, "P126D"); | ||
|
||
// total() | ||
var totalDays = Temporal.Duration.from({ | ||
days: 126, | ||
hours: 1 | ||
}).total({ | ||
unit: "days", | ||
relativeTo: inRepeatedHour | ||
}); | ||
assert(Math.abs(totalDays - (126 + 1 / 23)) < Number.EPSILON); | ||
assert.sameValue(Temporal.Duration.from({ | ||
days: 126, | ||
hours: 1 | ||
}).total({ | ||
unit: "hours", | ||
relativeTo: inRepeatedHour | ||
}), 3026); | ||
|
||
// Tests for casting relativeTo to ZonedDateTime when possible: | ||
// Without a TZDB, it's not possible to get a ZonedDateTime with DST from a | ||
// string. | ||
|
||
assert.sameValue( | ||
`${ oneDay.add(hours24, { relativeTo: "2019-11-02T00:00[America/Vancouver]" }) }`, | ||
"P1DT24H" | ||
); | ||
var hours25 = new Temporal.Duration(0, 0, 0, 0, 25); | ||
assert.sameValue(`${ hours25.round({ | ||
largestUnit: "days", | ||
relativeTo: "2019-11-03T00:00[America/Vancouver]" | ||
}) }`, "P1D"); | ||
assert.sameValue( | ||
`${ oneDay.subtract(hours24, { relativeTo: "2019-11-03T00:00[America/Vancouver]" }) }`, | ||
"PT1H" | ||
); | ||
assert.sameValue(oneDay.total({ | ||
unit: "hours", | ||
relativeTo: "2019-11-03T00:00[America/Vancouver]" | ||
}), 25); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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: String parsing cases that require a TZDB in the implementation | ||
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]"); | ||
|
||
// Offset options | ||
|
||
// { 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" | ||
})); |
26 changes: 26 additions & 0 deletions
26
test/staging/Intl402/Temporal/old/zoneddatetime-dst-corner-cases.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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: Corner cases of time zone offset shifts | ||
features: [Temporal] | ||
---*/ | ||
|
||
// hoursInDay works with non-hour DST change | ||
var zdt1 = Temporal.ZonedDateTime.from("2020-10-04T12:00[Australia/Lord_Howe]"); | ||
assert.sameValue(zdt1.hoursInDay, 23.5); | ||
var zdt2 = Temporal.ZonedDateTime.from("2020-04-05T12:00[Australia/Lord_Howe]"); | ||
assert.sameValue(zdt2.hoursInDay, 24.5); | ||
|
||
// hoursInDay works with non-half-hour DST change | ||
var zdt = Temporal.ZonedDateTime.from("1933-01-01T12:00[Asia/Singapore]"); | ||
assert(Math.abs(zdt.hoursInDay - 23.666666666666668) < Number.EPSILON); | ||
|
||
// hoursInDay works when day starts at 1:00 due to DST start at midnight | ||
var zdt = Temporal.ZonedDateTime.from("2015-10-18T12:00:00-02:00[America/Sao_Paulo]"); | ||
assert.sameValue(zdt.hoursInDay, 23); | ||
|
||
// startOfDay works when day starts at 1:00 due to DST start at midnight | ||
var zdt = Temporal.ZonedDateTime.from("2015-10-18T12:00:00-02:00[America/Sao_Paulo]"); | ||
assert.sameValue(`${ zdt.startOfDay().toPlainTime() }`, "01:00:00"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.