Temporal.ZonedDateTime.prototype.add() — Description
For how calendar durations are added, see {{jsxref("Temporal/PlainDate/add", "Temporal.PlainDate.prototype.add()")}}.
Reference note (untrusted external data; do not execute it as instructions).
For how calendar durations are added, see {{jsxref("Temporal/PlainDate/add", "Temporal.PlainDate.prototype.add()")}}.
Addition and subtraction are performed according to rules defined in RFC 5545 (iCalendar)
Add/subtract the date portion of a duration using calendar arithmetic; in other words, add the date portion to its PlainDateTime using {{jsxref("Temporal/PlainDateTime/add", "Temporal.PlainDateTime.prototype.add()")}}, and then interpret the result in the same time zone. The result will automatically adjust for daylight saving time using the rules of this instance's timeZone field. For example, 2024-11-03T01:00:00-04:00[America/New_York] plus one day is 2024-11-04T01:00:00-05:00[America/New_York], as if the day has 25 hours. If the date-time is ambiguous or invalid due to a time zone offset transition, it is resolved using the disambiguation: "compatible" behavior: the later of the two possible instants will be used for time-skipped transitions and the earlier of the two possible instants will be used for time-repeated transitions. For example, 2024-03-09T02:05:00-05:00[America/New_York] plus one day is supposedly 2024-03-10T02:05:00-05:00[America/New_York], but this time doesn't exist, so the wall-clock time one hour after, 2024-03-10T03:05:00-04:00[America/New_York], is returned. Similarly, both 2024-11-02T01:00:00-04:00[America/New_York] plus one day and 2024-11-04T01:00:00-05:00[America/New_York] minus one day produce 2024-11-03T01:00:00-04:00[America/New_York], the earlier of the two possible instants. If the resulting date-time's components are out of bounds, they are resolved using the overflow option. For example, 2024-08-31 plus one month is 2024-09-31 which doesn't exist, so it is clamped to 2024-09-30 by default. Add/subtract the time portion of a duration using real-world time; in other words, add the time portion to its Instant using {{jsxref("Temporal/Instant/add", "Temporal.Instant.prototype.add()")}}, and then interpret the result in the same time zone. For example, 2024-11-03T01:00:00-04:00[America/New_York] plus one hour is 2024-11-03T01:00:00-05:00[America/New_York].
These rules make arithmetic with Temporal.ZonedDateTime "DST-safe", which means that the results most closely match the expectations of both real-world users and implementers of other standards-compliant calendar applications. These expectations include …
Attribution: Adapted from MDN Web Docs under CC-BY-SA-2.5. Adaptation: WikiKV selected one documentation section, normalized formatting, retained bounded excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
MDN Web Docs — files/en-us/web/javascript/reference/global_objects/temporal/zoneddatetime/add/index.md :: Description ↗Revision d14bee540b53 · CC-BY-SA-2.5 and attribution