mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
Update timespan.rs
This commit is contained in:
parent
7e110542d6
commit
900429b3d1
1 changed files with 12 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue