From 43da205d0c486a082c380a1258229a055e5767ba Mon Sep 17 00:00:00 2001 From: mrw1593 Date: Mon, 7 Mar 2022 09:56:46 -0500 Subject: Implemented proper second addition --- src/time.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/time.rs') diff --git a/src/time.rs b/src/time.rs index 49dba51..0f6091e 100644 --- a/src/time.rs +++ b/src/time.rs @@ -352,6 +352,23 @@ impl Time { self.add_nanoseconds_checked(nanoseconds) .unwrap_or_else(|| panic!("Overflow when adding {nanoseconds} nanoseconds to {self}")) } + + /// Gets the number of seconds since midnight + #[must_use] + pub fn seconds_from_midnight(self) -> u32 { + self.hour as u32 * 3_600_000_000 + + self.minute as u32 * 60_000_000 + + self.second as u32 * 1_000_000 + } + + /// Gets the number of nanoseconds since midnight + #[must_use] + pub fn nanoseconds_from_midnight(self) -> u64 { + self.hour as u64 * 3_600_000_000_000 + + self.minute as u64 * 60_000_000_000 + + self.second as u64 * 1_000_000_000 + + self.nanosecond as u64 + } } impl PartialOrd for Time { -- cgit v1.2.3