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

Normative: Handle "start of day" separately from "midnight" #2918

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Jul 16, 2024

Fixes calculations of start of day in ZonedDateTime.prototype.hoursInDay, ZonedDateTime.prototype.startOfDay(), and ZonedDateTime.prototype.round() with smallestUnit: "day".

Updates the following operations to explicitly mean "start of day" and not
"midnight":

  • PlainDate.prototype.toZonedDateTime(timeZoneString)
  • PlainDate.prototype.toZonedDateTime(options) with omitted or undefined plainTime option
  • ZonedDateTime.prototype.withPlainTime() with no argument or undefined
  • Parsing YYYY-MM-DD[Zone] anywhere a ZonedDateTime string is expected

This is in order to handle one corner case from the TZDB where clocks were set one hour ahead in America/Toronto at 23:30 on March 30, 1919, meaning that the DST skipped hour encompassed midnight but did not start or end at midnight. (This was probably just in the city of Toronto and maybe some other towns, because time was still locally administered at that time.)

Closes: #2910

@ptomato ptomato mentioned this pull request Jul 16, 2024
91 tasks
@ptomato
Copy link
Collaborator Author

ptomato commented Jul 16, 2024

I had to refactor ParseISODateTime, InterpretISODateTimeOffset, and InterpretTemporalDateTimeFields to use Time Records instead of individual integer time components. I'll split this out later into an editorial PR so that at least should simplify things a bit.

@ptomato ptomato marked this pull request as draft July 16, 2024 21:22
@ptomato
Copy link
Collaborator Author

ptomato commented Jul 16, 2024

Draft until presented at TC39.

Tests are in tc39/test262#4158

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.

lgtm

@arshaw
Copy link
Contributor

arshaw commented Jul 19, 2024

lgtm as well. nice catch for ZonedDateTime.p.round

@ptomato ptomato force-pushed the 2910-startofday-in-canada-1919 branch from 7fbb958 to 32e7b56 Compare July 20, 2024 05:10
@ptomato
Copy link
Collaborator Author

ptomato commented Jul 20, 2024

Missed a fix in the validStrings test, since the output of the parsing methods has changed.

@ptomato ptomato force-pushed the calendar-time-zone-removals branch from 6fad4bd to 4047d55 Compare July 27, 2024 00:41
@SpikyC
Copy link

SpikyC commented Jul 29, 2024

Would America/Montreal behave the same, because they didn’t advanced their clock until 2:30 A.M. on the 31st (of March)?

@arshaw
Copy link
Contributor

arshaw commented Jul 29, 2024

@SpikyC, since the lost hour you're referencing is between 2:30:00 and 3:30:00, the 00:00:00 wallclock time still exists and thus there's no issue.

Reference: https://www.timeanddate.com/time/change/canada/montreal?year=1919

@SpikyC
Copy link

SpikyC commented Jul 29, 2024

@ptomato
Copy link
Collaborator Author

ptomato commented Jul 29, 2024

If you have the version of the TZDB with the merges, in which America/Montreal is an alias for America/Toronto, then you will get this behaviour for America/Montreal as well. It is recommended, although not required, that JS implementations use the version of the TZDB without the merges: https://tc39.es/proposal-temporal/#sec-use-of-iana-time-zone-database

@ptomato ptomato force-pushed the calendar-time-zone-removals branch from 4047d55 to 493ce51 Compare July 30, 2024 00:55
@justingrant
Copy link
Collaborator

It is recommended, although not required, that JS implementations use the version of the TZDB without the merges: https://tc39.es/proposal-temporal/#sec-use-of-iana-time-zone-database

This statement isn't quite accurate. What's discouraged (and disallowed once ECMA 402 PR #877 is merged soon) is merges between countries. Merges inside countries (like America/Montreal being merged into America/Toronto) are recommended to be supported. See that PR for more details about expected behavior.

@ptomato
Copy link
Collaborator Author

ptomato commented Jul 30, 2024

My mistake, thanks for clearing up the record!

@ptomato
Copy link
Collaborator Author

ptomato commented Jul 30, 2024

Achieved consensus at TC39 plenary 2024-07-30.

@ptomato ptomato marked this pull request as ready for review July 30, 2024 22:20
@ptomato ptomato force-pushed the calendar-time-zone-removals branch 2 times, most recently from 74ec1c7 to ffa4bd6 Compare August 7, 2024 00:04
@ptomato ptomato force-pushed the calendar-time-zone-removals branch 5 times, most recently from 2b549d0 to 2fa1b21 Compare August 22, 2024 00:04
Base automatically changed from calendar-time-zone-removals to main September 5, 2024 21:03
Fixes calculations of start of day in ZonedDateTime.prototype.hoursInDay,
ZonedDateTime.prototype.startOfDay(), and ZonedDateTime.prototype.round()
with smallestUnit: "day".

Updates the following operations to explicitly mean "start of day" and not
"midnight":
- PlainDate.prototype.toZonedDateTime(timeZoneString)
- PlainDate.prototype.toZonedDateTime(options) with omitted or undefined
  plainTime option
- ZonedDateTime.prototype.withPlainTime() with no argument or undefined
- Parsing 'YYYY-MM-DD[Zone]' anywhere a ZonedDateTime string is expected

This is in order to handle one corner case from the TZDB where clocks were
set one hour ahead in America/Toronto at 23:30 on March 30, 1919, meaning
that the DST skipped hour encompassed midnight but did not start or end at
midnight. (This was probably just in the city of Toronto and maybe some
other towns, because time was still locally administered at that time.)

Closes: #2910
@ptomato ptomato force-pushed the 2910-startofday-in-canada-1919 branch from 32e7b56 to d9aff67 Compare September 5, 2024 23:50
@ptomato ptomato merged commit 792d028 into main Sep 5, 2024
5 checks passed
@ptomato ptomato deleted the 2910-startofday-in-canada-1919 branch September 5, 2024 23:57
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.

ZonedDateTime.startOfDay: is it guaranteed to be the first instant in a calendar day?
5 participants