Skip to content

[Temporal] relativeto cleanup and move Duration staging old/accepts-...#4924

Open
ioannad wants to merge 1 commit intotc39:mainfrom
ioannad:temporal-staging-duration-old-datetime-strings-and-cleanup
Open

[Temporal] relativeto cleanup and move Duration staging old/accepts-...#4924
ioannad wants to merge 1 commit intotc39:mainfrom
ioannad:temporal-staging-duration-old-datetime-strings-and-cleanup

Conversation

@ioannad
Copy link
Contributor

@ioannad ioannad commented Feb 12, 2026

Some tests in test/staging/Temporal/Duration/old/accepts-datetime-strings-or-fields-for-relativeTo.js are covered by tests in

  • test/built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime.js
  • test/built-ins/Temporal/Duration/prototype/total/relativeto-string-plaindatetime.js
  • test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-no-time-units.js
  • test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-optional-properties.js

Merge test/built-ins/Temporal/Duration/prototype/total/relativeto-string-plaindatetime.js into test/built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime.js, rename the latter to test/built-ins/Temporal/Duration/prototype/total/relativeto-string.js, refactor the latter using forEach,
moving the throwing cases into relativeto-string-invalid.js, removing the test case covered by relativeto-string-zoneddatetime-wrong-offset.js, and finally add the only not covered staging test case "20200101" to it (similarly for round and create such a file for compare).

Remove the test/built-ins/Temporal/Duration/prototype/round/accepts-datetime-strings-for-relative-to.js which is very similar to the staging test this PR removes, because its tests are covered by

  • test/built-ins/Temporal/Duration/prototype/round/relativeto-string-datetime.js
  • test/built-ins/Temporal/Duration/prototype/round/relativeto-string-date.js (just renamed from relativeto-string-plaindatetime.js)
  • test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-no-time-units.js
  • test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-optional-properties.js

Additionally, for total:

  • Merge relativeto-string-zoneddatetime.js into `relativeto-string.js.
    • Same also for round and compare.
  • Merge relativeto-string-plaindatetime-invalid.js into relativeto-string-limits.js.
  • Delete relativeto-number.js and does-not-accept-non-string-primitives-for-relative-to.js because they are covered by relativeto-wrong-type.js.
    • Same also for round.
  • Merge throws-on-wrong-offset-for-zoneddatetime-relativeto.js into relativeto-string-zoneddatetime-wrong-offset.js, and rename the latter to relativeto-string-wrong-offset.js.
    • Similarly for round, and compare.
  • Rename all *relative-to*, *relativeTo*, and *relative test files with relativeto-* names (also for round and for compare). This to to make reviewing and cleanup easier, by bunching up the relativeto tests.

…m old/accepts-datetime-strings-or-fields-for-relativeTo

Some tests in `test/staging/Temporal/Duration/old/accepts-datetime-strings-or-fields-for-relativeTo.js`
are covered by tests in
- `test/built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime.js`
- `test/built-ins/Temporal/Duration/prototype/total/relativeto-string-plaindatetime.js`
- `test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-no-time-units.js`
- `test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-optional-properties.js`

Merge `test/built-ins/Temporal/Duration/prototype/total/relativeto-string-plaindatetime.js` into
`test/built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime.js`,
rename the latter to `test/built-ins/Temporal/Duration/prototype/total/relativeto-string.js`,
refactor the latter using `forEach`,
moving the throwing cases into `relativeto-string-invalid.js`,
removing the test case covered by `relativeto-string-zoneddatetime-wrong-offset.js`,
and finally add the only not covered staging test case "20200101" to it
(similarly for `round` and create such a file for `compare`).

Remove the `test/built-ins/Temporal/Duration/prototype/round/accepts-datetime-strings-for-relative-to.js`
which is very similar to the staging test this PR removes, because its tests are covered by
- `test/built-ins/Temporal/Duration/prototype/round/relativeto-string-datetime.js`
- `test/built-ins/Temporal/Duration/prototype/round/relativeto-string-date.js`
  (just renamed from `relativeto-string-plaindatetime.js`)
- `test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-no-time-units.js`
- `test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-optional-properties.js`

Additionally, for `total`:
- Merge `relativeto-string-zoneddatetime.js` into `relativeto-string.js.
  + Same also for `round` and `compare`.
- Merge `relativeto-string-plaindatetime-invalid.js` into `relativeto-string-limits.js`.
- Delete `relativeto-number.js` and `does-not-accept-non-string-primitives-for-relative-to.js` because
  they are covered by `relativeto-wrong-type.js`.
  + Same also for `round`.
- Merge `throws-on-wrong-offset-for-zoneddatetime-relativeto.js` into
  `relativeto-string-zoneddatetime-wrong-offset.js`, and rename the latter to
  `relativeto-string-wrong-offset.js`.
  + Similarly for `round`, and `compare`.
- Rename all `*relative-to*`, `*relativeTo*`, and `*relative` test files with `relativeto-*` names
  (also for `round` and for `compare`). This to to make reviewing and cleanup easier, by bunching up
  the relativeto tests.
@ioannad ioannad requested a review from a team as a code owner February 12, 2026 15:25
Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup! Approved with one minor adjustment.

const relativeTo = "2000-01-01T00:00+05:30[UTC]";
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo }));
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo: "2000-01-01T00:00+05:30[UTC]" }));
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo: "1971-01-01T00:00+02:00[-00:44:30]" }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion for improvement here. The existing test was probably written when sub-minute precision was still allowed in brackets. But it is no longer valid so this string fails to parse before the offset is computed. Something like this would be better:

Suggested change
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo: "1971-01-01T00:00+02:00[-00:44:30]" }));
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo: "1971-01-01T00:00+02:00[-00:44]" }));


assert.throws(RangeError, () => instance2.round({
smallestUnit: "seconds",
relativeTo: "1971-01-01T00:00+02:00[-00:44:30]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Suggested change
relativeTo: "1971-01-01T00:00+02:00[-00:44:30]"
relativeTo: "1971-01-01T00:00+02:00[-00:44]"


assert.throws(RangeError, () => instance2.total({
unit: "months",
relativeTo: "1971-01-01T00:00+02:00[-00:44:30]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
relativeTo: "1971-01-01T00:00+02:00[-00:44:30]"
relativeTo: "1971-01-01T00:00+02:00[-00:44]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants