Skip to content

Commit

Permalink
Docs: Document hoursInDay and startOfDay when same day starts twice (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism authored and ptomato committed Nov 7, 2024
1 parent 5cb74c3 commit 9e12c46
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/zoneddatetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,14 @@ If a time zone offset transition happens exactly at midnight, the transition wil

Note that transitions that skip entire days (like the 2011 [change](https://en.wikipedia.org/wiki/Time_in_Samoa#2011_time_zone_change) of `Pacific/Apia` to the opposite side of the International Date Line) will return `24` because there are 24 real-world hours between one day's midnight and the next day's midnight.

When the same day starts twice (due to an offset transition), `hoursInDay` reflects the total amount of time between the first start of the day, and the second end of the day. For example, on 2010-11-07 at 00:00:59 (1 minute after midnight), the `America/St_Johns` time zone transitioned from offset `-02:30` to offset `-03:30`, meaning that the time transitioned to 23:01:00 on the previous day. After 1 hour of wall-clock time passed, 2010-11-07 began again:

```javascript
const zdt = Temporal.ZonedDateTime.from('2010-11-07T23:00:00-03:30[America/St_Johns]);
zdt.hoursInDay; // 25
```
Similar examples include `America/Goose_Bay` before 2010, `America/Moncton` before 2006, `Pacific/Guam` and `Pacific/Saipan` in 1969, and `America/Phoenix` in 1944.
Usage example:
<!-- prettier-ignore-start -->
Expand Down Expand Up @@ -1188,6 +1196,13 @@ const zdt = Temporal.ZonedDateTime.from('2015-10-18T12:00-02:00[America/Sao_Paul
zdt.startOfDay(); // => 2015-10-18T01:00:00-02:00[America/Sao_Paulo]
```
When the same day starts twice (due to an offset transition), the earlier time is used for `startOfDay`. For example, the `America/St_Johns` time zone transitioned from offset `-02:30` to offset `-03:30` on 2010-11-07:
```javascript
const zdt = Temporal.ZonedDateTime.from('2010-11-07T23:00:00-03:30[America/St_Johns]');
zdt.startOfDay(); // 2010-11-07T00:00:00-02:30[America/St_Johns]
```
Usage example:
<!-- prettier-ignore-start -->
Expand Down

0 comments on commit 9e12c46

Please sign in to comment.