-
Notifications
You must be signed in to change notification settings - Fork 152
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
Partial spec for ZonedDateTime #1044
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1044 +/- ##
=======================================
Coverage 94.88% 94.88%
=======================================
Files 18 18
Lines 7134 7134
Branches 1137 1137
=======================================
Hits 6769 6769
Misses 358 358
Partials 7 7
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
spec/zoneddatetime.html
Outdated
1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]). | ||
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]]. | ||
1. Let _instant_ be ? CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]). | ||
1. Let _temporalDateTime_ be ? GetTemporalDateTimeFor(_timeZone_, _instant_). |
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.
General question: it's possible that re-building the DateTime for each property access could get quite expensive, esp in cases where you pull multiple props from the same instance which is common. Seems like an implementation may want to cache the DateTime the first time it's generated. Is that something that ECMAScript specs address? Or is that an implementation detail that the implementers worry about but the spec doesn't?
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.
I planned to find out later on what could be done to address this, so I will definitely follow up later, but my understanding is that it's not possible to cache the DateTime in the case of a custom time zone. For example, you could do this:
class MyTimeZone extends Temporal.TimeZone {
constructor() { super('bad'); }
getDateTimeFor() { return Temporal.DateTime.from('1970-01-01'); }
}
const tz = new MyTimeZone();
const zdt = new Temporal.ZonedDateTime(0n, tz);
zdt.year // => 1970
MyTimeZone.prototype.getDateTimeFor = function() { return Temporal.DateTime.from('2000-01-01'); }
zdt.year // => 2000
If we wrote in the spec that the DateTime had to be cached, then you could get into the situation where the result of zdt.year
is not equal to zdt.timeZone.getDateTimeFor(new Instant(zdt.epochNanoseconds)).year
.
Implementations can cache the calls if the time zone is a built-in one because then the call to getDateTimeFor won't be observable.
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.
Got it. As long as it's on your radar, that's good enough for me!
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.
Looks great. Your productivity is astounding! ;-)
b406b79
to
2165959
Compare
2165959
to
6acad7c
Compare
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.
I didn't go back and re-review the ZDT spec after my initial review, and it's a force-push so I'm not sure what changed since your initial checkin and my initial review, so I'm assuming that it's nothing but puppies and rainbows in there. ;-) If there are significant changes in the ZDT spec that you want me to re-review, just LMK. Thanks!
b5d2afd
to
7069424
Compare
7069424
to
3c2a164
Compare
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.
Thanks! Feel free to argue that in favour of deferring any of the comments below to a followup
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]]. | ||
1. Let _instant_ be ? CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]). | ||
1. Let _temporalDateTime_ be ? GetTemporalDateTimeFor(_timeZone_, _instant_). | ||
1. Return _temporalDateTime_.[[Hour]]. |
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.
Will need to be updated for time calendars.
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.
I'd prefer to leave this and write the spec for time calendars all at once.
1. If _smallestUnit_ is *"day"*, then | ||
1. Let _maximum_ be 1. | ||
1. Else if _smallestUnit_ is *"hour"*, then | ||
1. Let _maximum_ be 24. | ||
1. Else if _smallestUnit_ is *"minute"* or *"second"*, then | ||
1. Let _maximum_ be 60. | ||
1. Else, | ||
1. Let _maximum_ be 1000. |
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.
How many times do these steps occur now?
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.
Only twice. They are different for every type (except ZonedDateTime and PlainDateTime, now.)
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.
(I will follow up on this.)
1. Let _instant_ be ? CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]). | ||
1. Let _temporalDateTime_ be ? GetTemporalDateTimeFor(_timeZone_, _instant_). |
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.
I think it'll be better to create the DateTime in the constructor and stick it in an internal slot. Followup fine.
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.
See explanation in #1044 (comment) — the DateTime can't be cached unless the time zone is an unmodified built-in one and Temporal.TimeZone.prototype.getDateTimeFor is %Temporal.TimeZone.prototype.getDateTimeFor%.
As with the other types' constructors.
According to the latest decisions, the objects returned from ZonedDateTime.getFields() and ZonedDateTime.getISOFields() have timeZone and offset properties, so add them to the function signatures and correct the documentation.
This tells TypeScript that the valueOf() methods of these types always throw an exception.
This is a spec page which has all the correct entries for ZonedDateTime, although many of them are marked TODO. See: #569
3c2a164
to
030948e
Compare
This has all the entries for ZonedDateTime, although many of them are marked TODO. Includes a few minor other fixes.
See: #569