Skip to content
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

Merged
merged 4 commits into from
Oct 28, 2020
Merged

Partial spec for ZonedDateTime #1044

merged 4 commits into from
Oct 28, 2020

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Oct 23, 2020

This has all the entries for ZonedDateTime, although many of them are marked TODO. Includes a few minor other fixes.

See: #569

@codecov
Copy link

codecov bot commented Oct 23, 2020

Codecov Report

Merging #1044 into main will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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           
Flag Coverage Δ
#test262 45.61% <ø> (ø)
#tests 91.18% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 317c618...030948e. Read the comment docs.

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_).
Copy link
Collaborator

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?

Copy link
Collaborator Author

@ptomato ptomato Oct 23, 2020

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.

Copy link
Collaborator

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!

Copy link
Collaborator

@justingrant justingrant left a 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! ;-)

@ptomato ptomato force-pushed the zoneddatetime-spec branch 2 times, most recently from b406b79 to 2165959 Compare October 24, 2020 18:36
docs/zoneddatetime.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@justingrant justingrant left a 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!

@ptomato ptomato force-pushed the zoneddatetime-spec branch 3 times, most recently from b5d2afd to 7069424 Compare October 27, 2020 01:35
Copy link
Collaborator

@Ms2ger Ms2ger left a 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

spec/zoneddatetime.html Outdated Show resolved Hide resolved
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
1. Let _instant_ be ? CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]).
1. Let _temporalDateTime_ be ? GetTemporalDateTimeFor(_timeZone_, _instant_).
1. Return _temporalDateTime_.[[Hour]].
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

spec/zoneddatetime.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
Comment on lines +691 to +701
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.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.)

Copy link
Collaborator Author

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.)

spec/zoneddatetime.html Outdated Show resolved Hide resolved
Comment on lines +161 to +165
1. Let _instant_ be ? CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]).
1. Let _temporalDateTime_ be ? GetTemporalDateTimeFor(_timeZone_, _instant_).
Copy link
Collaborator

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.

Copy link
Collaborator Author

@ptomato ptomato Oct 28, 2020

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
@ptomato ptomato merged commit 643fd26 into main Oct 28, 2020
@ptomato ptomato deleted the zoneddatetime-spec branch October 28, 2020 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants