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

DurationFormatter: Duration Formatter Digital Implementation #5263

Merged
merged 9 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions components/experimental/src/duration/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ pub struct Duration {
pub nanoseconds: u64,
}

impl Duration {
/// Iterate over the units of the duration in descending order.
pub(crate) fn iter_units(&self) -> [u64; 10] {
[
self.years,
self.months,
self.weeks,
self.days,
self.hours,
self.minutes,
self.seconds,
self.milliseconds,
self.microseconds,
self.nanoseconds,
]
}
}

/// Describes whether a [`Duration`] is positive or negative.
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum DurationSign {
Expand All @@ -54,6 +72,15 @@ pub enum DurationSign {
Negative,
}

impl DurationSign {
pub(crate) fn as_fixed_decimal_sign(&self) -> fixed_decimal::Sign {
match self {
DurationSign::Positive => fixed_decimal::Sign::Positive,
DurationSign::Negative => fixed_decimal::Sign::Negative,
}
}
}

Comment on lines +75 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a following PR:

Suggested change
impl DurationSign {
pub(crate) fn as_fixed_decimal_sign(&self) -> fixed_decimal::Sign {
match self {
DurationSign::Positive => fixed_decimal::Sign::Positive,
DurationSign::Negative => fixed_decimal::Sign::Negative,
}
}
}
impl As<fixed_decimal::Sign> for DurationSign {
fn as(&self) -> Sign {
match self {
DurationSign::Positive => fixed_decimal::Sign::Positive,
DurationSign::Negative => fixed_decimal::Sign::Negative,
}
}
}

impl Duration {
/// Create a new positive [`Duration`] with all fields set to 0.
pub fn new() -> Self {
Expand Down
Loading