Skip to content

Commit

Permalink
comply with standard by falling back to ShowAll
Browse files Browse the repository at this point in the history
see GetNumberOption documentation
  • Loading branch information
kartva committed Aug 21, 2024
1 parent 85eac90 commit d7c1a00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/experimental/src/duration/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum FractionalDigits {
#[default]
ShowAll,
/// Use the given number of fractional digits.
/// This value is clamped to the range 0..=9.
/// Default [`FractionalDigits::ShowAll`] behavior is used if this value is out of the range 0..=9.
/// Fractional digits are rounded to zero if necessary.
Fixed(u8),
}
Expand Down
6 changes: 4 additions & 2 deletions components/experimental/src/duration/validated_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ impl ValidatedDurationFormatterOptions {
// section 1.2.1
// 27. Set durationFormat.[[FractionalDigits]] to ? GetNumberOption(options, "fractionalDigits", 0, 9, undefined).
if let FractionalDigits::Fixed(i) = builder.fractional_digits {
builder.fractional_digits = FractionalDigits::Fixed(i.clamp(0, 9));
if i > 9 {
builder.fractional_digits = FractionalDigits::ShowAll;
}
}

Ok(builder.try_into().unwrap())
Expand Down Expand Up @@ -436,6 +438,6 @@ mod tests {

let validated = ValidatedDurationFormatterOptions::validate(options).unwrap();

assert_eq!(validated.fractional_digits, FractionalDigits::Fixed(9));
assert_eq!(validated.fractional_digits, FractionalDigits::ShowAll);
}
}

0 comments on commit d7c1a00

Please sign in to comment.