Skip to content

Add validation logic to from_diff_settings #144

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

Merged
merged 4 commits into from
Dec 26, 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
16 changes: 15 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ impl ResolvedRoundingOptions {
.largest_unit
.unwrap_or(smallest_unit.max(fallback_largest));

// 11. If LargerOfTwoTemporalUnits(largestUnit, smallestUnit) is not largestUnit, throw a RangeError exception.
// 12. Let maximum be MaximumTemporalDurationRoundingIncrement(smallestUnit).
// 13. If maximum is not unset, perform ? ValidateTemporalRoundingIncrement(roundingIncrement, maximum, false).
if largest_unit < smallest_unit {
return Err(TemporalError::range().with_message(
"largestUnit when rounding Duration was not the largest provided unit",
));
}

let maximum = smallest_unit.to_maximum_rounding_increment();
if let Some(max) = maximum {
increment.validate(max.into(), false)?;
}

let resolved = ResolvedRoundingOptions {
largest_unit,
smallest_unit,
Expand Down Expand Up @@ -142,7 +156,7 @@ impl ResolvedRoundingOptions {
Some(unit) => unit,
};

if largest_unit.max(smallest_unit) != largest_unit {
if largest_unit < smallest_unit {
return Err(TemporalError::range().with_message(
"largestUnit when rounding Duration was not the largest provided unit",
));
Expand Down
Loading