Skip to content

Commit

Permalink
ISO 8601 -> RFC 9557
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jan 5, 2025
1 parent 1324f8d commit 44f3f7b
Show file tree
Hide file tree
Showing 32 changed files with 112 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ A new object with properties reflecting the options computed during the initiali
- : The value provided for this property in the `options` argument, or using the Unicode extension key `"nu"`, with default filled in as needed. It is a supported [numbering system](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems#supported_numbering_system_types) for this locale. The default is locale dependent.
- `timeZone`

- : The value provided for this property in the `options` argument, with default filled in as needed. It is a canonicalized [IANA time zone name](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets). The default is the runtime's default time zone.
- : The value provided for this property in the `options` argument, with default filled in as needed. It is an [IANA time zone name](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets). The default is the runtime's default time zone.

> [!NOTE]
> While the IANA database changes from time to time, the Unicode CLDR database (which browsers use) keeps old time zone names for stability purposes. All browsers canonicalize time zone names, but in different directions. For example, `new Intl.DateTimeFormat("en-US", { timeZone: "Europe/Kiev" }).resolvedOptions().timeZone` and `new Intl.DateTimeFormat("en-US", { timeZone: "Europe/Kyiv" }).resolvedOptions().timeZone` will return the same string in the same browser, but maybe different strings in different browsers. See [time zones and offsets](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets) for more information.
> The standardization of `Temporal` requires browsers to use the same identifier as originally specified, without canonicalization to a different alias. See [time zones and offsets](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets) for more information.
- `hourCycle` {{optional_inline}}
- : The value provided for this property in the `options` argument, or using the Unicode extension key `"hc"`, with default filled in as needed. If `hour12` was provided in the `options`, then that overrides other `hourCycle` settings. It is only present if the resolved options also include `hour` or `timeStyle`. It is either `"h11"`, `"h12"`, `"h23"`, or `"h24"`. The default is locale dependent, although `"h24"` is never a default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ None.

An array of strings representing supported time zones for the associated `Locale`, where each value is an [IANA time zone canonical name](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets), sorted in alphabetical order. If the locale identifier does not contain a region subtag, the returned value is `undefined`.

> [!NOTE]
> The standardization of `Temporal` requires browsers to always return the primary identifier in the IANA database, which may change over time. See [time zones and offsets](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets) for more information.
## Examples

### Obtaining supported time zones
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Intl.supportedValuesOf(key)
A sorted array of unique string values indicating the values supported by the implementation for the given key.

> [!NOTE]
> While the IANA database changes from time to time, the Unicode CLDR database (which browsers use) keeps old time zone names for stability purposes. Some browsers may use the legacy name, while others override it with the new name. See [time zones and offsets](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets) for more information.
> The standardization of `Temporal` requires browsers to always return the primary identifier in the IANA database, which may change over time. See [time zones and offsets](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets) for more information.
### Exceptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ With these tables, you should have a basic idea of how to navigate the `Temporal

### Calendars

A calendar is a way to organize days, typically into periods of weeks, months, years, and eras. Most of the world uses the Gregorian calendar, but there are many other calendars in use, especially in religious and cultural contexts. {{jsxref("Intl/Locale/getCalendars", "Intl.Locale.prototype.getCalendars()")}} lists most of the calendars likely to be supported by browsers. Here we provide a brief overview of how calendar systems are formed to help you internalize what factors may vary between calendars.
A calendar is a way to organize days, typically into periods of weeks, months, years, and eras. Most of the world uses the Gregorian calendar, but there are many other calendars in use, especially in religious and cultural contexts. By default, all calendar-aware `Temporal` objects use the ISO 8601 calendar system, which is based on the Gregorian calendar and defines additional week-numbering rules. {{jsxref("Intl/Locale/getCalendars", "Intl.Locale.prototype.getCalendars()")}} lists most of the calendars likely to be supported by browsers. Here we provide a brief overview of how calendar systems are formed to help you internalize what factors may vary between calendars.

There are three most prominent periodic events on Earth: its rotation around the sun (365.242 days for one revolution), the moon's rotation around Earth (29.5 days from new moon to new moon), and its rotation around its axis (24 hours from sunrise to sunrise). Every culture has the same measure of a "day", which is 24 hours. Occasional changes such as daylight saving time are not part of the calendar, but are part of the [time zone](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets)'s information.

Expand Down Expand Up @@ -321,6 +321,18 @@ The concept of a "week" is not connected with any astronomical event, but is a c
> - Don't assume that weeks are always 7 days long; use `daysInWeek` instead.
> - Note that the current `Temporal` API does not support year-week dates, so you can't construct dates using these properties or serialize dates to year-week representations. They are only informational properties.
### RFC 9557 format

All `Temporal` classes can be serialized and deserialized using the format specified in [RFC 9557](https://datatracker.ietf.org/doc/html/rfc9557), which is based on [ISO 8601 / RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339). The format, in its full form, is as follows (spaces are only for readability and should not be present in the actual string):

```plain
YYYY-MM-DD T HH:mm:ss.sssssssss Z/±HH:mm:ss.sssssssss [time_zone_id] [u-ca=calendar_id]
```

Different classes have different requirements for the presence of each component, so you will find a section titled "RFC 9557 format" in each class's documentation, which specifies the format recognized by that class.

This is very similar to the [date time string format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format) used by {{jsxref("Date")}}, which is also based on ISO 8601. The main addition is the ability to specify micro- and nanosecond components, and the ability to specify the time zone and calendar system.

## Static properties

- {{jsxref("Temporal.Duration")}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Temporal.Instant.from

{{JSRef}}

The **`Temporal.Instant.from()`** static method creates a new `Temporal.Instant` object from another `Temporal.Instant` object, or an ISO 8601 string.
The **`Temporal.Instant.from()`** static method creates a new `Temporal.Instant` object from another `Temporal.Instant` object, or an RFC 9557 string.

## Syntax

Expand All @@ -20,7 +20,7 @@ Temporal.Instant.from(info)
- `info`
- : One of the following:
- A {{jsxref("Temporal.Instant")}} instance, which creates a copy of the instance.
- An [ISO 8601](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#iso_8601_format) string containing a date, time, and time zone offset. The time zone name is ignored; only the offset is used.
- An [RFC 9557](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#rfc_9557_format) string containing a date, time, and time zone offset. The time zone name is ignored; only the offset is used.

### Return value

Expand All @@ -31,7 +31,7 @@ A new `Temporal.Instant` object representing the instant in time specified by `i
- {{jsxref("TypeError")}}
- : Thrown if `info` is not a `Temporal.Instant` instance or a string.
- {{jsxref("RangeError")}}
- : Thrown if the string is not a valid ISO 8601 string, or if the date and time are outside the range of representable instants (±10<sup>8</sup> days).
- : Thrown if the string is not a valid RFC 9557 string, or if the date and time are outside the range of representable instants (±10<sup>8</sup> days).

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The **`Temporal.Instant`** object represents a unique point in history, with nan

You can convert from `Date` to `Temporal.Instant` using the {{jsxref("Date.prototype.toTemporalInstant()")}} method, which should be preferred over other methods such as `Temporal.Instant.fromEpochMilliseconds()` because the former involves less user code and may be more optimized. You can also convert from `Temporal.Instant` to `Date` using its epoch milliseconds, such as `new Date(instant.epochMilliseconds)`.

### ISO 8601 format
### RFC 9557 format

`Instant` objects can be serialized and parsed using the [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601) (with some extensions specified by ECMAScript). The string has the following form (spaces are only for readability and should not be present in the actual string):
`Instant` objects can be serialized and parsed using the [RFC 9557](https://datatracker.ietf.org/doc/html/rfc9557) format, an extension to the [ISO 8601 / RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) format. The string has the following form (spaces are only for readability and should not be present in the actual string):

```plain
YYYY-MM-DD T HH:mm:ss.sssssssss Z/±HH:mm:ss.sssssssss
Expand All @@ -40,7 +40,7 @@ YYYY-MM-DD T HH:mm:ss.sssssssss Z/±HH:mm:ss.sssssssss
- `Z/±HH:mm:ss.sssssssss`
- : Either the UTC designator `Z` or `z`, or an offset from UTC in the form `+` or `-` followed by the same format as the time component. Note that subminute precision may be unsupported by other systems. If an offset is provided, the time is interpreted in the specified offset.

As an input, you may optionally include the time zone identifier and calendar, in the same format as [`ZonedDateTime`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#iso_8601_format), but they will be ignored. Other annotations in the `[key=value]` format are also ignored, and they must not have the critical flag.
As an input, you may optionally include the time zone identifier and calendar, in the same format as [`ZonedDateTime`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#rfc_9557_format), but they will be ignored. Other annotations in the `[key=value]` format are also ignored, and they must not have the critical flag.

When serializing, you can configure the fractional second digits and offset.

Expand All @@ -54,7 +54,7 @@ When serializing, you can configure the fractional second digits and offset.
- {{jsxref("Temporal/Instant/compare", "Temporal.Instant.compare()")}}
- : Returns a number (-1, 0, 1) indicating whether the first instant comes before, is the same as, or comes after the second instant. Equivalent to comparing the {{jsxref("Temporal/Instant/epochNanoseconds", "epochNanoseconds")}} of the two instants.
- {{jsxref("Temporal/Instant/from", "Temporal.Instant.from()")}}
- : Creates a new `Temporal.Instant` object from another `Temporal.Instant` object, or an ISO 8601 string.
- : Creates a new `Temporal.Instant` object from another `Temporal.Instant` object, or an RFC 9557 string.
- {{jsxref("Temporal/Instant/fromEpochMilliseconds", "Temporal.Instant.fromEpochMilliseconds()")}}
- : Creates a new `Temporal.Instant` object from the number of milliseconds since the Unix epoch (midnight at the beginning of January 1, 1970, UTC).
- {{jsxref("Temporal/Instant/fromEpochNanoseconds", "Temporal.Instant.fromEpochNanoseconds()")}}
Expand Down Expand Up @@ -86,11 +86,11 @@ These properties are defined on `Temporal.Instant.prototype` and shared by all `
- {{jsxref("Temporal/Instant/subtract", "Temporal.Instant.prototype.subtract()")}}
- : Returns a new `Temporal.Instant` object representing this instant moved backward by a given duration (in a form convertible by {{jsxref("Temporal/Duration/from", "Temporal.Duration.from()")}}).
- {{jsxref("Temporal/Instant/toJSON", "Temporal.Instant.prototype.toJSON()")}}
- : Returns a string representing this instant in the same [ISO 8601 format](#iso_8601_format) as calling {{jsxref("Temporal/Instant/toString", "toString()")}}.
- : Returns a string representing this instant in the same [RFC 9557 format](#rfc_9557_format) as calling {{jsxref("Temporal/Instant/toString", "toString()")}}.
- {{jsxref("Temporal/Instant/toLocaleString", "Temporal.Instant.prototype.toLocaleString()")}}
- : Returns a string with a language-sensitive representation of this instant. In implementations with [`Intl.DateTimeFormat` API](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) support, this method simply calls `Intl.DateTimeFormat`.
- {{jsxref("Temporal/Instant/toString", "Temporal.Instant.prototype.toString()")}}
- : Returns a string representing this instant in the [ISO 8601 format](#iso_8601_format) using the specified time zone.
- : Returns a string representing this instant in the [RFC 9557 format](#rfc_9557_format) using the specified time zone.
- {{jsxref("Temporal/Instant/toZonedDateTimeISO", "Temporal.Instant.prototype.toZonedDateTimeISO()")}}
- : Returns a new {{jsxref("Temporal.ZonedDateTime")}} object representing this instant in the specified time zone using the ISO 8601 calendar system.
- {{jsxref("Temporal/Instant/until", "Temporal.Instant.prototype.until()")}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Temporal.Instant.toJSON

{{JSRef}}

The **`toJSON()`** method of {{jsxref("Temporal.Instant")}} instances returns a string representing this instant in the same [ISO 8601 format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#iso_8601_format) as calling {{jsxref("Temporal/Instant/toString", "toString()")}}.
The **`toJSON()`** method of {{jsxref("Temporal.Instant")}} instances returns a string representing this instant in the same [RFC 9557 format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#rfc_9557_format) as calling {{jsxref("Temporal/Instant/toString", "toString()")}}.

## Syntax

Expand All @@ -21,7 +21,7 @@ None.

### Return value

A string representing the given instant in the [ISO 8601 format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#iso_8601_format), with as much subsecond precision as necessary to represent the duration accurately, and with the UTC time zone designator `Z`.
A string representing the given instant in the [RFC 9557 format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#rfc_9557_format), with as much subsecond precision as necessary to represent the duration accurately, and with the UTC time zone designator `Z`.

## Description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Temporal.Instant.toString

{{JSRef}}

The **`toString()`** method of {{jsxref("Temporal.Instant")}} instances returns a string representing this instant in the [ISO 8601 format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#iso_8601_format) using the specified time zone.
The **`toString()`** method of {{jsxref("Temporal.Instant")}} instances returns a string representing this instant in the [RFC 9557 format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#rfc_9557_format) using the specified time zone.

## Syntax

Expand All @@ -31,7 +31,7 @@ toString(options)

### Return value

A string in the [ISO 8601 format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#iso_8601_format) representing this instant using the specified time zone. No annotations, such as time zone names, are included.
A string in the [RFC 9557 format](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant#rfc_9557_format) representing this instant using the specified time zone. No annotations, such as time zone names, are included.

### Exceptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Temporal.PlainDate.from

{{JSRef}}

The **`Temporal.PlainDate.from()`** static method creates a new `Temporal.PlainDate` object from another `Temporal.PlainDate` object, an object with date properties, or an ISO 8601 string.
The **`Temporal.PlainDate.from()`** static method creates a new `Temporal.PlainDate` object from another `Temporal.PlainDate` object, an object with date properties, or an RFC 9557 string.

## Syntax

Expand All @@ -25,7 +25,7 @@ Temporal.PlainDate.from(info, options)
- A {{jsxref("Temporal.PlainDate")}} instance, which creates a copy of the instance.
- A {{jsxref("Temporal.PlainDateTime")}} instance, which provides the calendar date in the same fashion as {{jsxref("Temporal/PlainDateTime/toPlainDate", "Temporal.PlainDateTime.prototype.toPlainDate()")}}.
- A {{jsxref("Temporal.ZonedDateTime")}} instance, which provides the calendar date in the same fashion as {{jsxref("Temporal/ZonedDateTime/toPlainDate", "Temporal.ZonedDateTime.prototype.toPlainDate()")}}.
- An [ISO 8601](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate#iso_8601_format) string containing a date and optionally a calendar.
- An [RFC 9557](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate#rfc_9557_format) string containing a date and optionally a calendar.
- An object containing the following properties (in the order they are retrieved and validated):

- `calendar` {{optional_inline}}
Expand Down
Loading

0 comments on commit 44f3f7b

Please sign in to comment.