Skip to content

Commit

Permalink
DurationFormatter: validated_options: add documentation to DurationFo…
Browse files Browse the repository at this point in the history
…rmatterOptionsError (#5210)
  • Loading branch information
kartva authored Jul 18, 2024
1 parent 14e86d3 commit e308753
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,19 @@ pub struct ValidatedDurationFormatterOptions {
fractional_digits: FractionalDigits,
}

/// Error type for [DurationFormatterOptions] validation.
/// Error type for [`DurationFormatterOptions`] validation.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DurationFormatterOptionsError {
InvalidFractionalDigits,
/// Returned when a unit field is set to [`FieldDisplay::Always`] and the style is set to [`FieldStyle::Fractional`].
DisplayAlwaysFractional,

/// Returned when a previous unit's style is [`FieldStyle::Fractional`], but the following unit's style is not [`FieldStyle::Fractional`].
PreviousFractional,

/// Returned when a previous unit's style is set to [`FieldStyle::Numeric`] or [`FieldStyle::TwoDigit`] and the following unit's style is not
/// [`FieldStyle::Fractional`], [`FieldStyle::Numeric`], or [`FieldStyle::TwoDigit`].
PreviousNumeric,
}

impl ValidatedDurationFormatterOptions {
Expand Down Expand Up @@ -139,15 +148,15 @@ impl ValidatedDurationFormatterOptions {
// 7. If display is "always" and style is "fractional", then
if *visibility == Some(FieldDisplay::Always) && *style == Some(FieldStyle::Fractional) {
// a. Throw a RangeError exception.
return Err(DurationFormatterOptionsError::InvalidFractionalDigits);
return Err(DurationFormatterOptionsError::DisplayAlwaysFractional);
}

// 8. If prevStyle is "fractional", then
if prev_style == Some(FieldStyle::Fractional) {
// a. If style is not "fractional", then
if *style != Some(FieldStyle::Fractional) {
// i. Throw a RangeError exception.
return Err(DurationFormatterOptionsError::InvalidFractionalDigits);
return Err(DurationFormatterOptionsError::PreviousFractional);
}
}

Expand All @@ -159,7 +168,7 @@ impl ValidatedDurationFormatterOptions {
Some(FieldStyle::Fractional | FieldStyle::Numeric | FieldStyle::TwoDigit)
) {
// i. Throw a RangeError exception.
return Err(DurationFormatterOptionsError::InvalidFractionalDigits);
return Err(DurationFormatterOptionsError::PreviousNumeric);
}
// b. If unit is "minutes" or "seconds", then
if unit == Unit::Minute || unit == Unit::Second {
Expand Down

0 comments on commit e308753

Please sign in to comment.