Skip to content

Commit

Permalink
Simplifications and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jan 3, 2025
1 parent ac298ef commit f385d12
Show file tree
Hide file tree
Showing 35 changed files with 44 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ console.log(d4.days); // 7
// Balance d4
const d4Balanced = d4.round({
largestUnit: "week",
relativeTo: new Temporal.PlainDate(2021, 1, 1), // ISO 8601 calendar
relativeTo: Temporal.PlainDate.from("2021-01-01"), // ISO 8601 calendar
});
console.log(d4Balanced.days); // 0
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Temporal.Duration.from(info)
- : One of the following:

- A {{jsxref("Temporal.Duration")}} instance, which creates a copy of the instance.
- An [ISO 8601](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#iso_8601_duration_format) string representing a duration.
- An object containing at least one of the following properties (in the order they are retrieved and validated):

- {{jsxref("Temporal/Duration/days", "days")}}
Expand All @@ -37,8 +38,6 @@ Temporal.Duration.from(info)

Each property should contain an integer number value. The resulting duration must not have [mixed signs](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#duration_sign), so all of these properties must have the same sign (or zero). Missing properties are treated as zero.

- An [ISO 8601](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#iso_8601_duration_format) string representing a duration.

### Return value

A new `Temporal.Duration` object, possibly [unbalanced](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#duration_balancing), with the specified components.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ console.log(d4.months); // 12
// Balance d4
const d4Balanced = d4.round({
largestUnit: "year",
relativeTo: new Temporal.PlainDate(2021, 1, 1), // ISO 8601 calendar
relativeTo: Temporal.PlainDate.from("2021-01-01"), // ISO 8601 calendar
});
console.log(d4Balanced.months); // 0
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ console.log(d4.weeks); // 0
// Balance d4
const d4Balanced = d4.round({
largestUnit: "week",
relativeTo: new Temporal.PlainDate(2021, 1, 1), // ISO 8601 calendar
relativeTo: Temporal.PlainDate.from("2021-01-01"), // ISO 8601 calendar
});
console.log(d4Balanced.weeks); // 1
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,7 @@ with(info)
### Parameters

- `info`

- : An object containing at least one of the following properties (in the order they are retrieved and validated):

- {{jsxref("Temporal/Duration/days", "days")}}
- {{jsxref("Temporal/Duration/hours", "hours")}}
- {{jsxref("Temporal/Duration/microseconds", "microseconds")}}
- {{jsxref("Temporal/Duration/milliseconds", "milliseconds")}}
- {{jsxref("Temporal/Duration/minutes", "minutes")}}
- {{jsxref("Temporal/Duration/months", "months")}}
- {{jsxref("Temporal/Duration/nanoseconds", "nanoseconds")}}
- {{jsxref("Temporal/Duration/seconds", "seconds")}}
- {{jsxref("Temporal/Duration/weeks", "weeks")}}
- {{jsxref("Temporal/Duration/years", "years")}}

Each property should contain an integer number value. The resulting duration must not have [mixed signs](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#duration_sign), so all of these properties must have the same sign (or zero), and must be the same as the original duration, unless you are replacing every non-zero field.
- : An object containing at least one of the properties recognized by {{jsxref("Temporal/Duration/from", "Temporal.Duration.from()")}}: `years`, `months`, `weeks`, `days`, `hours`, `minutes`, `seconds`, `milliseconds`, `microseconds`, `nanoseconds`. Unspecified properties use the values from the original duration.

### Return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ console.log(d4.years); // 12
// Balance d4
const d4Balanced = d4.round({
largestUnit: "year",
relativeTo: new Temporal.PlainDate(2021, 1, 1), // ISO 8601 calendar
relativeTo: Temporal.PlainDate.from("2021-01-01"), // ISO 8601 calendar
});
console.log(d4Balanced.years); // 1
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ since(other, options)
- `other`
- : A string or a {{jsxref("Temporal.Instant")}} instance representing an instant to subtract from this instant. It is converted to a `Temporal.Instant` object using the same algorithm as {{jsxref("Temporal/Instant/from", "Temporal.Instant.from()")}}.
- `options` {{optional_inline}}
- : An object containing some or all of the following properties (in the order they are retrieved and validated):
- `largestUnit` {{optional_inline}}
- : A string representing the largest unit to include in the output. The value must be one of the following: `"hour"`, `"minute"`, `"second"`, `"millisecond"`, `"microsecond"`, `"nanosecond"`, or their plural forms, or the value `"auto"` which means `"second"` or `smallestUnit`, whichever is greater. Defaults to `"auto"`. The result will not contain units larger than this; for example, if the largest unit is `"minute"`, then "1 hour 30 minutes" will become "90 minutes".
- `roundingIncrement` {{optional_inline}}
- : A number (truncated to an integer) representing the rounding increment in the given `smallestUnit`. Defaults to `1`. The increment must be a divisor of the maximum value of the unit; for example, if the unit is hours, the increment must be a divisor of 24 and must not be 24 itself, which means it can be 1, 2, 3, 4, 6, 8, or 12.
- `roundingMode` {{optional_inline}}
- : A string specifying how to round off the fractional part of `smallestUnit`. See [`Intl.NumberFormat()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingmode). Defaults to `"trunc"`.
- `smallestUnit` {{optional_inline}}
- : A string representing the smallest unit to include in the output. The value must be one of the following: `"hour"`, `"minute"`, `"second"`, `"millisecond"`, `"microsecond"`, `"nanosecond"`, or their plural forms. Defaults to `"nanosecond"`. For units larger than `"nanosecond"`, fractional parts of the `smallestUnit` will be [rounded](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/round) according to the `roundingIncrement` and `roundingMode` settings. Must be smaller or equal to `largestUnit`.
- : An object containing the options for {{jsxref("Temporal/Duration/round", "Temporal.Duration.prototype.round()")}}, which includes `largestUnit`, `roundingIncrement`, `roundingMode`, and `smallestUnit`. `largestUnit` and `smallestUnit` only accept the units: `"hour"`, `"minute"`, `"second"`, `"millisecond"`, `"microsecond"`, `"nanosecond"`, or their plural forms. For `largestUnit`, the default value `"auto"` means `"second"` or `smallestUnit`, whichever is greater. For `smallestUnit`, the default value is `"nanosecond"`.

### Return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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 object containing the following properties (in the order they are retrieved and validated):

- `calendar` {{optional_inline}}
Expand All @@ -42,8 +43,6 @@ Temporal.PlainDate.from(info, options)

The info should explicitly specify a year (as `year` or `era` and `eraYear`), a month (as `month` or `monthCode`), and a day.

- An [ISO 8601](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate#iso_8601_format) string containing a date and optionally a calendar.

- `options` {{optional_inline}}
- : An object containing the following property:
- `overflow` {{optional_inline}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ since(other, options)
- `other`
- : A string, an object, or a {{jsxref("Temporal.PlainDate")}} instance representing a date to subtract from this date. It is converted to a `Temporal.PlainDate` object using the same algorithm as {{jsxref("Temporal/PlainDate/from", "Temporal.PlainDate.from()")}}. It must have the same calendar as `this`.
- `options` {{optional_inline}}
- : An object containing some or all of the following properties (in the order they are retrieved and validated):
- `largestUnit` {{optional_inline}}
- : A string representing the largest unit to include in the output. The value must be one of the following: `"year"`, `"month"`, `"week"`, `"day"`, or their plural forms, or the value `"auto"` which means `"day"` or `smallestUnit`, whichever is greater. Defaults to `"auto"`. The result will not contain units larger than this; for example, if the largest unit is `"month"`, then "1 year 2 months" will become "14 months". Note that using [units larger than `"day"`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#calendar_durations) may make the duration not portable to other calendars or dates.
- `roundingIncrement` {{optional_inline}}
- : A number (truncated to an integer) representing the rounding increment in the given `smallestUnit`. Defaults to `1`. Must be in the inclusive range of 1 to 1e9.
- `roundingMode` {{optional_inline}}
- : A string specifying how to round off the fractional part of `smallestUnit`. See [`Intl.NumberFormat()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingmode). Defaults to `"trunc"`.
- `smallestUnit` {{optional_inline}}
- : A string representing the smallest unit to include in the output. The value must be one of the following: `"year"`, `"month"`, `"week"`, `"day"`, or their plural forms. Defaults to `"day"`. For units larger than `"day"`, fractional parts of the `smallestUnit` will be [rounded](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/round) according to the `roundingIncrement` and `roundingMode` settings. Must be smaller or equal to `largestUnit`.
- : An object containing the options for {{jsxref("Temporal/Duration/round", "Temporal.Duration.prototype.round()")}}, which includes `largestUnit`, `roundingIncrement`, `roundingMode`, and `smallestUnit`. `largestUnit` and `smallestUnit` only accept the units: `"year"`, `"month"`, `"week"`, `"day"`, or their plural forms. For `largestUnit`, the default value `"auto"` means `"day"` or `smallestUnit`, whichever is greater. For `smallestUnit`, the default value is `"day"`. The current date is used as the `relativeTo` option. Note that using [units larger than `"day"`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#calendar_durations) may make the duration not portable to other calendars or dates.

### Return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ with(info, options)
### Parameters

- `info`
- : An object containing at least one of the following properties (in the order they are retrieved and validated):
- `day` {{optional_inline}}
- : An integer that corresponds to the {{jsxref("Temporal/PlainDate/day", "day")}} property. Must be positive regardless of the `overflow` option.
- `era` and `eraYear` {{optional_inline}}
- : A string and an integer that correspond to the {{jsxref("Temporal/PlainDate/era", "era")}} and {{jsxref("Temporal/PlainDate/eraYear", "eraYear")}} properties. Are only used if the calendar system has eras. `era` and `eraYear` must be provided simultaneously. If all of `era`, `eraYear`, and `year` are provided, they must be consistent.
- `month` {{optional_inline}}
- : Corresponds to the {{jsxref("Temporal/PlainDate/month", "month")}} property. Must be positive regardless of the `overflow` option.
- `monthCode` {{optional_inline}}
- : Corresponds to the {{jsxref("Temporal/PlainDate/monthCode", "monthCode")}} property. If both `month` and `monthCode` are provided, they must be consistent.
- `year` {{optional_inline}}
- : Corresponds to the {{jsxref("Temporal/PlainDate/year", "year")}} property.
- : An object containing at least one of the properties recognized by {{jsxref("Temporal/PlainDate/from", "Temporal.PlainDate.from()")}} (except `calendar`): `day`, `era` and `eraYear`, `month`, `monthCode`, `year`. Unspecified properties use the values from the original date. You only need to provide one of `month` or `monthCode`, and one of `era` and `eraYear` or `year`, and the other will be updated accordingly.
- `options` {{optional_inline}}
- : An object containing the following property:
- `overflow` {{optional_inline}}
Expand Down Expand Up @@ -62,7 +52,7 @@ A new `Temporal.PlainDate` object, where the fields specified in `info` that are
### Using with()

```js
const date = new Temporal.PlainDate(2021, 7, 6);
const date = Temporal.PlainDate.from("2021-07-06");
const newDate = date.with({ day: date.daysInMonth });
console.log(newDate.toString()); // 2021-07-31
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Temporal.PlainDateTime.equals

{{JSRef}}

The **`equals()`** method of {{jsxref("Temporal.PlainDateTime")}} instances returns `true` if this date-time is equivalent in value to another date-time (in a form convertible by {{jsxref("Temporal/PlainDate/from", "Temporal.PlainDate.from()")}}), and `false` otherwise. They are compared both by their date and time values and their calendars, so two date-times from different calendars may be considered equal by {{jsxref("Temporal/PlainDateTime/compare", "Temporal.PlainDateTime.compare()")}} but not by `equals()`.
The **`equals()`** method of {{jsxref("Temporal.PlainDateTime")}} instances returns `true` if this date-time is equivalent in value to another date-time (in a form convertible by {{jsxref("Temporal/PlainDate/from", "Temporal.PlainDateTime.from()")}}), and `false` otherwise. They are compared both by their date and time values and their calendars, so two date-times from different calendars may be considered equal by {{jsxref("Temporal/PlainDateTime/compare", "Temporal.PlainDateTime.compare()")}} but not by `equals()`.

## Syntax

Expand All @@ -33,10 +33,10 @@ const dt1 = Temporal.PlainDateTime.from("2021-08-01");
const dt2 = Temporal.PlainDateTime.from({ year: 2021, month: 8, day: 1 });
console.log(dt1.equals(dt2)); // true

const dt3 = Temporal.PlainDate.from("2021-08-01[u-ca=japanese]");
const dt3 = Temporal.PlainDateTime.from("2021-08-01[u-ca=japanese]");
console.log(dt1.equals(dt3)); // false

const dt4 = Temporal.PlainDate.from("2021-08-01T01:00:00");
const dt4 = Temporal.PlainDateTime.from("2021-08-01T01:00:00");
console.log(dt1.equals(dt4)); // false
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Temporal.PlainDateTime.from(info, options)
- `info`
- : One of the following:
- A {{jsxref("Temporal.PlainDateTime")}} instance, which creates a copy of the instance.
- An object containing properties that are accepted by either {{jsxref("Temporal/PlainDate/from", "Temporal.PlainDate.from()")}} (`calendar`, `era`, `eraYear`, `year`, `month`, `monthCode`, `day`) or {{jsxref("Temporal/PlainTime/from", "Temporal.PlainTime.from()")}} (`hour`, `minute`, `second`, `millisecond`, `microsecond`, `nanosecond`). The info should explicitly specify a year (as `year` or `era` and `eraYear`), a month (as `month` or `monthCode`), and a day; others are optional and will be set to their default values.
- An [ISO 8601](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime#iso_8601_format) string containing a date, optionally a time, and optionally a calendar.
- An object containing properties that are recognized by either {{jsxref("Temporal/PlainDate/from", "Temporal.PlainDate.from()")}} (`calendar`, `era`, `eraYear`, `year`, `month`, `monthCode`, `day`) or {{jsxref("Temporal/PlainTime/from", "Temporal.PlainTime.from()")}} (`hour`, `minute`, `second`, `millisecond`, `microsecond`, `nanosecond`). The info should explicitly specify a year (as `year` or `era` and `eraYear`), a month (as `month` or `monthCode`), and a day; others are optional and will be set to their default values.
- `options` {{optional_inline}}
- : An object containing the following property:
- `overflow` {{optional_inline}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ since(other, options)
- `other`
- : A string, an object, or a {{jsxref("Temporal.PlainDateTime")}} instance representing a date-time to subtract from this date-time. It is converted to a `Temporal.PlainDateTime` object using the same algorithm as {{jsxref("Temporal/PlainDateTime/from", "Temporal.PlainDateTime.from()")}}. It must have the same calendar as `this`.
- `options` {{optional_inline}}
- : An object containing some or all of the following properties (in the order they are retrieved and validated):
- `largestUnit` {{optional_inline}}
- : A string representing the largest unit to include in the output. The value must be one of the following: `"year"`, `"month"`, `"week"`, `"day"`, `"hour"`, `"minute"`, `"second"`, `"millisecond"`, `"microsecond"`, `"nanosecond"`, or their plural forms, or the value `"auto"` which means `"day"` or `smallestUnit`, whichever is greater. Defaults to `"auto"`. The result will not contain units larger than this; for example, if the largest unit is `"month"`, then "1 year 2 months" will become "14 months". Note that using [units larger than `"day"`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#calendar_durations) may make the duration not portable to other calendars or dates.
- `roundingIncrement` {{optional_inline}}
- : A number (truncated to an integer) representing the rounding increment in the given `smallestUnit`. Defaults to `1`. Must be in the inclusive range of 1 to 1e9.
- `roundingMode` {{optional_inline}}
- : A string specifying how to round off the fractional part of `smallestUnit`. See [`Intl.NumberFormat()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingmode). Defaults to `"trunc"`.
- `smallestUnit` {{optional_inline}}
- : A string representing the smallest unit to include in the output. The value must be one of the following: `"year"`, `"month"`, `"week"`, `"day"`, `"hour"`, `"minute"`, `"second"`, `"millisecond"`, `"microsecond"`, `"nanosecond"`, or their plural forms. Defaults to `"nanosecond"`. For units larger than `"nanosecond"`, fractional parts of the `smallestUnit` will be [rounded](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/round) according to the `roundingIncrement` and `roundingMode` settings. Must be smaller or equal to `largestUnit`.
- : An object containing the options for {{jsxref("Temporal/Duration/round", "Temporal.Duration.prototype.round()")}}, which includes `largestUnit`, `roundingIncrement`, `roundingMode`, and `smallestUnit`. `largestUnit` and `smallestUnit` accept all possible units. For `largestUnit`, the default value `"auto"` means `"day"` or `smallestUnit`, whichever is greater. For `smallestUnit`, the default value is `"nanosecond"`. The current date is used as the `relativeTo` option. Note that using [units larger than `"day"`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#calendar_durations) may make the duration not portable to other calendars or dates.

### Return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ console.log(time.toString()); // '12:34:56'
- {{jsxref("Temporal.PlainDateTime")}}
- {{jsxref("Temporal.PlainTime")}}
- {{jsxref("Temporal/PlainDateTime/toPlainDate", "Temporal.PlainDateTime.prototype.toPlainDate()")}}
- {{jsxref("Temporal/PlainDateTime/toZonedDateTime", "Temporal.PlainDate.prototype.toZonedDateTime()")}}
- {{jsxref("Temporal/PlainDateTime/toZonedDateTime", "Temporal.PlainDateTime.prototype.toZonedDateTime()")}}
Loading

0 comments on commit f385d12

Please sign in to comment.