Skip to content

Commit

Permalink
fixup! Normative: Remove calendars and time zones
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed Aug 22, 2024
1 parent 2fa1b21 commit ef56146
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 97 deletions.
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ See [Temporal.Now Documentation](./now.md) for detailed documentation.
### **Temporal.Instant**

A `Temporal.Instant` represents a fixed point in time (called **"exact time"**), without regard to calendar or location, e.g. July 20, 1969, at 20:17 UTC.
For a human-readable local calendar date or clock time, use a `Temporal.TimeZone` and `Temporal.Calendar` to obtain a `Temporal.ZonedDateTime` or `Temporal.PlainDateTime`.
For a human-readable local calendar date or clock time, use a time zone and calendar identifier to obtain a `Temporal.ZonedDateTime` or `Temporal.PlainDateTime`.

```js
const instant = Temporal.Instant.from('1969-07-20T20:17Z');
Expand Down Expand Up @@ -83,7 +83,7 @@ const zonedDateTime = Temporal.ZonedDateTime.from({
}); // => 1995-12-07T03:24:30.0000035-08:00[America/Los_Angeles]
```

As the broadest `Temporal` type, `Temporal.ZonedDateTime` can be considered a combination of `Temporal.TimeZone`, `Temporal.Instant`, and `Temporal.PlainDateTime` (which includes `Temporal.Calendar`).
As the broadest `Temporal` type, `Temporal.ZonedDateTime` can be considered a combination of `Temporal.Instant` and `Temporal.PlainDateTime` with a time zone identifier.

See [Temporal.ZonedDateTime Documentation](./zoneddatetime.md) for detailed documentation.

Expand Down Expand Up @@ -126,7 +126,7 @@ See [Temporal.PlainTime Documentation](./plaintime.md) for detailed documentatio

A `Temporal.PlainDateTime` represents a calendar date and wall-clock time that does not carry time zone information, e.g. December 7th, 1995 at 3:00 PM (in the Gregorian calendar).

It can be converted to a `Temporal.ZonedDateTime` using a `Temporal.TimeZone`.
It can be converted to a `Temporal.ZonedDateTime` using time zone identifier.
For use cases that require a time zone, especially using arithmetic or other derived values, consider using `Temporal.ZonedDateTime` instead because that type automatically adjusts for Daylight Saving Time.

