diff options
Diffstat (limited to 'apps/cassiopeia/src/time.rs')
-rw-r--r-- | apps/cassiopeia/src/time.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/apps/cassiopeia/src/time.rs b/apps/cassiopeia/src/time.rs index 4ac4ce7db900..0161742a0c92 100644 --- a/apps/cassiopeia/src/time.rs +++ b/apps/cassiopeia/src/time.rs @@ -27,12 +27,23 @@ impl<'t> Sub for &'t Time { } } +impl ToString for Time { + fn to_string(&self) -> String { + format!("{}", self.inner.format("%Y-%m-%d %H:%M:%S%:z")) + } +} + impl Time { /// Get the current local time and pin it to a fixed Tz offset pub fn now() -> Self { let now = Local::now(); Self { - inner: build_datetime(now.time()), + inner: build_datetime( + now.time() + .with_second(0) + .and_then(|t| t.with_nanosecond(0)) + .unwrap(), + ), } } @@ -44,7 +55,7 @@ impl Time { pub fn after(&self, date: &Date) -> bool { &Date::from(self.date()) > date } - + #[cfg(test)] pub(crate) fn fixed(hour: u32, min: u32, sec: u32) -> Self { Self { @@ -59,10 +70,9 @@ impl Time { /// rounding values that were created in a different timezone. pub fn round(&self) -> Self { let naive = self.inner.time(); - let (new_min, incr_hour) = match naive.minute() { // 0-7 => (0, false) - m if m > 0 && m < 7 => (0, false), + m if m >= 0 && m < 7 => (0, false), // 7-22 => (15, false) m if m >= 7 && m < 22 => (15, false), // 22-37 => (30, false) |