From f8566e845f0557c8731131eef283a8e5c8aafb08 Mon Sep 17 00:00:00 2001 From: mrw1593 Date: Mon, 7 Mar 2022 10:49:16 -0500 Subject: Fixed some pedantic clippy warnings --- src/timestamp.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/timestamp.rs') diff --git a/src/timestamp.rs b/src/timestamp.rs index 6798792..ea8f2e1 100644 --- a/src/timestamp.rs +++ b/src/timestamp.rs @@ -7,6 +7,7 @@ pub struct UnixTimestamp { } impl UnixTimestamp { + #[must_use] pub const fn new(seconds: i64, nanoseconds: u32) -> Self { Self { seconds, @@ -14,14 +15,17 @@ impl UnixTimestamp { } } + #[must_use] pub const fn seconds_since_unix_epoch(self) -> i64 { self.seconds } + #[must_use] pub const fn nanosecond(self) -> u32 { self.nanoseconds } + #[must_use] pub const fn add_seconds_overflowing(self, seconds: i64) -> (Self, bool) { // TODO overflowing goes first let (seconds, overflowing) = self.seconds.overflowing_add(seconds as i64); @@ -30,6 +34,7 @@ impl UnixTimestamp { (timestamp, overflowing) } + #[must_use] pub const fn add_nanoseconds_overflowing(self, nanoseconds: i64) -> (Self, bool) { let total_nanos = (self.nanoseconds as i64 + nanoseconds) % 1_000_000_000; let total_nanos = total_nanos + (1_000_000_000 * total_nanos.is_negative() as i64); @@ -45,10 +50,10 @@ impl UnixTimestamp { impl From for UnixTimestamp { fn from(ndt: NaiveDateTime) -> Self { - const UNIX_EPOCH_DAYS: isize = Date::UNIX_EPOCH.days_after_common_era(); + const UNIX_EPOCH_DAYS: i64 = Date::UNIX_EPOCH.days_after_common_era(); // TODO don't require the .date() let days = (ndt.date().days_after_common_era() - UNIX_EPOCH_DAYS) as i64; - let seconds = days * 86_400 + ndt.time().seconds_from_midnight() as i64; + let seconds = days * 86_400 + i64::from(ndt.time().seconds_from_midnight()); let nanoseconds = ndt.nanosecond(); Self::new(seconds, nanoseconds) -- cgit v1.2.3