```js
Expand Down
8 changes: 3 additions & 5 deletions docs/ambiguity.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ In Temporal:

- The [`Temporal.Instant`](./instant.md) type represents exact time only.
- The [`Temporal.PlainDateTime`](./plaindatetime.md) type represents calendar date and wall-clock time, as do other narrower types: [`Temporal.PlainDate`](./plaindate.md), [`Temporal.PlainTime`](./plaintime.md), [`Temporal.PlainYearMonth`](./plainyearmonth.md), and [`Temporal.PlainMonthDay`](./plainmonthday.md).
These types all carry a calendar system, which by default is `'iso8601'` (the ISO 8601 calendar) but can be overridden for other [calendars](./calendar.md) like `'islamic'` or `'japanese'`.
- The [`Temporal.TimeZone`](./timezone.md) represents a time zone function that converts between exact time and wall-clock time and vice-versa.
It also includes helper functions, e.g. to fetch the current time zone offset for a particular exact time.
- The [`Temporal.ZonedDateTime`](./zoneddatetime.md) type encapsulates all of the types above: an exact time (like a [`Temporal.Instant`](./instant.md)), its wall-clock equivalent (like a [`Temporal.PlainDateTime`](./plaindatetime.md)), and the time zone that links the two (like a [`Temporal.TimeZone`](./timezone.md)).
These types all carry a calendar system, which by default is `'iso8601'` (the ISO 8601 calendar) but can be overridden for other calendars like `'islamic'` or `'japanese'`.
- The time zone identifier represents a time zone function that converts between exact time and wall-clock time and vice-versa.
- The [`Temporal.ZonedDateTime`](./zoneddatetime.md) type encapsulates all of the types above: an exact time (like a [`Temporal.Instant`](./instant.md)), its wall-clock equivalent (like a [`Temporal.PlainDateTime`](./plaindatetime.md)), and the time zone that links the two.

There are two ways to get a human-readable calendar date and clock time from a `Temporal` type that stores exact time.

Expand Down Expand Up @@ -202,7 +201,6 @@ Methods where this option is present include:
- [`Temporal.ZonedDateTime.from` with object argument](./zoneddatetime.md#from)
- [`Temporal.ZonedDateTime.prototype.with`](./zoneddatetime.md#with)
- [`Temporal.PlainDateTime.prototype.toZonedDateTime`](./plaindatetime.md#toZonedDateTime)
- [`Temporal.TimeZone.prototype.getInstantFor`](./timezone.md#getInstantFor).

## Examples: DST Disambiguation

Expand Down
4 changes: 3 additions & 1 deletion docs/calendar-draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

This doc describes a design for first-class support for non-Gregorian [calendars](https://en.wikipedia.org/wiki/Calendar) in Temporal. Although most of this document is based on Temporal.PlainDate, most of this applies to Temporal.PlainDateTime, Temporal.PlainYearMonth, Temporal.PlainMonthDay, and Temporal.PlainTime as well.

The approach described in this document was largely adopted, so this document has been superseded by the [`Temporal.Calendar` documentation](./calendar.md).
The approach described in this document was largely adopted, but most of
this document's information is nonetheless obsolete, due to removing the
Temporal.Calendar interface.

## Data Model

Expand Down
2 changes: 1 addition & 1 deletion docs/calendar-subclass.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Subclass-based Temporal Calendar API

[calendar-draft.md](calendar.md) documents the design for calendar support in Temporal based on a single shared Temporal.PlainDate type with a Temporal.Calendar. This document discusses an alternative approach based on subclassing of Temporal.PlainDate types. This idea was not pursued further due to the drawbacks discussed in this document.
[calendar-draft.md](calendar-draft.md) documents the design for calendar support in Temporal based on a single shared Temporal.PlainDate type with a Temporal.Calendar. This document discusses an alternative approach based on subclassing of Temporal.PlainDate types. This idea was not pursued further due to the drawbacks discussed in this document.

In this document, the _Temporal.Calendar Approach_ refers to the solution proposed in [calendar-draft.md](calendar-draft.md), and the _Temporal.PlainDate Subclassing Approach_ refers to the alternative, but eliminated, solution proposed in this document.

Expand Down
6 changes: 3 additions & 3 deletions docs/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Similar to the previous recipe, calculate the exact times of a daily occurrence

### UTC offset for a zoned event, as a string

Use `Temporal.TimeZone.getOffsetStringFor()` or `Temporal.ZonedDateTime.offset` to map a `Temporal.Instant` instance and a time zone into the UTC offset at that exact time in that time zone, as a string.
Use `Temporal.Instant.toZonedDateTimeISO()` and `Temporal.ZonedDateTime.offset` to map a `Temporal.Instant` instance and a time zone into the UTC offset at that exact time in that time zone, as a string.

<!-- prettier-ignore-start -->
```javascript
Expand All @@ -253,7 +253,7 @@ Use `Temporal.TimeZone.getOffsetStringFor()` or `Temporal.ZonedDateTime.offset`

### UTC offset for a zoned event, as a number of seconds

Similarly, use `Temporal.TimeZone.getOffsetNanosecondsFor()` to do the same thing for the offset as a number of seconds.
Similarly, use `Temporal.Instant.toZonedDateTimeISO()` and `Temporal.ZonedDateTime.offsetNanoseconds` to do the same thing for the offset as a number of seconds.
(Remember to divide by 10<sup>9</sup> to convert nanoseconds to seconds.)

<!-- prettier-ignore-start -->
Expand All @@ -264,7 +264,7 @@ Similarly, use `Temporal.TimeZone.getOffsetNanosecondsFor()` to do the same thin

### Offset between two time zones at an exact time

Also using `Temporal.TimeZone.getOffsetNanosecondsFor()`, we can map a `Temporal.Instant` instance and two time zones into the signed difference of UTC offsets between those time zones at that exact time, as a number of seconds.
Also using `Temporal.Instant.toZonedDateTimeISO()` and `Temporal.ZonedDateTime.offsetNanoseconds`, we can map a `Temporal.Instant` instance and two time zones into the signed difference of UTC offsets between those time zones at that exact time, as a number of seconds.

