-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normative: Replace TimeZone transition methods with ZonedDateTime met…
…hods TimeZone.p.getNextTransition → ZonedDateTime.p.nextTransition TimeZone.p.getPreviousTransition → ZonedDateTime.p.previousTransition This is one step towards removing Temporal.TimeZone. The functionality of querying UTC offset transition remains, but is moved to ZonedDateTime. See: #2826 Co-Authored-By: Richard Gibson <richard.gibson@gmail.com>
- Loading branch information
Showing
14 changed files
with
168 additions
and
181 deletions.
There are no files selected for viewing
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
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
34 changes: 0 additions & 34 deletions
34
docs/cookbook/getInstantOfNearestOffsetTransitionToInstant.mjs
This file was deleted.
Oops, something went wrong.
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
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,33 @@ | ||
/** | ||
* Get the nearest following exact time that the given time zone transitions | ||
* to another UTC offset, inclusive or exclusive. | ||
* | ||
* @param {Temporal.ZonedDateTime} zonedDateTime - Starting exact time and time | ||
* zone to consider | ||
* @param {boolean} inclusive - Include the start time, or not | ||
* @returns {(Temporal.ZonedDateTime|null)} - Next UTC offset transition, or | ||
* null if none known at this time | ||
*/ | ||
function getNextOffsetTransitionFromExactTime(zonedDateTime, inclusive) { | ||
let nearest; | ||
if (inclusive) { | ||
// In case instant itself is the exact time of a transition: | ||
nearest = zonedDateTime.subtract({ nanoseconds: 1 }).getTimeZoneTransition('next'); | ||
} else { | ||
nearest = zonedDateTime.getTimeZoneTransition('next'); | ||
} | ||
return nearest; | ||
} | ||
|
||
const nycTime = Temporal.ZonedDateTime.from('2019-04-16T21:01Z[America/New_York]'); | ||
|
||
const nextTransition = getNextOffsetTransitionFromExactTime(nycTime, false); | ||
assert.equal(nextTransition.toString(), '2019-11-03T01:00:00-05:00[America/New_York]'); | ||
|
||
// Inclusive | ||
const sameTransition = getNextOffsetTransitionFromExactTime(nextTransition, true); | ||
assert.equal(sameTransition.toString(), nextTransition.toString()); | ||
|
||
// No known future DST transitions in a time zone | ||
const reginaTime = Temporal.ZonedDateTime.from('2019-04-16T21:01Z[America/Regina]'); | ||
assert.equal(getNextOffsetTransitionFromExactTime(reginaTime), null); |
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
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
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
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
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
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.