Skip to content

Commit

Permalink
More feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jan 9, 2025
1 parent 7a86d33 commit fc843e3
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Consider this code:
function looseJsonParse(obj) {
return eval(`(${obj})`);
}
console.log(looseJsonParse("{ a: 4 - 1, b: function () {}, c: new Date() }"));
console.log(looseJsonParse("{ a: 4 - 1, b: function () {}, c: new Map() }"));
```
Simply using indirect eval and forcing strict mode can make the code much better:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ format(date)
### Parameters

- `date`
- : The date to format. Can be a {{jsxref("Date")}} or {{jsxref("Temporal.PlainDateTime")}}; can be a {{jsxref("Temporal.PlainTime")}}, {{jsxref("Temporal.PlainDate")}}, {{jsxref("Temporal.PlainYearMonth")}}, or {{jsxref("Temporal.PlainMonthDay")}}, if the `DateTimeFormat` object was configured to print at least one relevant part of the date. Note that {{jsxref("Temporal.ZonedDateTime")}} always throws a `TypeError`; use {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}} instead.
- : The date to format. Can be a {{jsxref("Date")}} or {{jsxref("Temporal.PlainDateTime")}} object. Additionally can be a {{jsxref("Temporal.PlainTime")}}, {{jsxref("Temporal.PlainDate")}}, {{jsxref("Temporal.PlainYearMonth")}}, or {{jsxref("Temporal.PlainMonthDay")}} object if the `DateTimeFormat` object was configured to print at least one relevant part of the date.
> [!NOTE]
> A {{jsxref("Temporal.ZonedDateTime")}} object will always throw a `TypeError`; use {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}} or convert it to a {{jsxref("Temporal.PlainDateTime")}} object instead.
### Return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ formatRange(startDate, endDate)
### Parameters

- `startDate`
- : The start of the date range. Can be a {{jsxref("Date")}} or {{jsxref("Temporal.PlainDateTime")}}; can be a {{jsxref("Temporal.PlainTime")}}, {{jsxref("Temporal.PlainDate")}}, {{jsxref("Temporal.PlainYearMonth")}}, or {{jsxref("Temporal.PlainMonthDay")}}, if the `DateTimeFormat` object was configured to print at least one relevant part of the date. Note that {{jsxref("Temporal.ZonedDateTime")}} always throws a `TypeError`; use {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}} instead.
- : The start of the date range. Can be a {{jsxref("Date")}} or {{jsxref("Temporal.PlainDateTime")}} object. Additionally can be a {{jsxref("Temporal.PlainTime")}}, {{jsxref("Temporal.PlainDate")}}, {{jsxref("Temporal.PlainYearMonth")}}, or {{jsxref("Temporal.PlainMonthDay")}} object if the `DateTimeFormat` object was configured to print at least one relevant part of the date.
> [!NOTE]
> A {{jsxref("Temporal.ZonedDateTime")}} object will always throw a `TypeError`; use {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}} or convert it to a {{jsxref("Temporal.PlainDateTime")}} object instead.
- `endDate`
- : The end of the date range. Must have the same type as `startDate`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ formatRangeToParts(startDate, endDate)
### Parameters

- `startDate`
- : The start of the date range. Can be a {{jsxref("Date")}} or {{jsxref("Temporal.PlainDateTime")}}; can be a {{jsxref("Temporal.PlainTime")}}, {{jsxref("Temporal.PlainDate")}}, {{jsxref("Temporal.PlainYearMonth")}}, or {{jsxref("Temporal.PlainMonthDay")}}, if the `DateTimeFormat` object was configured to print at least one relevant part of the date. Note that {{jsxref("Temporal.ZonedDateTime")}} always throws a `TypeError`; use {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}} instead.
- : The start of the date range. Can be a {{jsxref("Date")}} or {{jsxref("Temporal.PlainDateTime")}} object. Additionally can be a {{jsxref("Temporal.PlainTime")}}, {{jsxref("Temporal.PlainDate")}}, {{jsxref("Temporal.PlainYearMonth")}}, or {{jsxref("Temporal.PlainMonthDay")}} object if the `DateTimeFormat` object was configured to print at least one relevant part of the date.
> [!NOTE]
> A {{jsxref("Temporal.ZonedDateTime")}} object will always throw a `TypeError`; use {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}} or convert it to a {{jsxref("Temporal.PlainDateTime")}} object instead.
- `endDate`
- : The end of the date range. Must have the same type as `startDate`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ formatToParts(date)
### Parameters

- `date` {{optional_inline}}
- : The date to format. Can be a {{jsxref("Date")}} or {{jsxref("Temporal.PlainDateTime")}}; can be a {{jsxref("Temporal.PlainTime")}}, {{jsxref("Temporal.PlainDate")}}, {{jsxref("Temporal.PlainYearMonth")}}, or {{jsxref("Temporal.PlainMonthDay")}}, if the `DateTimeFormat` object was configured to print at least one relevant part of the date. Note that {{jsxref("Temporal.ZonedDateTime")}} always throws a `TypeError`; use {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}} instead.
- : The date to format. Can be a {{jsxref("Date")}} or {{jsxref("Temporal.PlainDateTime")}} object. Additionally can be a {{jsxref("Temporal.PlainTime")}}, {{jsxref("Temporal.PlainDate")}}, {{jsxref("Temporal.PlainYearMonth")}}, or {{jsxref("Temporal.PlainMonthDay")}} object if the `DateTimeFormat` object was configured to print at least one relevant part of the date.
> [!NOTE]
> A {{jsxref("Temporal.ZonedDateTime")}} object will always throw a `TypeError`; use {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}} or convert it to a {{jsxref("Temporal.PlainDateTime")}} object instead.
### Return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ console.log(usedOptions.timeZone);
- {{jsxref("Date.prototype.toLocaleString()")}}
- {{jsxref("Date.prototype.toLocaleDateString()")}}
- {{jsxref("Date.prototype.toLocaleTimeString()")}}
- {{domxref("Temporal/Instant/toLocaleString", "Temporal.Instant.prototype.toLocaleString()")}}
- {{domxref("Temporal/PlainDate/toLocaleString", "Temporal.PlainDate.prototype.toLocaleString()")}}
- {{domxref("Temporal/PlainDateTime/toLocaleString", "Temporal.PlainDateTime.prototype.toLocaleString()")}}
- {{domxref("Temporal/PlainTime/toLocaleString", "Temporal.PlainTime.prototype.toLocaleString()")}}
- {{domxref("Temporal/PlainYearMonth/toLocaleString", "Temporal.PlainYearMonth.prototype.toLocaleString()")}}
- {{domxref("Temporal/PlainMonthDay/toLocaleString", "Temporal.PlainMonthDay.prototype.toLocaleString()")}}
- {{domxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}}
- {{jsxref("Temporal/Instant/toLocaleString", "Temporal.Instant.prototype.toLocaleString()")}}
- {{jsxref("Temporal/PlainDate/toLocaleString", "Temporal.PlainDate.prototype.toLocaleString()")}}
- {{jsxref("Temporal/PlainDateTime/toLocaleString", "Temporal.PlainDateTime.prototype.toLocaleString()")}}
- {{jsxref("Temporal/PlainTime/toLocaleString", "Temporal.PlainTime.prototype.toLocaleString()")}}
- {{jsxref("Temporal/PlainYearMonth/toLocaleString", "Temporal.PlainYearMonth.prototype.toLocaleString()")}}
- {{jsxref("Temporal/PlainMonthDay/toLocaleString", "Temporal.PlainMonthDay.prototype.toLocaleString()")}}
- {{jsxref("Temporal/ZonedDateTime/toLocaleString", "Temporal.ZonedDateTime.prototype.toLocaleString()")}}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A new {{jsxref("Temporal.Instant")}} object representing adding `duration` to th
- {{jsxref("RangeError")}}
- : Thrown in one of the following cases:
- `duration` is a [calendar duration](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#calendar_durations) (it has a non-zero `years`, `months`, or `weeks`), or has a non-zero `days`, because calendar durations are ambiguous without a calendar and time reference.
- The sum of `this` and `duration` overflows the maximum or underflows the minimum representable instant, which is ±10<sup>8</sup> days.
- The sum of `this` and `duration` overflows the maximum or underflows the minimum representable instant, which is ±10<sup>8</sup> days (about ±273,972.6 years).

## Description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ const instant2 = Temporal.Instant.from("1969-08-01T12:34:56.789Z");
console.log(instant2.epochMilliseconds); // -13173903211
```