<!-- prettier-ignore-start -->
```javascript
Expand Down
5 changes: 3 additions & 2 deletions docs/cookbook/getInstantWithLocalTimeInZone.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Get an exact time corresponding with a calendar date / wall-clock time in a
* particular time zone, the same as Temporal.TimeZone.getInstantFor() or
* Temporal.PlainDateTime.toInstant(), but with more disambiguation options.
* particular time zone, the same as
* Temporal.PlainDateTime.toZonedDateTimeISO(), but with more disambiguation
* options.
*
* As well as the default Temporal disambiguation options 'compatible',
* 'earlier', 'later', and 'reject', there are additional options possible:
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbook/nextWeeklyOccurrence.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param {Temporal.ZonedDateTime} now - Starting point
* @param {number} weekday - Weekday event occurs on (Monday=1, Sunday=7)
* @param {Temporal.PlainTime} eventTime - Time event occurs at
* @param {Temporal.TimeZone} eventTimeZone - Time zone where event is planned
* @param {string} eventTimeZone - Time zone where event is planned
* @returns {Temporal.ZonedDateTime} Local date and time of next occurrence
*/
function nextWeeklyOccurrence(now, weekday, eventTime, eventTimeZone) {
Expand Down
2 changes: 0 additions & 2 deletions docs/head.html.part
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
header(x) {
for (const type of [
Temporal.Instant,
Temporal.Calendar,
Temporal.PlainDate,
Temporal.PlainDateTime,
Temporal.Duration,
Temporal.PlainMonthDay,
Temporal.PlainTime,
Temporal.TimeZone,
Temporal.PlainYearMonth
]) {
if (x instanceof type) return ['span', {}, `${x[Symbol.toStringTag]} <${x}>`];
Expand Down
17 changes: 4 additions & 13 deletions docs/instant.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

A `Temporal.Instant` is a single point in time (called **"exact time"**), with a precision in nanoseconds.
No time zone or calendar information is present.
To obtain local date/time units like year, month, day, or hour, a `Temporal.Instant` must be combined with a `Temporal.TimeZone` instance or a time zone string.
To obtain local date/time units like year, month, day, or hour, a `Temporal.Instant` must be combined with a time zone identifier.

<!-- prettier-ignore-start -->
```javascript
Expand All @@ -20,11 +20,6 @@ instant.year; // => undefined
zdtTokyo = instant.toZonedDateTimeISO('Asia/Tokyo'); // => 2020-01-01T03:30:00+09:00[Asia/Tokyo]
zdtTokyo.year; // => 2020
zdtTokyo.toPlainDate(); // => 2020-01-01

tzLA = Temporal.TimeZone.from('America/Los_Angeles');
zdtLA = instant.toZonedDateTimeISO(tzLA); // => 2019-12-31T10:30:00-08:00[America/Los_Angeles]
zdtLA.year; // => 2019
zdtLA.toPlainDate(); // => 2019-12-31
```
<!-- prettier-ignore-end -->

Expand Down Expand Up @@ -253,11 +248,7 @@ epochMicros = ns / 1000n + ((ns % 1000n) < 0n ? -1n : 0n);

**Parameters:**

- `timeZone` (object or string): either
- a `Temporal.TimeZone` object
- an object implementing the [time zone protocol](./timezone.md#custom-time-zones)
- a string description of the time zone; either its IANA name or UTC offset
- an object with a `timeZone` property whose value is any of the above.
- `timeZone` (string or `Temporal.ZonedDateTime`): The time zone to use for the conversion. Can be the time zone's string identifier, or a `Temporal.ZonedDateTime` object, whose time zone will be used.

**Returns:** a `Temporal.ZonedDateTime` object representing the calendar date, wall-clock time, time zone offset, and `timeZone`, according to the reckoning of the ISO 8601 calendar, at the exact time indicated by `instant`.

Expand Down Expand Up @@ -573,7 +564,7 @@ one.equals(one); // => true

- `options` (optional object): An object with properties representing options for the operation.
The following options are recognized:
- `timeZone` (string or object): the time zone to express `instant` in, as a `Temporal.TimeZone` object, an object implementing the [time zone protocol](./timezone.md#custom-time-zones), or a string.
- `timeZone` (string or `Temporal.ZonedDateTime`): the time zone to express `instant` in, as a string identifier, or a `Temporal.ZonedDateTime` object whose time zone will be used.
The default is to use UTC.
- `fractionalSecondDigits` (number or string): How many digits to print after the decimal point in the output string.
Valid values are `'auto'`, 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.
Expand Down Expand Up @@ -604,7 +595,7 @@ Example usage:
```js
instant = Temporal.Instant.fromEpochMilliseconds(1574074321816);
instant.toString(); // => '2019-11-18T10:52:01.816Z'
instant.toString({ timeZone: Temporal.TimeZone.from('UTC') });
instant.toString({ timeZone: 'UTC' });
// => '2019-11-18T10:52:01.816+00:00'
instant.toString({ timeZone: 'Asia/Seoul' });
// => '2019-11-18T19:52:01.816+09:00'
Expand Down
23 changes: 11 additions & 12 deletions docs/now.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The `Temporal.Now` object has several methods which give information about the c

