Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporal.Duration.prototype.round: Condition to convert zonedRelativeTo to plainRelativeTo incorrect #2680

Closed
anba opened this issue Sep 25, 2023 · 3 comments
Assignees

Comments

@anba
Copy link
Contributor

anba commented Sep 25, 2023

Step 29:

If zonedRelativeTo is not undefined; and smallestUnit is any of "year", "month", "week"; and any of duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]] ≠ 0; then

There are two issues:

  • The condition should be "or" instead of "and".
  • largestUnit needs to be tested, too.

This condition should instead be:

1. If zonedRelativeTo is not undefined, then
  1. If smallestUnit is any of "year", "month", "week"; or largestUnit is any of "year", "month", "week"; or any of duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]] ≠ 0; then
    1. Set plainRelativeTo to ? ToTemporalDate(zonedRelativeTo).
  • largestUnit is tested for BalanceDateDurationRelative.
  • smallestUnit is tested for RoundDuration.
  • The duration units are tested for UnbalanceDateDurationRelative.
@anba
Copy link
Contributor Author

anba commented Sep 25, 2023

Is the check for duration.[[Days]] ≠ 0 actually needed? Because days in UnbalanceDateDurationRelative can be any value (when years, months, and weeks are all zero).

@ptomato
Copy link
Collaborator

ptomato commented Sep 25, 2023

Agreed, thanks for catching this. Also agreed that the duration.[[Days]] check is not needed.

@ptomato ptomato self-assigned this Sep 25, 2023
@ptomato
Copy link
Collaborator

ptomato commented Sep 25, 2023

The and/or issue is already fixed in #2671. I'll push a fix for the largestUnit issue there, too. Note that the conditions change as a result of the commit "Normative: Precalculate PlainDateTime from ZonedDateTime in more places", so the duration.[[Days]] check will actually be needed.

ptomato added a commit that referenced this issue Sep 26, 2023
There are a few more places where we can avoid doing an additional lookup
and call of getOffsetNanosecondsFor on the same ZonedDateTime, to convert
it into a PlainDateTime.

This affects

- Temporal.Duration.prototype.add (with relativeTo ZonedDateTime)
- Temporal.Duration.prototype.subtract (ditto)
- Temporal.Duration.prototype.round (ditto)
- Temporal.Duration.prototype.total (ditto)
- Temporal.ZonedDateTime.prototype.since
- Temporal.ZonedDateTime.prototype.until

(also fixes "and" vs "or" prose mistakes)
Closes: #2680
Closes: #2681
ptomato added a commit that referenced this issue Sep 26, 2023
There are a few more places where we can avoid doing an additional lookup
and call of getOffsetNanosecondsFor on the same ZonedDateTime, to convert
it into a PlainDateTime.

This affects

- Temporal.Duration.prototype.add (with relativeTo ZonedDateTime)
- Temporal.Duration.prototype.subtract (ditto)
- Temporal.Duration.prototype.round (ditto)
- Temporal.Duration.prototype.total (ditto)
- Temporal.ZonedDateTime.prototype.since
- Temporal.ZonedDateTime.prototype.until

(also fixes "and" vs "or" prose mistakes)
Closes: #2680
Closes: #2681
ptomato added a commit that referenced this issue Sep 27, 2023
There are a few more places where we can avoid doing an additional lookup
and call of getOffsetNanosecondsFor on the same ZonedDateTime, to convert
it into a PlainDateTime.

This affects

- Temporal.Duration.prototype.add (with relativeTo ZonedDateTime)
- Temporal.Duration.prototype.subtract (ditto)
- Temporal.Duration.prototype.round (ditto)
- Temporal.Duration.prototype.total (ditto)
- Temporal.ZonedDateTime.prototype.since
- Temporal.ZonedDateTime.prototype.until

(also fixes "and" vs "or" prose mistakes)
Closes: #2680
Closes: #2681
ptomato added a commit that referenced this issue Oct 4, 2023
There are a few more places where we can avoid doing an additional lookup
and call of getOffsetNanosecondsFor on the same ZonedDateTime, to convert
it into a PlainDateTime.

This affects

- Temporal.Duration.prototype.add (with relativeTo ZonedDateTime)
- Temporal.Duration.prototype.subtract (ditto)
- Temporal.Duration.prototype.round (ditto)
- Temporal.Duration.prototype.total (ditto)
- Temporal.ZonedDateTime.prototype.since
- Temporal.ZonedDateTime.prototype.until

(also fixes "and" vs "or" prose mistakes)
Closes: #2680
Closes: #2681
@ptomato ptomato closed this as completed in 6eec81d Oct 4, 2023
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

No branches or pull requests

2 participants