### Changing epochMilliseconds

This is the method that allows you to move by any amount of time:

```js
const instant = Temporal.Instant.from("2021-08-01T12:34:56.789Z");
const instant1hourLater = instant.add({ hours: 1 });
console.log(instant1hourLater.epochMilliseconds); // 1627824896789
```

If you already know the change in milliseconds, you can also directly construct a new `Temporal.Instant` object:

```js
const instant = Temporal.Instant.from("2021-08-01T12:34:56.789Z");
const instant1hourLater = Temporal.Instant.fromEpochMilliseconds(
instant.epochMilliseconds + 3600000,
);
console.log(instant1hourLater.epochMilliseconds); // 1627824896789
```

## Specifications

{{Specifications}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The **`epochNanoseconds`** accessor property of {{jsxref("Temporal.Instant")}} i

The set accessor of `epochNanoseconds` is `undefined`. You cannot change this property directly. To create a new `Temporal.Instant` object with the desired new `epochNanoseconds` value, use the {{jsxref("Temporal/Instant/add", "add()")}} or {{jsxref("Temporal/Instant/subtract", "subtract()")}} method with the appropriate duration.

An instant can only represent ±10<sup>8</sup> days around the epoch, which is ±8.64e21 nanoseconds. Attempts to set `epochNanosecond` beyond this boundary throws a {{jsxref("RangeError")}}.
An instant can only represent ±10<sup>8</sup> days (about ±273,972.6 years) around the epoch, which is ±8.64e21 nanoseconds. Attempting to set `epochNanosecond` beyond this boundary throws a {{jsxref("RangeError")}}.

## Examples

Expand All @@ -25,6 +25,26 @@ const instant2 = Temporal.Instant.from("1969-08-01T12:34:56.789Z");
console.log(instant2.epochNanoseconds); // -13173903211000000n
```

### Changing epochNanoseconds

This is the method that allows you to move by any amount of time:

```js
const instant = Temporal.Instant.from("2021-08-01T12:34:56.789Z");
const instant1hourLater = instant.add({ hours: 1 });
console.log(instant1hourLater.epochNanoseconds); // 1627824896789000000n
```

If you already know the change in nanoseconds, you can also directly construct a new `Temporal.Instant` object:

```js
const instant = Temporal.Instant.from("2021-08-01T12:34:56.789Z");
const instant1hourLater = Temporal.Instant.fromEpochNanoseconds(
instant.epochNanoseconds + 3600000000000n,
);
console.log(instant1hourLater.epochNanoseconds); // 1627824896789000000n
```

## Specifications

{{Specifications}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 RFC 9557 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, or about ±273,972.6 years).

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A new `Temporal.Instant` object representing the instant in time specified by `e
### Exceptions

- {{jsxref("RangeError")}}
- : Thrown if `epochMilliseconds` is outside the range of a representable instant, which is ±10<sup>8</sup> days (±8.64e15 milliseconds), or if it cannot be converted to a BigInt (e.g., not an integer).
- : Thrown if `epochMilliseconds` is outside the range of a representable instant, which is ±10<sup>8</sup> days (±8.64e15 milliseconds, or about ±273,972.6 years), or if it cannot be converted to a BigInt (e.g., not an integer).

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A new `Temporal.Instant` object representing the instant in time specified by `e
### Exceptions

- {{jsxref("RangeError")}}
- : Thrown if `epochNanoseconds` is outside the range of a representable instant, which is ±10<sup>8</sup> days (±8.64e21 nanoseconds).
- : Thrown if `epochNanoseconds` is outside the range of a representable instant, which is ±10<sup>8</sup> days (±8.64e21 nanoseconds, or about ±273,972.6 years).

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A new `Temporal.Instant` object representing the instant in time specified by `e
### Exceptions

- {{jsxref("RangeError")}}
- : Thrown if `epochNanoseconds` is outside the range of a representable instant, which is ±10<sup>8</sup> days.
- : Thrown if `epochNanoseconds` is outside the range of a representable instant, which is ±10<sup>8</sup> days (±8.64e21 nanoseconds, or about ±273,972.6 years).

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A new {{jsxref("Temporal.Instant")}} object representing subtracting `duration`
- {{jsxref("RangeError")}}
- : Thrown in one of the following cases:
- `duration` is a [calendar duration](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#calendar_durations) (it has a non-zero `years`, `months`, or `weeks`), or has a non-zero `days`, because calendar durations are ambiguous without a calendar and time reference.
- The difference of `this` and `duration` overflows the maximum or underflows the minimum representable instant, which is ±10<sup>8</sup> days.
- The difference of `this` and `duration` overflows the maximum or underflows the minimum representable instant, which is ±10<sup>8</sup> days (about ±273,972.6 years).

## Description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The **`epochNanoseconds`** accessor property of {{jsxref("Temporal.ZonedDateTime

The set accessor of `epochNanoseconds` is `undefined`. You cannot change this property directly. To create a new `Temporal.ZonedDateTime` object with the desired new `epochNanoseconds` value, use the {{jsxref("Temporal/ZonedDateTime/add", "add()")}} or {{jsxref("Temporal/ZonedDateTime/subtract", "subtract()")}} method with the appropriate duration.

An instant can only represent ±10<sup>8</sup> days around the epoch, which is ±8.64e21 nanoseconds. Attempts to set `epochNanosecond` beyond this boundary throws a {{jsxref("RangeError")}}.
An instant can only represent ±10<sup>8</sup> days (about ±273,972.6 years) around the epoch, which is ±8.64e21 nanoseconds. Attempting to set `epochNanosecond` beyond this boundary throws a {{jsxref("RangeError")}}.

## Examples

Expand Down

0 comments on commit fc843e3

Please sign in to comment.