Skip to content

Commit

Permalink
Docs: Write better language instead of "thing: any" for from() parame…
Browse files Browse the repository at this point in the history
…ters

Rename the parameters to "item" to match the spec text. Make clear that
they can be a string, property bag, or instance, but not other types like
number, bigint, etc.

Closes: #1394
  • Loading branch information
ptomato committed Sep 25, 2024
1 parent 28bf8dd commit efa8bb7
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 50 deletions.
6 changes: 3 additions & 3 deletions docs/duration.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ new Temporal.Duration(); // => PT0S

## Static methods

### Temporal.Duration.**from**(_thing_: any) : Temporal.Duration
### Temporal.Duration.**from**(_item_: Temporal.Duration | object | string) : Temporal.Duration

**Parameters:**

- `thing`: A `Duration`-like object or a string from which to create a `Temporal.Duration`.
- `item`: a value convertible to a `Temporal.Duration`.

**Returns:** a new `Temporal.Duration` object.

Expand All @@ -89,7 +89,7 @@ Any missing ones will be assumed to be 0.
All non-zero values must be integers, must have the same sign, and must not be infinite.
Otherwise, the function will throw a `RangeError`.

Any non-object value is converted to a string, which is expected to be in ISO 8601 format.
If the value is not an object, it must be a string, which is expected to be in ISO 8601 format.

> **NOTE:** This function understands strings where weeks and other units are combined, and strings with a single sign character at the start, which are extensions to the ISO 8601 standard described in ISO 8601-2.
> For example, `P3W1D` is understood to mean three weeks and one day, `-P1Y1M` is a negative duration of one year and one month, and `+P1Y1M` is one year and one month.
Expand Down
6 changes: 3 additions & 3 deletions docs/instant.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ turnOfTheCentury = new Temporal.Instant(-2208988800000000000n); // => 1900-01-01

## Static methods

### Temporal.Instant.**from**(_thing_: any) : Temporal.Instant
### Temporal.Instant.**from**(_item_: Temporal.Instant | string) : Temporal.Instant

**Parameters:**

- `thing`: The value representing the desired exact time.
- `item`: a value convertible to a `Temporal.Instant`.

**Returns:** a new `Temporal.Instant` object.

This static method creates a new `Temporal.Instant` object from another value.
If the value is another `Temporal.Instant` object, a new object representing the same exact time is returned.

Any other value is converted to a string, which is expected to be in ISO 8601 format, including a date, a time, and a time zone.
Otherwise, the value must be a string, which is expected to be in ISO 8601 format, including a date, a time, and a time zone.
The time zone name, if given, is ignored; only the time zone offset is taken into account.

Example usage:
Expand Down
16 changes: 8 additions & 8 deletions docs/plaindate.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ date = new Temporal.PlainDate(2020, 3, 14); // => 2020-03-14

## Static methods

### Temporal.PlainDate.**from**(_thing_: any, _options_?: object) : Temporal.PlainDate
### Temporal.PlainDate.**from**(_item_: Temporal.PlainDate | object | string, _options_?: object) : Temporal.PlainDate

**Parameters:**

- `thing`: The value representing the desired date.
- `item`: a value convertible to a `Temporal.PlainDate`.
- `options` (optional object): An object with properties representing options for constructing the date.
The following options are recognized:
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
- `overflow` (string): How to deal with out-of-range values if `item` is an object.
Allowed values are `constrain` and `reject`.
The default is `constrain`.

