-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of ZonedDateTime #1073
Changes from all commits
97d5cb2
fe6c384
ff514e8
c9d11a4
f03b29f
1cb5160
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import { | |
NANOSECOND, | ||
DATE_BRAND, | ||
CALENDAR, | ||
EPOCHNANOSECONDS, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor question: why is it TIME_ZONE but EPOCHNANOSECONDS? Is there some meaning intended by not splitting EPOCH and NANOSECONDS with an underscore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's pretty arbitrary. Splitting with an underscore seems proper, but I didn't want to rename all of the existing EPOCHNANOSECONDS names used in Instant. |
||
CreateSlots, | ||
GetSlot, | ||
SetSlot | ||
|
@@ -323,6 +324,39 @@ export class Date { | |
const nanosecond = GetSlot(temporalTime, NANOSECOND); | ||
return new DateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar); | ||
} | ||
toZonedDateTime(timeZoneLike, temporalTime = undefined, options = undefined) { | ||
if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); | ||
const timeZone = ES.ToTemporalTimeZone(timeZoneLike); | ||
options = ES.NormalizeOptionsObject(options); | ||
const disambiguation = ES.ToTemporalDisambiguation(options); | ||
|
||
const year = GetSlot(this, ISO_YEAR); | ||
const month = GetSlot(this, ISO_MONTH); | ||
const day = GetSlot(this, ISO_DAY); | ||
const calendar = GetSlot(this, CALENDAR); | ||
const DateTime = GetIntrinsic('%Temporal.DateTime%'); | ||
|
||
let hour = 0, | ||
minute = 0, | ||
second = 0, | ||
millisecond = 0, | ||
microsecond = 0, | ||
nanosecond = 0; | ||
if (temporalTime !== undefined) { | ||
temporalTime = ES.ToTemporalTime(temporalTime, GetIntrinsic('%Temporal.Time%')); | ||
hour = GetSlot(temporalTime, HOUR); | ||
minute = GetSlot(temporalTime, MINUTE); | ||
second = GetSlot(temporalTime, SECOND); | ||
millisecond = GetSlot(temporalTime, MILLISECOND); | ||
microsecond = GetSlot(temporalTime, MICROSECOND); | ||
nanosecond = GetSlot(temporalTime, NANOSECOND); | ||
} | ||
|
||
const dt = new DateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar); | ||
const instant = ES.GetTemporalInstantFor(timeZone, dt, disambiguation); | ||
const ZonedDateTime = GetIntrinsic('%Temporal.ZonedDateTime%'); | ||
return new ZonedDateTime(GetSlot(instant, EPOCHNANOSECONDS), timeZone, calendar); | ||
} | ||
toYearMonth() { | ||
if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); | ||
const YearMonth = GetIntrinsic('%Temporal.YearMonth%'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, crap. This may run afoul of the guidelines we've been using that object-valued property getters must return the same (
===
) object every time. That'd imply a slot to cache this object. Probably not worth the hassle and potential runtime performance impact to keep it a property. Should we change this to astartOfDay()
method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, this is better off as a method.