#[allow(clippy::exhaustive_structs)] #[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Duration {
pub sign: DurationSign,
pub years: u64,
pub months: u64,
pub weeks: u64,
pub days: u64,
pub hours: u64,
pub minutes: u64,
pub seconds: u64,
pub milliseconds: u64,
pub microseconds: u64,
pub nanoseconds: u64,
}
impl Duration {
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,
]
}
pub(crate) fn get_sign(&self) -> fixed_decimal::Sign {
for &unit in self.iter_units().iter() {
if unit != 0 {
return match self.sign {
DurationSign::Positive => fixed_decimal::Sign::None,
DurationSign::Negative => fixed_decimal::Sign::Negative,
};
}
}
fixed_decimal::Sign::None
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[allow(clippy::exhaustive_enums)] pub enum DurationSign {
#[default]
Positive,
Negative,
}
impl Duration {
pub fn new() -> Self {
Self::default()
}
}