Expand All @@ -71,24 +71,24 @@ If the value is any other object, it:
- Must have either a number `month` property or a string `monthCode` property.
- May have a `calendar` property. If omitted, the [ISO 8601 calendar](https://en.wikipedia.org/wiki/ISO_8601#Dates) will be used by default.

Any non-object value is converted to a string, which is expected to be in ISO 8601 format.
If the value is not an object, it must be a string, which is expected to be in ISO 8601 format.
Any time part is optional and will be ignored.
Time zone or UTC offset information will also be ignored, with one exception: if a string contains a `Z` in place of a numeric UTC offset, then a `RangeError` will be thrown because interpreting these strings as a local date and time is usually a bug. `Temporal.Instant.from` should be used instead to parse these strings, and the result's `toZonedDateTimeISO` method can be used to obtain a timezone-local date and time.

In unusual cases of needing date or time components of `Z`-terminated timestamp strings (e.g. daily rollover of a UTC-timestamped log file), use the time zone `'UTC'`. For example, the following code returns a "UTC date": `Temporal.Instant.from(thing).toZonedDateTimeISO('UTC').toPlainDate()`.
In unusual cases of needing date or time components of `Z`-terminated timestamp strings (e.g. daily rollover of a UTC-timestamped log file), use the time zone `'UTC'`. For example, the following code returns a "UTC date": `Temporal.Instant.from(item).toZonedDateTimeISO('UTC').toPlainDate()`.

If the string isn't valid according to ISO 8601, then a `RangeError` will be thrown regardless of the value of `overflow`.

The `overflow` option works as follows, if `thing` is an object:
The `overflow` option works as follows, if `item` is an object:

- In `constrain` mode (the default), any out-of-range values are clamped to the nearest in-range value.
- In `reject` mode, the presence of out-of-range values will cause the function to throw a `RangeError`.

The `overflow` option is ignored if `thing` is a string.
The `overflow` option is ignored if `item` is a string.

Additionally, if the result is earlier or later than the range of dates that `Temporal.PlainDate` can represent (approximately half a million years centered on the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time)), then this function will throw a `RangeError` regardless of `overflow`.

> **NOTE**: The allowed values for the `thing.month` property start at 1, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11).
> **NOTE**: The allowed values for the `item.month` property start at 1, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11).
Example usage:

Expand Down
16 changes: 8 additions & 8 deletions docs/plaindatetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ datetime = new Temporal.PlainDateTime(2020, 3, 14, 13, 37); // => 2020-03-14T13:

## Static methods

### Temporal.PlainDateTime.**from**(_thing_: any, _options_?: object) : Temporal.PlainDateTime
### Temporal.PlainDateTime.**from**(_item_: Temporal.PlainDateTime | object | string, _options_?: object) : Temporal.PlainDateTime

**Parameters:**

- `thing`: The value representing the desired date and time.
- `item`: a value convertible to a `Temporal.PlainDateTime`.
- `options` (optional object): An object with properties representing options for constructing the date and time.
The following options are recognized:
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
- `overflow` (string): How to deal with out-of-range values if `item` is an object.
Allowed values are `constrain` and `reject`.
The default is `constrain`.

Expand All @@ -103,27 +103,27 @@ Default values for other missing fields are determined by the calendar.
If the `calendar` property is not present, it's assumed to be `'iso8601'` (identifying the [ISO 8601 calendar](https://en.wikipedia.org/wiki/ISO_8601#Dates)).
Any other missing properties will be assumed to be 0 (for time fields).

Any non-object value is converted to a string, which is expected to be in ISO 8601 format.
If the value is not an object, it must be a string, which is expected to be in ISO 8601 format.
Time zone or UTC offset information will be ignored, with one exception: if a string contains a `Z` in place of a numeric UTC offset, then a `RangeError` will be thrown because interpreting these strings as a local date and time is usually a bug. `Temporal.Instant.from` should be used instead to parse these strings, and the result's `toZonedDateTimeISO` method can be used to obtain a timezone-local date and time.

In unusual cases of needing date or time components of `Z`-terminated timestamp strings (e.g. daily rollover of a UTC-timestamped log file), use the time zone `'UTC'`. For example, the following code returns a "UTC date": `Temporal.Instant.from(thing).toZonedDateTimeISO('UTC').toPlainDate()`.
In unusual cases of needing date or time components of `Z`-terminated timestamp strings (e.g. daily rollover of a UTC-timestamped log file), use the time zone `'UTC'`. For example, the following code returns a "UTC date": `Temporal.Instant.from(item).toZonedDateTimeISO('UTC').toPlainDate()`.

If the string isn't valid according to ISO 8601, then a `RangeError` will be thrown regardless of the value of `overflow`.

The `overflow` option works as follows, if `thing` is an object:
The `overflow` option works as follows, if `item` is an object:

- In `constrain` mode (the default), any out-of-range values are clamped to the nearest in-range value.
- In `reject` mode, the presence of out-of-range values will cause the function to throw a `RangeError`.

The `overflow` option is ignored if `thing` is a string.
The `overflow` option is ignored if `item` is a string.

