Skip to content

Commit

Permalink
Time zone / calendar / time components
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jan 13, 2025
1 parent fc28f6b commit 2e7b76a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ A new `Temporal.Instant` object representing the instant in time specified by `e
```js
const instant = Temporal.Instant.fromEpochMilliseconds(0);
console.log(instant.toString()); // 1970-01-01T00:00:00Z
const vostok1Liftoff = Temporal.Instant.fromEpochMilliseconds(-275248380000);
console.log(vostok1Liftoff.toString()); // 1961-04-12T06:07:00Z
const sts1Liftoff = Temporal.Instant.fromEpochMilliseconds(355924804000);
console.log(sts1Liftoff.toString()); // 1981-04-12T12:00:04Z
```

## Specifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ A new `Temporal.Instant` object representing the instant in time specified by `e
```js
const instant = Temporal.Instant.fromEpochNanoseconds(0n);
console.log(instant.toString()); // 1970-01-01T00:00:00Z
const vostok1Liftoff =
Temporal.Instant.fromEpochNanoseconds(-275248380000000000n);
console.log(vostok1Liftoff.toString()); // 1961-04-12T06:07:00Z
const sts1Liftoff = Temporal.Instant.fromEpochNanoseconds(355924804000000000n);
console.log(sts1Liftoff.toString()); // 1981-04-12T12:00:04Z
```

## Specifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ A new `Temporal.Instant` object representing the instant in time specified by `e
```js
const instant = new Temporal.Instant(0n);
console.log(instant.toString()); // 1970-01-01T00:00:00Z
const vostok1Liftoff = new Temporal.Instant(-275248380000000000n);
console.log(vostok1Liftoff.toString()); // 1961-04-12T06:07:00Z
const sts1Liftoff = new Temporal.Instant(355924804000000000n);
console.log(sts1Liftoff.toString()); // 1981-04-12T12:00:04Z
```

## Specifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Typically, `minute` always goes from 0 to 59 and then back to 0, even when passi
```js
const dt = Temporal.ZonedDateTime.from(
"2021-10-03T01:59:00+10:30[Australia/Lord_Howe]",
).add({ minutes: 1 });
);
console.log(dt.minute); // 59
const dt2 = dt.add({ minutes: 1 });
console.log(dt2.minute); // 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Temporal.ZonedDateTime.timeZoneId

{{JSRef}}

The **`timeZoneId`** accessor property of {{jsxref("Temporal.ZonedDateTime")}} instances returns a string representing the [time zone identifier](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets) used to interpret the internal instant. The string is either a named identifier in the preferred case (such as `"America/New_York"`), or an offset in the form `"±hh:mm"`. Aliases are not canonicalized to the primary identifier.
The **`timeZoneId`** accessor property of {{jsxref("Temporal.ZonedDateTime")}} instances returns a string representing the [time zone identifier](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets) used to interpret the internal instant. The string is either a named identifier in the preferred case (such as `"America/New_York"`), or an offset in the form `"±hh:mm"`. If the time zone has aliases, the `timeZoneId` is the identifier used to create the `ZonedDateTime`, without canonicalization to the primary identifier.

The set accessor of `timeZoneId` is `undefined`. You cannot change this property directly. Use the {{jsxref("Temporal/ZonedDateTime/withTimeZone", "withTimeZone()")}} method to create a new `Temporal.ZonedDateTime` object with the desired new value.

Expand All @@ -31,7 +31,7 @@ const dt3 = dt2.withTimeZone("Asia/Shanghai");
console.log(dt3.timeZoneId); // "Asia/Shanghai"
```

Unlike the `timeZone` returned by {{jsxref("Intl/DatetimeFormat/resolvedOptions", "Intl.DateTimeFormat.prototype.resolvedOptions()")}}, the `timeZoneId` is never canonicalized to the primary identifier.
The `timeZoneId` is never canonicalized to the primary identifier; it is the same as the one used to create the `ZonedDateTime`.

```js
const dt = Temporal.ZonedDateTime.from(
Expand Down

0 comments on commit 2e7b76a

Please sign in to comment.