-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I messed up GIT history while rebasing, so squashing into one commit
- Loading branch information
1 parent
76da5bc
commit 9fe4bc5
Showing
40 changed files
with
10,613 additions
and
349 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
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 |
---|---|---|
@@ -1,22 +1,29 @@ | ||
// LocalDateTime POC notes | ||
// - Existing code is fine-- no DST issues. | ||
// - This function will break around DST transitions if the caller passes a | ||
// date/time duration instead of the expected absolute duration. | ||
// - The result will be easier to work with because it has its time zone already | ||
// baked in. | ||
|
||
/** | ||
* Given a localized departure time and a flight duration, get a local arrival | ||
* time in the destination time zone. | ||
* | ||
* @param {string} parseableDeparture - Departure time with time zone | ||
* @param {Temporal.Duration} flightTime - Duration of the flight | ||
* @param {Temporal.Duration} flightTime - Absolute duration of the flight | ||
* @param {Temporal.TimeZone} destinationTimeZone - Time zone in which the | ||
* flight's destination is located | ||
* @returns {Temporal.DateTime} Local arrival time | ||
* @returns {Temporal.LocalDateTime} Local arrival time | ||
*/ | ||
function getLocalizedArrival(parseableDeparture, flightTime, destinationTimeZone) { | ||
const departure = Temporal.Absolute.from(parseableDeparture); | ||
const arrival = departure.plus(flightTime); | ||
return arrival.inTimeZone(destinationTimeZone); | ||
const departure = Temporal.LocalDateTime.from(parseableDeparture); | ||
const arrival = departure.plus(flightTime, { durationKind: 'absolute' }); | ||
return arrival.with({ timeZone: destinationTimeZone }); | ||
} | ||
|
||
const arrival = getLocalizedArrival( | ||
'2020-03-08T11:55:00+08:00[Asia/Hong_Kong]', | ||
Temporal.Duration.from({ minutes: 775 }), | ||
'America/Los_Angeles' | ||
); | ||
assert.equal(arrival.toString(), '2020-03-08T09:50'); | ||
assert.equal(arrival.toString(), '2020-03-08T09:50-07:00[America/Los_Angeles]'); |
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 |
---|---|---|
@@ -1,19 +1,33 @@ | ||
// LocalDateTime POC notes | ||
// - TODO: should the string representation of an "offset time zone" include | ||
// the offset in brackets, or have nothing in brackets? If "nothing", then | ||
// should `LocalDateTime.from` also accept bracket-less strings when parsing? | ||
|
||
const absoluteTime = Temporal.Absolute.from('2020-01-03T10:41:51Z'); | ||
|
||
const result = absoluteTime.toString('Europe/Paris'); | ||
|
||
assert.equal(result, '2020-01-03T11:41:51+01:00[Europe/Paris]'); | ||
assert.equal(Temporal.Absolute.compare(absoluteTime, Temporal.Absolute.from(result)), 0); | ||
|
||
const ldt = Temporal.LocalDateTime.from({ absolute: absoluteTime, timeZone: 'Europe/Paris' }); | ||
assert.equal(ldt.toString(), '2020-01-03T11:41:51+01:00[Europe/Paris]'); | ||
assert.equal(Temporal.Absolute.compare(absoluteTime, ldt.absolute), 0); | ||
assert.equal(ldt.toDateTime().toString(), '2020-01-03T11:41:51'); | ||
|
||
// With an offset: | ||
|
||
const result2 = absoluteTime.toString('-07:00'); | ||
const ldt2 = Temporal.LocalDateTime.from({ absolute: absoluteTime, timeZone: '-07:00' }); | ||
|
||
assert.equal(result2, '2020-01-03T03:41:51-07:00'); | ||
assert.equal(ldt2.toString(), '2020-01-03T03:41:51-07:00[-07:00]'); | ||
|
||
// With a Temporal.TimeZone object: | ||
|
||
const timeZone = Temporal.TimeZone.from('Asia/Seoul'); | ||
const result3 = absoluteTime.toString(timeZone); | ||
const ldt3 = Temporal.LocalDateTime.from({ absolute: absoluteTime, timeZone: 'Asia/Seoul' }); | ||
|
||
assert.equal(result3, '2020-01-03T19:41:51+09:00[Asia/Seoul]'); | ||
assert.equal(ldt3.toString(), '2020-01-03T19:41:51+09:00[Asia/Seoul]'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const instant = Temporal.Absolute.from('2020-01-09T00:00Z'); | ||
const nyc = Temporal.TimeZone.from('America/New_York'); | ||
const ldt = Temporal.LocalDateTime.from({ absolute: '2020-01-09T00:00Z', timeZone: 'America/New_York' }); | ||
|
||
nyc.getOffsetNanosecondsFor(instant) / 1e9; // => -18000 | ||
ldt.timeZoneOffsetNanoseconds / 1e9; // => -18000 | ||
|
||
assert.equal(ldt.timeZoneOffsetNanoseconds / 1e9, '-18000'); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const instant = Temporal.Absolute.from('2020-01-09T00:00Z'); | ||
const nyc = Temporal.TimeZone.from('America/New_York'); | ||
const ldt = Temporal.LocalDateTime.from({ absolute: '2020-01-09T00:00Z', timeZone: 'America/New_York' }); | ||
|
||
nyc.getOffsetStringFor(instant); // => -05:00 | ||
ldt.timeZoneOffsetString; // => '-05:00' | ||
|
||
assert.equal(ldt.timeZoneOffsetString, '-05: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.