Additionally, if the result is earlier or later than the range of dates that `Temporal.PlainDateTime` can represent (approximately half a million years centered on the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time)), then this method will throw a `RangeError` regardless of `overflow`.

> **NOTE**: Although Temporal does not deal with leap seconds, dates coming from other software may have a `second` value of 60.
> In the default `constrain` mode and when parsing an ISO 8601 string, this will be converted to 59.
> In `reject` mode, this function will throw, so if you have to interoperate with times that may contain leap seconds, don't use `reject`.
> **NOTE**: The allowed values for the `thing.month` property start at 1, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11).
> **NOTE**: The allowed values for the `item.month` property start at 1, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11).
Example usage:

Expand Down
14 changes: 7 additions & 7 deletions docs/plainmonthday.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ md = new Temporal.PlainMonthDay(2, 29); // => 02-29

## Static methods

### Temporal.PlainMonthDay.**from**(_thing_: any, _options_?: object) : Temporal.PlainMonthDay
### Temporal.PlainMonthDay.**from**(_item_: Temporal.PlainMonthDay | object | string, _options_?: object) : Temporal.PlainMonthDay

**Parameters:**

- `thing`: The value representing the desired date.
- `item`: a value convertible to a `Temporal.PlainMonthDay`.
- `options` (optional object): An object with properties representing options for constructing the date.
The following options are recognized:
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
- `overflow` (string): How to deal with out-of-range values if `item` is an object.
Allowed values are `constrain` and `reject`.
The default is `constrain`.

Expand All @@ -73,23 +73,23 @@ If the value is any other object, it:
If `month` is used and `calendar` is provided, then `year` must be provided as well because `month` is ambiguous in some calendars without knowing the year.
- May have a `calendar` property. If omitted, the [ISO 8601 calendar](https://en.wikipedia.org/wiki/ISO_8601#Dates) will be used by default.

Any non-object value will be converted to a string, which is expected to be in ISO 8601 format.
If the value is not an object, it must be a string, which is expected to be in ISO 8601 format.
For the ISO 8601 calendar, only the month and day will be parsed from the string.
For other calendars, the year and calendar are also parsed in addition to month and day.
Any other parts of the string are optional and will be ignored.

If the string isn't valid according to ISO 8601, then a `RangeError` will be thrown regardless of the value of `overflow`.
A `RangeError` will also be thrown for strings that contain a `Z` in place of a numeric UTC offset, because interpreting these strings as a local date is usually a bug.

The `overflow` option works as follows, if `thing` is an object:
The `overflow` option works as follows, if `item` is an object:

- In `constrain` mode (the default), any out-of-range values are clamped to the nearest in-range value, with "nearest" defined by the calendar.
- In `reject` mode, the presence of out-of-range values will cause the function to throw a `RangeError`.
If `day`, `month` and `year` are provided, that calendar date must exist in the provided calendar or a `RangeError` will be thrown.

The `overflow` option is ignored if `thing` is a string.
The `overflow` option is ignored if `item` is a string.

> **NOTE**: The allowed values for the `thing.month` property start at 1, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11).
> **NOTE**: The allowed values for the `item.month` property start at 1, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11).
Example usage:

Expand Down
14 changes: 7 additions & 7 deletions docs/plaintime.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ time = new Temporal.PlainTime(13, 37); // => 13:37:00

## Static methods

### Temporal.PlainTime.**from**(_thing_: any, _options_?: object) : Temporal.PlainTime
### Temporal.PlainTime.**from**(_item_: Temporal.PlainTime | object | string, _options_?: object) : Temporal.PlainTime

**Parameters:**

- `thing`: The value representing the desired time.
- `item`: a value convertible to a `Temporal.PlainTime`.
- `options` (optional object): An object with properties representing options for constructing the time.
The following options are recognized:
- `overflow` (optional string): How to deal with out-of-range values if `thing` is an object.
- `overflow` (optional string): How to deal with out-of-range values if `item` is an object.
Allowed values are `constrain` and `reject`.
The default is `constrain`.

Expand All @@ -60,18 +60,18 @@ Any missing ones will be assumed to be 0.

