Skip to content

Commit

Permalink
fix: make negative_duration Negative
Browse files Browse the repository at this point in the history
  • Loading branch information
kartva committed Aug 22, 2024
1 parent 7bafabe commit 0ac516f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/experimental/src/duration/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Duration {
/// Whether the duration is positive.
/// Use [`Duration::get_sign`] to find the zero-aware sign.
pub sign: DurationSign,
/// The number of years in the duration.
pub years: u64,
Expand Down
6 changes: 3 additions & 3 deletions components/experimental/src/duration/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use super::{options::*, Duration, DurationFormatter, DurationSign};
use super::{options::*, Duration, DurationFormatter};

use super::validated_options::Unit;
use core::fmt;
Expand Down Expand Up @@ -528,7 +528,7 @@ impl<'a> FormattedDuration<'a> {
// a. Set signDisplayed to false.
sign_displayed = false;
// b. If value is 0 and DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]) is -1, then
if value == 0 && self.duration.sign == DurationSign::Negative {
if value == 0 && self.duration.get_sign() == fixed_decimal::Sign::Negative {
// i. Set value to negative-zero.
formatted_value.apply_sign_display(SignDisplay::Always);
}
Expand Down Expand Up @@ -731,7 +731,7 @@ mod tests {
};

let negative_duration = Duration {
sign: DurationSign::Positive,
sign: DurationSign::Negative,
..Default::default()
};

Expand Down

0 comments on commit 0ac516f

Please sign in to comment.