diff --git a/CHANGELOG.md b/CHANGELOG.md index 968fb6c..f02d741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - CDS timestamp: Added constructor function to create the time provider from `chrono::DateTime` and a generic UNIX timestamp (`i64` seconds and subsecond milliseconds). +- New `UnixTimeStamp` abstraction which contains the unix seconds as an `i64` + and an optional subsecond millisecond counter (`u16`) +- `MAX_DAYS_24_BITS` which contains maximum value which can be supplied + to the days field of a CDS time provider with 24 bits days field width. + +## Changed + +- `CcsdsTimeProvider` trait (breaking): + - Add new `unix_stamp` method returning the new `UnixTimeStamp` struct + - Add new `subsecond_millis` method returning counter `Option` + - Default impl for `unix_stamp` which re-uses `subsecond_millis` and + existing `unix_seconds` method +- `TimestampError` (breaking): Add `DateBeforeCcsdsEpoch` error type + because new CDS API allow supplying invalid date times before CCSDS epoch. + Make `TimestampError` with `#[non_exhaustive]` attribute to prevent + future breakages if new error variants are added # [v0.4.2] 14.01.2023 diff --git a/src/time/cds.rs b/src/time/cds.rs index 8e9bdad..1433da2 100644 --- a/src/time/cds.rs +++ b/src/time/cds.rs @@ -167,7 +167,7 @@ pub struct TimeProvider { submillis_precision: Option, /// This is not strictly necessary but still cached because it significantly simplifies the /// calculation of [`DateTime`]. - unix_stamp: UnixTimeStamp, + unix_stamp: UnixTimestamp, } /// Common properties for all CDS time providers. @@ -1096,7 +1096,7 @@ impl CcsdsTimeProvider for TimeProvider UnixTimeStamp { + fn unix_stamp(&self) -> UnixTimestamp { self.unix_stamp } diff --git a/src/time/cuc.rs b/src/time/cuc.rs index dd5c1bf..21b24a7 100644 --- a/src/time/cuc.rs +++ b/src/time/cuc.rs @@ -565,15 +565,6 @@ impl CcsdsTimeProvider for TimeProviderCcsdsEpoch { None } - /// Please note that this function only works as intended if the time counter resolution - /// is one second. - fn unix_stamp(&self) -> UnixTimeStamp { - UnixTimeStamp { - unix_seconds: self.unix_seconds(), - subsecond_millis: None, - } - } - fn date_time(&self) -> Option> { let unix_seconds = self.unix_seconds(); let ns = if let Some(fractional_part) = self.fractions { diff --git a/src/time/mod.rs b/src/time/mod.rs index 34fa08f..9af0cf5 100644 --- a/src/time/mod.rs +++ b/src/time/mod.rs @@ -56,6 +56,7 @@ pub fn ccsds_time_code_from_p_field(pfield: u8) -> Result { #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[non_exhaustive] pub enum TimestampError { /// Contains tuple where first value is the expected time code and the second /// value is the found raw value @@ -219,8 +220,8 @@ pub trait CcsdsTimeProvider { fn unix_seconds(&self) -> i64; fn subsecond_millis(&self) -> Option; - fn unix_stamp(&self) -> UnixTimeStamp { - UnixTimeStamp { + fn unix_stamp(&self) -> UnixTimestamp { + UnixTimestamp { unix_seconds: self.unix_seconds(), subsecond_millis: self.subsecond_millis(), } @@ -234,12 +235,12 @@ pub trait CcsdsTimeProvider { /// Also can optionally include subsecond millisecond for greater accuracy. #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct UnixTimeStamp { +pub struct UnixTimestamp { pub unix_seconds: i64, subsecond_millis: Option, } -impl UnixTimeStamp { +impl UnixTimestamp { pub fn new(unix_seconds: i64) -> Self { Self { unix_seconds, @@ -267,7 +268,7 @@ impl UnixTimeStamp { pub fn from_now() -> Result { let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; let epoch = now.as_secs(); - Ok(UnixTimeStamp { + Ok(UnixTimestamp { unix_seconds: epoch as i64, subsecond_millis: Some(now.subsec_millis() as u16), }) @@ -314,17 +315,17 @@ mod tests { #[test] fn basic_unix_stamp_test() { - let stamp = UnixTimeStamp::new(-200); + let stamp = UnixTimestamp::new(-200); assert_eq!(stamp.unix_seconds, -200); assert!(stamp.subsecond_millis().is_none()); - let stamp = UnixTimeStamp::new(250); + let stamp = UnixTimestamp::new(250); assert_eq!(stamp.unix_seconds, 250); assert!(stamp.subsecond_millis().is_none()); } #[test] fn basic_float_unix_stamp_test() { - let stamp = UnixTimeStamp::new_with_subsecond_millis(500, 600).unwrap(); + let stamp = UnixTimestamp::new_with_subsecond_millis(500, 600).unwrap(); assert!(stamp.subsecond_millis.is_some()); assert_eq!(stamp.unix_seconds, 500); let subsec_millis = stamp.subsecond_millis().unwrap();