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

Fix panics when no relative_to is supplied to round #40

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/components/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,13 @@ impl Duration {
};
// 35. Let calendarRec be ? CreateCalendarMethodsRecordFromRelativeTo(plainRelativeTo, zonedRelativeTo, « DATE-ADD, DATE-UNTIL »).

// TODO: Validate below expect -> Potentially return error.
let relative_to_date = relative_to.date.expect("Date must exist at this point.");
// TODO: relativeTo will need to be removed soon.
let relative_to_date = relative_to.date;

// 36. Let unbalanceResult be ? UnbalanceDateDurationRelative(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], largestUnit, plainRelativeTo, calendarRec).
let unbalanced =
self.date()
.unbalance_relative(largest_unit, Some(relative_to_date), context)?;
let unbalanced = self
.date()
.unbalance_relative(largest_unit, relative_to_date, context)?;

// NOTE: Step 37 handled in round duration
// 37. Let norm be NormalizeTimeDuration(duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]],
Expand Down Expand Up @@ -621,7 +621,7 @@ impl Duration {
let result = intermediate.balance_relative(
largest_unit,
smallest_unit,
Some(relative_to_date),
relative_to_date,
context,
)?;

Expand Down