Skip to content

Conversation

@ptomato
Copy link
Collaborator

@ptomato ptomato commented Jan 15, 2026

This feature has been buggy for years and nobody noticed, so it must not be used very often. This is an alternative solution to fix the bug in issue #3197 and would supersede #3208 if accepted.

This changes PlainYearMonth.prototype.add/subtract to throw a RangeError if the supplied duration has nonzero weeks, days, or time units. (Only years and months are allowed.)

This does not change the behaviour of PlainDate.prototype.add/subtract, because there are more use cases for adding e.g. { hours: 48 }, and days are always 24 hours in PlainDate.

Closes: #3197

@acutmore
Copy link

This PR achieved consensus during TC39 plenary yesterday (2025-01-20) 🎉

ptomato added a commit to ptomato/test262 that referenced this pull request Jan 22, 2026
Durations with units lower than months are no longer allowed. (The lower
units may be present but 0.) Adjust the existing PlainYearMonth addition
tests to test this behaviour and delete tests that are now irrelevant.

Normative change: tc39/proposal-temporal#3253
Approved in 2026-01 TC39 plenary.
ptomato added a commit to ptomato/test262 that referenced this pull request Jan 22, 2026
Durations with units lower than months are no longer allowed. (The lower
units may be present but 0.) Adjust the existing PlainYearMonth addition
tests to test this behaviour and delete tests that are now irrelevant.

Normative change: tc39/proposal-temporal#3253
Approved in 2026-01 TC39 plenary.
ptomato added a commit to ptomato/test262 that referenced this pull request Jan 22, 2026
Durations with units lower than months are no longer allowed. (The lower
units may be present but 0.) Adjust the existing PlainYearMonth addition
tests to test this behaviour and delete tests that are now irrelevant.

Normative change: tc39/proposal-temporal#3253
Approved in 2026-01 TC39 plenary.
@ptomato
Copy link
Collaborator Author

ptomato commented Jan 22, 2026

Test262 tests in tc39/test262#4883

Ms2ger pushed a commit to ptomato/test262 that referenced this pull request Jan 26, 2026
Durations with units lower than months are no longer allowed. (The lower
units may be present but 0.) Adjust the existing PlainYearMonth addition
tests to test this behaviour and delete tests that are now irrelevant.

Normative change: tc39/proposal-temporal#3253
Approved in 2026-01 TC39 plenary.
Ms2ger pushed a commit to tc39/test262 that referenced this pull request Jan 26, 2026
Durations with units lower than months are no longer allowed. (The lower
units may be present but 0.) Adjust the existing PlainYearMonth addition
tests to test this behaviour and delete tests that are now irrelevant.

Normative change: tc39/proposal-temporal#3253
Approved in 2026-01 TC39 plenary.
@Manishearth
Copy link
Contributor

Anything stopping us landing this?

@Manishearth
Copy link
Contributor

Slash would it be bad if I implemented this in V8 now instead of waiting?

@Manishearth
Copy link
Contributor

Manishearth commented Jan 28, 2026

FWIW, the current placement of the check is quite awkward for V8 order-of-operations, because it's doing further validation of an input before other inputs are parsed.

boa-dev/temporal#671 is our temporal_rs implementation, https://chromium-review.googlesource.com/c/v8/v8/+/7528669 uplifts to V8, and https://chromium-review.googlesource.com/c/v8/v8/+/7527580 duplicates that check in V8 for order-of-operations reasons.

@ptomato
Copy link
Collaborator Author

ptomato commented Jan 28, 2026

Anything stopping us landing this?

Just waiting for #3256 and #3263, since it's convenient to pull in changes at the same time as pulling in the test262 commit that tests them. Those are landed as of today.
(That, and it needs a green checkmark — technically it hasn't been reviewed yet.)

FWIW, the current placement of the check is quite awkward for V8 order-of-operations, because it's doing further validation of an input before other inputs are parsed.

For future reference, it would have made things a lot easier to have this feedback before the plenary! But you're right, it doesn't fit with the precedent we set in #3130. I'm assuming it's OK to incorporate this implementation feedback before landing this PR.

This feature has been buggy for years and nobody noticed, so it must not
be used very often. This is an alternative solution to fix the bug in
issue #3197 and would supersede #3208 if accepted.

This changes PlainYearMonth.prototype.add/subtract to throw a RangeError
if the supplied duration has nonzero weeks, days, or time units. (Only
years and months are allowed.)

This does not change the behaviour of PlainDate.prototype.add/subtract,
because there are more use cases for adding e.g. { hours: 48 }, and days
are always 24 hours in PlainDate.

Closes: #3197
@ptomato ptomato force-pushed the disallow-adding-days-to-plainyearmonth branch from b8409e4 to faae30c Compare January 29, 2026 00:12
@ptomato
Copy link
Collaborator Author

ptomato commented Jan 29, 2026

Updated.

@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.94%. Comparing base (3ffa677) to head (faae30c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3253   +/-   ##
=======================================
  Coverage   97.94%   97.94%           
=======================================
  Files          22       22           
  Lines       10408    10408           
  Branches     1816     1816           
=======================================
  Hits        10194    10194           
  Misses        196      196           
  Partials       18       18           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ptomato added a commit to ptomato/test262 that referenced this pull request Jan 29, 2026
The recent normative change disallowing addition of weeks and lower
units (tc39/proposal-temporal#3253) should be
implemented such that the exception is thrown after all options are read
and cast.
@ptomato
Copy link
Collaborator Author

ptomato commented Jan 29, 2026

Additional test coverage for the order of operations in tc39/test262#4894

@Manishearth
Copy link
Contributor

For future reference, it would have made things a lot easier to have this feedback before the plenary!

I'm usually not implementing things until they land or there's relative certainty that they will land (for example, from the presence of test262 tests), so I wouldn't have really had an opportunity until now.

I could try and review future changes for this type of thing but I also just didn't expect changes like this at this stage.

Copy link
Contributor

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

Spec text looks good. Current implementation expectedly fails a bunch of test262 tests, but I haven't yet tried to update V8's test262 pin.

@Manishearth
Copy link
Contributor

test262 commit 1115529eaccb7411b11834efbd0551dbd04f42cd passes with https://chromium-review.googlesource.com/c/v8/v8/+/7528669 with the added SKIPs removed.

Ms2ger pushed a commit to tc39/test262 that referenced this pull request Jan 29, 2026
The recent normative change disallowing addition of weeks and lower
units (tc39/proposal-temporal#3253) should be
implemented such that the exception is thrown after all options are read
and cast.
@Ms2ger Ms2ger merged commit 31c031f into main Jan 29, 2026
10 checks passed
@Ms2ger Ms2ger deleted the disallow-adding-days-to-plainyearmonth branch January 29, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Surprising behavior with PlainYearMonth subtraction and constraining

5 participants