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

Remove plainDateTimeOrRelativeToWillBeUsed #2836

Open
ptomato opened this issue May 10, 2024 · 0 comments
Open

Remove plainDateTimeOrRelativeToWillBeUsed #2836

ptomato opened this issue May 10, 2024 · 0 comments

Comments

@ptomato
Copy link
Collaborator

ptomato commented May 10, 2024

From #2758 reviews. This can likely be drastically simplified after #2826 lands and can maybe even be done as part of that issue.

This plainDateTimeOrRelativeToWillBeUsed is a little hard to reason about. Here's how you can make it clearer. Feel free to queue this up as an Editorial task for later if the goal here is keep the diff as small as possible.

You can determine whether nanosecond-rounding is possible at the beginning of the function and it makes things clearer. Pseudocode:

const needRelativeRounding =
  zonedRelativeTo || // if zoned date time
  // OR, if plain date and there's a unit >DAY
  ES.IsCalendarUnit(largestUnit) ||
  calendarUnitsPresent

if (!needRelativeRounding) {
  // do nanosecond-based rounding (BalanceTimeDuration)
  // return the result here, short circuiting
}

if (!zonedRelativeTo || !plainRelativeTo) {
  throw new RangeError('need a relativeTo')
}

const calendarRec = CalendarMethodRecord.CreateFromRelativeTo(plainRelativeTo, zonedRelativeTo, [
  'dateAdd',
  'dateUntil'
]);

if (zonedRelativeTo) {
  const precalculatedPlainDateTime = // ...
  // proceed with DifferenceZonedDateTimeWithRounding...
} else if (plainRelativeTo) {
  // proceed with DifferencePlainDateTimeWithRounding...
}

Originally posted by @arshaw in #2758 (comment)

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

1 participant