If the `calendar` property is present, it must be the string `'iso8601'` or the [ISO 8601 calendar](https://en.wikipedia.org/wiki/ISO_8601#Dates), for future compatibility.

Any non-object value will be converted to a string, which is expected to be in ISO 8601 format.
If the value is not an object, it must be a string, which is expected to be in ISO 8601 format.
If the string designates a date, it will be ignored.
Time zone or UTC offset information will also be ignored, with one exception: if a string contains a `Z` in place of a numeric UTC offset, then a `RangeError` will be thrown because interpreting these strings as a local time is usually a bug. `Temporal.Instant.from` should be used instead to parse these strings, and the result's `toZonedDateTimeISO` method can be used to obtain a timezone-local date and time.

In unusual cases of needing date or time components of `Z`-terminated timestamp strings (e.g. daily rollover of a UTC-timestamped log file), use the time zone `'UTC'`. For example, the following code returns a "UTC time": `Temporal.Instant.from(thing).toZonedDateTimeISO('UTC').toPlainTime()`.
In unusual cases of needing date or time components of `Z`-terminated timestamp strings (e.g. daily rollover of a UTC-timestamped log file), use the time zone `'UTC'`. For example, the following code returns a "UTC time": `Temporal.Instant.from(item).toZonedDateTimeISO('UTC').toPlainTime()`.

The `overflow` option works as follows, if `thing` is an object:
The `overflow` option works as follows, if `item` is an object:

- In `constrain` mode (the default), any out-of-range values are clamped to the nearest in-range value.
- In `reject` mode, the presence of out-of-range values will cause the function to throw a `RangeError`.

The `overflow` option is ignored if `thing` is a string.
The `overflow` option is ignored if `item` is a string.

> **NOTE**: Although Temporal does not deal with leap seconds, times coming from other software may have a `second` value of 60.
> In the default `constrain` mode, this will be converted to 59.
Expand Down
14 changes: 7 additions & 7 deletions docs/plainyearmonth.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ ym = new Temporal.PlainYearMonth(2019, 6);

## Static methods

### Temporal.PlainYearMonth.**from**(_thing_: any, _options_?: object) : Temporal.PlainYearMonth
### Temporal.PlainYearMonth.**from**(_item_: Temporal.PlainYearMonth | object | string, _options_?: object) : Temporal.PlainYearMonth

**Parameters:**

- `thing`: The value representing the desired month.
- `item`: a value convertible to a `Temporal.PlainYearMonth`.
- `options` (optional object): An object with properties representing options for constructing the date.
The following options are recognized:
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
- `overflow` (string): How to deal with out-of-range values if `item` is an object.
Allowed values are `constrain` and `reject`.
The default is `constrain`.

Expand All @@ -75,22 +75,22 @@ A `Temporal.PlainYearMonth` will be constructed from these properties.
If the `calendar` property is not present, it's assumed to be `'iso8601'` (identifying the [ISO 8601 calendar](https://en.wikipedia.org/wiki/ISO_8601#Dates)).
In this calendar, `era` is ignored.

Any non-object value is converted to a string, which is expected to be in ISO 8601 format.
If the value is not an object, it must be a string, which is expected to be in ISO 8601 format.
Any parts of the string other than the year and the month are optional and will be ignored.

If the string isn't valid according to ISO 8601, then a `RangeError` will be thrown regardless of the value of `overflow`.
A `RangeError` will also be thrown for strings that contain a `Z` in place of a numeric UTC offset, because interpreting these strings as a local date is usually a bug.

The `overflow` option works as follows, if `thing` is an object:
The `overflow` option works as follows, if `item` is an object:

- In `constrain` mode (the default), any out-of-range values are clamped to the nearest in-range value.
- In `reject` mode, the presence of out-of-range values will cause the function to throw a `RangeError`.

The `overflow` option is ignored if `thing` is a string.
The `overflow` option is ignored if `item` is a string.

Additionally, if the result is earlier or later than the range of dates that `Temporal.PlainYearMonth` can represent (approximately half a million years centered on the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time)), then this method will throw a `RangeError` regardless of `overflow`.

> **NOTE**: The allowed values for the `thing.month` property start at 1, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11).
> **NOTE**: The allowed values for the `item.month` property start at 1, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11).
Example usage:

Expand Down
Loading

0 comments on commit efa8bb7

Please sign in to comment.