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

Use Temporal.Now.timeZoneId() instead of timeZone() #3027

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cookbook/fromLegacyDate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ assert.equal(instant.toString(), '1970-01-01T00:00:01Z');

// To use the system's local time zone, which corresponds to using
// legacy Date's getFullYear(), getMonth(), etc. methods, pass
// Temporal.Now.timeZone() as the time zone. In a browser, this
// Temporal.Now.timeZoneId() as the time zone. In a browser, this
// will be the user's time zone, but on a server the value may not
// be what you expect, so avoid doing this in a server context.

Expand Down
4 changes: 2 additions & 2 deletions docs/instant.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ Conversions to narrower types like `Temporal.PlainDate` or `Temporal.PlainTime`
```javascript
date = new Date(2019, 11, 31, 18, 30); // => Tue Dec 31 2019 18:30:00 GMT-0800 (Pacific Standard Time)
instant = date.toTemporalInstant(); // => 2020-01-01T02:30:00Z
zonedDateTime = instant.toZonedDateTimeISO(Temporal.Now.timeZone());
zonedDateTime = instant.toZonedDateTimeISO(Temporal.Now.timeZoneId());
// => 2019-12-31T18:30:00-08:00[America/Los_Angeles]
zonedDateTime.day; // => 31
dateOnly = zonedDateTime.toPlainDate(); // => 2019-12-31
```
<!-- prettier-ignore-end -->

Bugs in `Date`=>`Temporal` conversions can be caused by picking the wrong time zone when converting from `Temporal.Instant` to `Temporal.ZonedDateTime`.
For example, the example above constructs the `Date` using local-timezone parameters, so it uses the system time zone: `Temporal.Now.timeZone()`.
For example, the example above constructs the `Date` using local-timezone parameters, so it uses the system time zone: `Temporal.Now.timeZoneId()`.
But if the `Date` had been initialized with a string like `'2019-12-31'`, then getting the same date back in a `Temporal.PlainDate` would require using the `'UTC'` time zone instead.

For discussion and code examples about picking the correct time zone, and also about `Date`<=>`Temporal` interoperability in general, see [Converting between `Temporal` types and legacy `Date`](cookbook.md#converting-between-temporal-types-and-legacy-date) in the documentation cookbook.
Expand Down
8 changes: 4 additions & 4 deletions docs/now.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The `Temporal.Now` object has several methods which give information about the c

## Methods

### Temporal.Now.**zonedDateTimeISO**(_timeZone_: object | string = Temporal.Now.timeZone()) : Temporal.ZonedDateTime
### Temporal.Now.**zonedDateTimeISO**(_timeZone_: object | string = Temporal.Now.timeZoneId()) : Temporal.ZonedDateTime

**Parameters:**

Expand Down Expand Up @@ -93,7 +93,7 @@ console.log(`At ${nextTransition} the offset will change from UTC ${before} to $
// At 2025-03-09T03:00:00-07:00[America/Los_Angeles] the offset will change from UTC -08:00 to -07:00
```

### Temporal.Now.**plainDateTimeISO**(_timeZone_: object | string = Temporal.Now.timeZone()) : Temporal.PlainDateTime
### Temporal.Now.**plainDateTimeISO**(_timeZone_: object | string = Temporal.Now.timeZoneId()) : Temporal.PlainDateTime

**Parameters:**

Expand Down Expand Up @@ -129,7 +129,7 @@ Object.entries(financialCentres).forEach(([name, timeZone]) => {
```
<!-- prettier-ignore-end -->

### Temporal.Now.**plainDateISO**(_timeZone_: object | string = Temporal.Now.timeZone()) : Temporal.PlainDate
### Temporal.Now.**plainDateISO**(_timeZone_: object | string = Temporal.Now.timeZoneId()) : Temporal.PlainDate

**Parameters:**

Expand All @@ -156,7 +156,7 @@ date = Temporal.Now.plainDateISO().withCalendar('persian');
if (date.month === 1 && date.day === 1) console.log('New year!');
```

### Temporal.Now.**plainTimeISO**(_timeZone_: object | string = Temporal.Now.timeZone()) : Temporal.PlainTime
### Temporal.Now.**plainTimeISO**(_timeZone_: object | string = Temporal.Now.timeZoneId()) : Temporal.PlainTime

**Parameters:**

Expand Down
Loading