Skip to content

Commit

Permalink
Final batch of Temporal edits (#38092)
Browse files Browse the repository at this point in the history
* Fix broken links

* Note RangeError thrown by disambiguation: "reject" when wall-clock time is ambiguous

* Fix log output of ZonedDateTime

Most likely, the time zone annotation is appended if you are logging a
ZonedDateTime object.

* Fix copy-paste error

* Add link to "day example"

I found it difficult to understand what the code example was showing
because it mentioned a day example but it wasn't clear where this example
was. I think it's clearer with a link. (I split the code block in two and
moved the sentence outside of the code block so that I could put a link in
it.)
  • Loading branch information
ptomato authored Feb 11, 2025
1 parent 332c437 commit b4696c0
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ A new {{jsxref("Temporal.Instant")}} object representing subtracting `duration`

## Description

Subtracting a duration is equivalent to [adding](Web/JavaScript/Reference/Global_Objects/Temporal/Instant/add) its [negation](Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.
Subtracting a duration is equivalent to [adding](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/add) its [negation](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ The current date and time in the specified time zone, as a {{jsxref("Temporal.Zo
```js
// The current date and time in the system's time zone
const dateTime = Temporal.Now.zonedDateTimeISO();
console.log(dateTime); // e.g.: 2021-10-01T06:12:34.567890123+03:00
console.log(dateTime); // e.g.: 2021-10-01T06:12:34.567890123+03:00[Africa/Nairobi]

// The current date and time in the "America/New_York" time zone
const dateTimeInNewYork = Temporal.Now.zonedDateTimeISO("America/New_York");
console.log(dateTimeInNewYork); // e.g.: 2021-09-30T23:12:34.567890123-04:00
console.log(dateTimeInNewYork); // e.g.: 2021-09-30T23:12:34.567890123-04:00[America/New_York]
```

## Specifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ for (
) {
console.log(month.month);
}
```

Alternatively, this is also a safe way (unlike the [day example](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate/day#looping_through_all_days_in_a_month)):

// Alternatively, this is also a safe way (unlike the day example):
```js
for (let month = 1; month <= year.monthsInYear; month++) {
const monthDate = year.with({ month });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ console.log(date3.monthsInYear); // 13; 2023 is a Chinese leap year

### Changing to the second last month of the year

You can use `monthsInYear` to change to the second last day of the month:
You can use `monthsInYear` to change to the second last month of the year:

```js
const date = Temporal.PlainDate.from("2021-07-01");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ A new `Temporal.PlainDate` object representing the date specified by the origina

## Description

Subtracting a duration is equivalent to [adding](Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate/add) its [negation](Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.
Subtracting a duration is equivalent to [adding](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate/add) its [negation](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.

### Exceptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ A new `Temporal.PlainDateTime` object representing the date-time specified by th

## Description

Subtracting a duration is equivalent to [adding](Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime/add) its [negation](Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.
Subtracting a duration is equivalent to [adding](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime/add) its [negation](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ A new {{jsxref("Temporal.ZonedDateTime")}} instance representing the same date-t
### Exceptions

- {{jsxref("RangeError")}}
- : Thrown if any of the options is invalid, or if `timeZone` is not a valid time zone identifier.
- : Thrown in one of the following cases:
- Any of the options is invalid.
- `timeZone` is not a valid time zone identifier.
- The wall-clock time is ambiguous in the time zone, and `options.disambiguation` is set to `"reject"`.
- {{jsxref("TypeError")}}
- : Thrown if any of the arguments are not of the expected type.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ subtract(duration)

A new `Temporal.PlainTime` object representing the time specified by the original `PlainTime`, minus the duration.

Subtracting a duration is equivalent to [adding](Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/add) its [negation](Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.
Subtracting a duration is equivalent to [adding](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/add) its [negation](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ A new `Temporal.PlainYearMonth` object representing the year-month specified by

## Description

Subtracting a duration is equivalent to [adding](Web/JavaScript/Reference/Global_Objects/Temporal/PlainYearMonth/add) its [negation](Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply. Subtracting a positive duration starts from the end of the year-month and moves backward, so any increment smaller than the month's length is ignored.
Subtracting a duration is equivalent to [adding](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainYearMonth/add) its [negation](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply. Subtracting a positive duration starts from the end of the year-month and moves backward, so any increment smaller than the month's length is ignored.

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ A new `Temporal.ZonedDateTime` object, representing the date and time specified
- The provided properties that specify the same component are inconsistent.
- The provided non-numerical properties are not valid; for example, if `monthCode` is never a valid month code in this calendar.
- The provided numerical properties are out of range, and `options.overflow` is set to `"reject"`.
- The wall-clock time is ambiguous in the time zone, and `options.disambiguation` is set to `"reject"`.
- The info is not in the [representable range](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal#representable_dates), which is ±10<sup>8</sup> days, or about ±273,972.6 years, from the Unix epoch.

## Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ A new `Temporal.ZonedDateTime` object representing the date-time specified by th

## Description

Subtracting a duration is equivalent to [adding](Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime/add) its [negation](Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.
Subtracting a duration is equivalent to [adding](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime/add) its [negation](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated), so all the same considerations apply.

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ A new `Temporal.ZonedDateTime` object, where the fields specified in `info` that
- The provided properties that specify the same component are inconsistent.
- The provided non-numerical properties are not valid; for example, if `monthCode` is never a valid month code in this calendar.
- The provided numerical properties are out of range, and `options.overflow` is set to `"reject"`.
- The wall-clock time represented by the provided properties is ambiguous in the time zone, and `options.disambiguation` is set to `"reject"`.
- The result is not in the [representable range](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal#representable_dates), which is ±10<sup>8</sup> days, or about ±273,972.6 years, from the Unix epoch.

## Examples
Expand Down

0 comments on commit b4696c0

Please sign in to comment.