Skip to content

Commit d9d3a24

Browse files
ptomatoryzokuken
authored andcommitted
docs: Clarify that the from() overflow option doesn't apply to strings
Closes: #797
1 parent 3b1bf3f commit d9d3a24

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

docs/plaindate.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ date = new Temporal.PlainDate(2020, 3, 14); // => 2020-03-14
5555
- `thing`: The value representing the desired date.
5656
- `options` (optional object): An object with properties representing options for constructing the date.
5757
The following options are recognized:
58-
- `overflow` (string): How to deal with out-of-range values in `thing`.
58+
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
5959
Allowed values are `constrain` and `reject`.
6060
The default is `constrain`.
6161

@@ -73,11 +73,13 @@ Any non-object value is converted to a string, which is expected to be in ISO 86
7373
Any time or time zone part is optional and will be ignored.
7474
If the string isn't valid according to ISO 8601, then a `RangeError` will be thrown regardless of the value of `overflow`.
7575

76-
The `overflow` option works as follows:
76+
The `overflow` option works as follows, if `thing` is an object:
7777

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

81+
The `overflow` option is ignored if `thing` is a string.
82+
8183
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`.
8284

8385
> **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).

docs/plaindatetime.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ datetime = new Temporal.PlainDateTime(2020, 3, 14, 13, 37); // => 2020-03-14T13:
8383
- `thing`: The value representing the desired date and time.
8484
- `options` (optional object): An object with properties representing options for constructing the date and time.
8585
The following options are recognized:
86-
- `overflow` (string): How to deal with out-of-range values in `thing`.
86+
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
8787
Allowed values are `constrain` and `reject`.
8888
The default is `constrain`.
8989

@@ -103,11 +103,13 @@ Any non-object value is converted to a string, which is expected to be in ISO 86
103103
Any time zone part is optional and will be ignored.
104104
If the string isn't valid according to ISO 8601, then a `RangeError` will be thrown regardless of the value of `overflow`.
105105

106-
The `overflow` option works as follows:
106+
The `overflow` option works as follows, if `thing` is an object:
107107

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

111+
The `overflow` option is ignored if `thing` is a string.
112+
111113
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`.
112114

113115
> **NOTE**: Although Temporal does not deal with leap seconds, dates coming from other software may have a `second` value of 60.

docs/plainmonthday.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ md = new Temporal.PlainMonthDay(2, 29); // => 02-29
5555
- `thing`: The value representing the desired date.
5656
- `options` (optional object): An object with properties representing options for constructing the date.
5757
The following options are recognized:
58-
- `overflow` (string): How to deal with out-of-range values in `thing`.
58+
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
5959
Allowed values are `constrain` and `reject`.
6060
The default is `constrain`.
6161

@@ -76,12 +76,14 @@ For other calendars, the year and calendar are also parsed in addition to month
7676
Any other parts of the string are optional and will be ignored.
7777
If the string isn't valid according to ISO 8601, then a `RangeError` will be thrown regardless of the value of `overflow`.
7878

79-
The `overflow` option works as follows:
79+
The `overflow` option works as follows, if `thing` is an object:
8080

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

85+
The `overflow` option is ignored if `thing` is a string.
86+
8587
> **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).
8688
8789
Example usage:

docs/plaintime.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ time = new Temporal.PlainTime(13, 37); // => 13:37
4949
- `thing`: The value representing the desired time.
5050
- `options` (optional object): An object with properties representing options for constructing the time.
5151
The following options are recognized:
52-
- `overflow` (optional string): How to deal with out-of-range values of the other parameters.
52+
- `overflow` (optional string): How to deal with out-of-range values if `thing` is an object.
5353
Allowed values are `constrain` and `reject`.
5454
The default is `constrain`.
5555

@@ -65,11 +65,13 @@ If the `calendar` property is present, it must be the string `'iso8601'` or the
6565
Any non-object value will be converted to a string, which is expected to be in ISO 8601 format.
6666
If the string designates a date or a time zone, they will be ignored.
6767

68-
The `overflow` option works as follows:
68+
The `overflow` option works as follows, if `thing` is an object:
6969

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

73+
The `overflow` option is ignored if `thing` is a string.
74+
7375
> **NOTE**: Although Temporal does not deal with leap seconds, times coming from other software may have a `second` value of 60.
7476
> In the default `constrain` mode, this will be converted to 59.
7577
> In `reject` mode, the constructor will throw, so if you have to interoperate with times that may contain leap seconds, don't use `reject`.

docs/plainyearmonth.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ym = new Temporal.PlainYearMonth(2019, 6);
5858
- `thing`: The value representing the desired month.
5959
- `options` (optional object): An object with properties representing options for constructing the date.
6060
The following options are recognized:
61-
- `overflow` (string): How to deal with out-of-range values in `thing`.
61+
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
6262
Allowed values are `constrain` and `reject`.
6363
The default is `constrain`.
6464

@@ -76,11 +76,13 @@ Any non-object value is converted to a string, which is expected to be in ISO 86
7676
Any parts of the string other than the year and the month are optional and will be ignored.
7777
If the string isn't valid according to ISO 8601, then a `RangeError` will be thrown regardless of the value of `overflow`.
7878

79-
The `overflow` option works as follows:
79+
The `overflow` option works as follows, if `thing` is an object:
8080

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

84+
The `overflow` option is ignored if `thing` is a string.
85+
8486
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`.
8587

8688
> **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).

docs/zoneddatetime.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ new Temporal.ZonedDateTime(0n, 'America/Los_Angeles'); // same, but shorter
6060

6161
- `thing`: The value representing the desired date, time, time zone, and calendar.
6262
- `options` (optional object): An object which may have some or all of the following properties:
63-
- `overflow` (string): How to deal with out-of-range values in `thing`.
63+
- `overflow` (string): How to deal with out-of-range values if `thing` is an object.
6464
Allowed values are `'constrain'` and `'reject'`.
6565
The default is `'constrain'`.
6666
- `disambiguation` (string): How to disambiguate if the date and time given by `zonedDateTime` does not exist in the time zone, or exists more than once.
@@ -120,11 +120,13 @@ Note that using `Temporal.ZonedDateTime` with a single-offset time zone will not
120120
Therefore, using offset time zones with `Temporal.ZonedDateTime` is relatively unusual.
121121
Instead of using `Temporal.ZonedDateTime` with an offset time zone, it may be easier for most use cases to use `Temporal.PlainDateTime` and/or `Temporal.Instant` instead.
122122

123-
The `overflow` option works as follows:
123+
The `overflow` option works as follows, if `thing` is an object:
124124

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

128+
The `overflow` option is ignored if `thing` is a string.
129+
128130
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`.
129131

130132
> **NOTE**: Although Temporal does not deal with leap seconds, dates coming from other software may have a `second` value of 60.

0 commit comments

Comments
 (0)