Update timespan.rs

This commit is contained in:
user1823 2025-08-04 15:45:29 +05:30 committed by GitHub
parent 7e110542d6
commit 900429b3d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -111,6 +111,18 @@ impl Timespan {
}
}
/// Returns the value in the given unit
pub fn as_provided_unit(&self, unit: TimespanUnit) -> f32 {
match unit {
TimespanUnit::Seconds => self.seconds,
TimespanUnit::Minutes => self.seconds / MINUTE,
TimespanUnit::Hours => self.seconds / HOUR,
TimespanUnit::Days => self.seconds / DAY,
TimespanUnit::Months => self.seconds / MONTH,
TimespanUnit::Years => self.seconds / YEAR,
}
}
/// Round seconds and days to integers, otherwise
/// truncates to one decimal place.
pub fn as_rounded_unit(self) -> f32 {