From b4696c099a33202f1ce2063f14648de398703774 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 10 Feb 2025 17:32:41 -0800 Subject: [PATCH] Final batch of Temporal edits (#38092) * 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.) --- .../global_objects/temporal/instant/subtract/index.md | 2 +- .../global_objects/temporal/now/zoneddatetimeiso/index.md | 4 ++-- .../global_objects/temporal/plaindate/month/index.md | 5 ++++- .../global_objects/temporal/plaindate/monthsinyear/index.md | 2 +- .../global_objects/temporal/plaindate/subtract/index.md | 2 +- .../global_objects/temporal/plaindatetime/subtract/index.md | 2 +- .../temporal/plaindatetime/tozoneddatetime/index.md | 5 ++++- .../global_objects/temporal/plaintime/subtract/index.md | 2 +- .../global_objects/temporal/plainyearmonth/subtract/index.md | 2 +- .../global_objects/temporal/zoneddatetime/from/index.md | 1 + .../global_objects/temporal/zoneddatetime/subtract/index.md | 2 +- .../global_objects/temporal/zoneddatetime/with/index.md | 1 + 12 files changed, 19 insertions(+), 11 deletions(-) diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/instant/subtract/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/instant/subtract/index.md index 729a252e0a6cf1a..b1361e55e9a5173 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/instant/subtract/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/instant/subtract/index.md @@ -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 diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/now/zoneddatetimeiso/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/now/zoneddatetimeiso/index.md index 08468316e74b52d..3f5b83c163597ae 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/now/zoneddatetimeiso/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/now/zoneddatetimeiso/index.md @@ -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 diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/month/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/month/index.md index 2d88083f8ea3e2f..a2f1a0e5203dd7e 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/month/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/month/index.md @@ -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 }); } diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/monthsinyear/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/monthsinyear/index.md index 29c06cbb4ca088b..69b0a0eba312a81 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/monthsinyear/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/monthsinyear/index.md @@ -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"); diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/subtract/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/subtract/index.md index 69a72f9bd76c7ff..5f34212cb934066 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/subtract/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/plaindate/subtract/index.md @@ -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 diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/plaindatetime/subtract/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/plaindatetime/subtract/index.md index 7fcef18f5014782..f2ed92b8b631050 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/plaindatetime/subtract/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/plaindatetime/subtract/index.md @@ -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 diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/plaindatetime/tozoneddatetime/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/plaindatetime/tozoneddatetime/index.md index a9d6cf8aabda488..8bada084ac3880b 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/plaindatetime/tozoneddatetime/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/plaindatetime/tozoneddatetime/index.md @@ -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. diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/plaintime/subtract/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/plaintime/subtract/index.md index 14c654ec8835097..85c3f8fc4202349 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/plaintime/subtract/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/plaintime/subtract/index.md @@ -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 diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/plainyearmonth/subtract/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/plainyearmonth/subtract/index.md index 2443e0c92e2ec0c..e0a238c6b94e808 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/plainyearmonth/subtract/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/plainyearmonth/subtract/index.md @@ -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 diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/from/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/from/index.md index 57b4e4270a74301..ec7a18e724cce76 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/from/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/from/index.md @@ -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 ±108 days, or about ±273,972.6 years, from the Unix epoch. ## Examples diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/subtract/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/subtract/index.md index a73cc3feecdc46c..a7274b2fe936e47 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/subtract/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/subtract/index.md @@ -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 diff --git a/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/with/index.md b/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/with/index.md index 8c382b395c0bdf4..3c66efd324c9ad8 100644 --- a/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/with/index.md +++ b/files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/with/index.md @@ -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 ±108 days, or about ±273,972.6 years, from the Unix epoch. ## Examples