summaryrefslogtreecommitdiff
path: root/src/time.rs
diff options
context:
space:
mode:
authormrw1593 <botahamec@outlook.com>2022-03-07 09:56:46 -0500
committermrw1593 <botahamec@outlook.com>2022-03-07 09:56:46 -0500
commit43da205d0c486a082c380a1258229a055e5767ba (patch)
tree2852943fb41316a47e9aa80c49a5282800c15574 /src/time.rs
parent0fb870509821eb6f8158a9ee3cc02e6a0f951c86 (diff)
Implemented proper second addition
Diffstat (limited to 'src/time.rs')
-rw-r--r--src/time.rs17
1 files changed, 17 insertions, 0 deletions
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 {