From ac2936460f44d9e2567115b958735d0ea7a680d1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Feb 2023 18:47:46 +0100 Subject: [PATCH] minor fix for UnixTimestamp --- CHANGELOG.md | 5 +++++ src/time/mod.rs | 10 ++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2fdef1..c4bcc71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added missing Service IDs to `ecss.PusServiceId` and marked in `#[non_exhaustive]`. +## Fixed + +- `time.UnixTimestamp`: All constructors and `From` conversions now use the `new` constructor, + which should cause a correct conversion of 0 subsecond milliseconds to a `None` value. + # [v0.5.2] 2023-01-26 ## Added diff --git a/src/time/mod.rs b/src/time/mod.rs index 90f23ac..419d601 100644 --- a/src/time/mod.rs +++ b/src/time/mod.rs @@ -285,10 +285,7 @@ impl UnixTimestamp { pub fn from_now() -> Result { let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; let epoch = now.as_secs(); - Ok(UnixTimestamp { - unix_seconds: epoch as i64, - subsecond_millis: Some(now.subsec_millis() as u16), - }) + Ok(Self::const_new(epoch as i64, now.subsec_millis() as u16)) } #[inline] @@ -310,10 +307,7 @@ impl UnixTimestamp { impl From> for UnixTimestamp { fn from(value: DateTime) -> Self { - Self { - unix_seconds: value.timestamp(), - subsecond_millis: Some(value.timestamp_subsec_millis() as u16), - } + Self::const_new(value.timestamp(), value.timestamp_subsec_millis() as u16) } }