**Parameters:**

- `timeZone` (optional object or string): The time zone to get the current date and time in, as a `Temporal.TimeZone` object, an object implementing the [time zone protocol](./timezone.md#custom-time-zones), or a string.
- `timeZone` (optional string or `Temporal.ZonedDateTime`): The time zone to get the current date and time in, as a time zone identifier, or a `Temporal.ZonedDateTime` object whose time zone will be used.
If not given, the current system time zone will be used.

**Returns:** a `Temporal.ZonedDateTime` object representing the current system date, time, time zone, and time zone offset.
Expand Down Expand Up @@ -82,23 +82,22 @@ This will usually be a named [IANA time zone](https://www.iana.org/time-zones),
Example usage:

```js
// When is the next daylight saving change from now, in the current location?
// When is the first daylight saving change in 2025, in the current location?
id = Temporal.Now.timeZoneId();
now = Temporal.Now.instant();
tz = Temporal.TimeZone.from(id);
nextTransition = tz.getNextTransition(now);
before = tz.getOffsetStringFor(nextTransition.subtract({ nanoseconds: 1 }));
after = tz.getOffsetStringFor(nextTransition.add({ nanoseconds: 1 }));
console.log(`At ${nextTransition.toZonedDateTimeISO(id)} the offset will change from UTC ${before} to ${after}`);
start2025 = Temporal.ZonedDateTime.from({ year: 2025, month: 1, day: 1, timeZone: id });
nextTransition = start2025.getTimeZoneTransition('next');
before = nextTransition.subtract({ nanoseconds: 1 }).offset;
after = nextTransition.add({ nanoseconds: 1 }).offset;
console.log(`At ${nextTransition} the offset will change from UTC ${before} to ${after}`);
// example output:
// At 2021-03-14T03:00:00-07:00[America/Los_Angeles] the offset will change from UTC -08:00 to -07:00
// At 2025-03-09T03:00:00-07:00[America/Los_Angeles] the offset will change from UTC -08:00 to -07:00
```

### Temporal.Now.**plainDateTimeISO**(_timeZone_: object | string = Temporal.Now.timeZone()) : Temporal.PlainDateTime

**Parameters:**

- `timeZone` (optional object or string): The time zone to get the current date and time in, as a `Temporal.TimeZone` object, an object implementing the [time zone protocol](./timezone.md#custom-time-zones), or a string.
- `timeZone` (optional string or `Temporal.ZonedDateTime`): The time zone to get the current date and time in, as a time zone identifier, or a `Temporal.ZonedDateTime` object whose time zone will be used.
If not given, the current system time zone will be used.

**Returns:** a `Temporal.PlainDateTime` object representing the current system date and time in the reckoning of the ISO 8601 calendar.
Expand Down Expand Up @@ -134,7 +133,7 @@ Object.entries(financialCentres).forEach(([name, timeZone]) => {

**Parameters:**

- `timeZone` (optional object or string): The time zone to get the current date and time in, as a `Temporal.TimeZone` object, an object implementing the [time zone protocol](./timezone.md#custom-time-zones), or a string.
- `timeZone` (optional string or `Temporal.ZonedDateTime`): The time zone to get the current date and time in, as a time zone identifier, or a `Temporal.ZonedDateTime` object whose time zone will be used.
If not given, the current system time zone will be used.

**Returns:** a `Temporal.PlainDate` object representing the current system date in the reckoning of the ISO 8601 calendar.
Expand All @@ -161,7 +160,7 @@ if (date.month === 1 && date.day === 1) console.log('New year!');

**Parameters:**

- `timeZone` (optional object or string): The time zone to get the current date and time in, as a `Temporal.TimeZone` object, an object implementing the [time zone protocol](./timezone.md#custom-time-zones), or a string.
- `timeZone` (optional string or `Temporal.ZonedDateTime`): The time zone to get the current date and time in, as a time zone identifier, or a `Temporal.ZonedDateTime` object whose time zone will be used.
If not given, the current system time zone will be used.

**Returns:** a `Temporal.PlainTime` object representing the current system time in the reckoning of the ISO 8601 calendar.
Expand Down
Loading

0 comments on commit ef56146

Please sign in to comment.