From 27d8e414399586f3b0dee8590f0fcb923d519c07 Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Wed, 16 Nov 2022 09:50:57 +0100 Subject: [PATCH] epoch, timescale: implement default trait --- src/epoch.rs | 2 +- src/timescale.rs | 12 ++++++++++++ tests/timescale.rs | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/epoch.rs b/src/epoch.rs index 1fd11108..b5c74aeb 100644 --- a/src/epoch.rs +++ b/src/epoch.rs @@ -156,7 +156,7 @@ const CUMULATIVE_DAYS_FOR_MONTH: [u16; 12] = { /// Defines a nanosecond-precision Epoch. /// /// Refer to the appropriate functions for initializing this Epoch from different time systems or representations. -#[derive(Copy, Clone, Eq)] +#[derive(Copy, Clone, Eq, Default)] #[repr(C)] #[cfg_attr(feature = "python", pyclass)] pub struct Epoch { diff --git a/src/timescale.rs b/src/timescale.rs index f38ff233..7b07ce24 100644 --- a/src/timescale.rs +++ b/src/timescale.rs @@ -74,6 +74,18 @@ pub enum TimeScale { BDT, } +impl Default for TimeScale { + /// Builds default TAI time scale + fn default() -> Self { + /* + * We use TAI as default Time scale, + * because `Epoch` is always defined with respect to TAI. + * Also, a default `Epoch` is then a null duration into TAI. + */ + Self::TAI + } +} + impl TimeScale { pub(crate) const fn formatted_len(&self) -> usize { match &self { diff --git a/tests/timescale.rs b/tests/timescale.rs index 7004718d..3f4edb9b 100644 --- a/tests/timescale.rs +++ b/tests/timescale.rs @@ -54,3 +54,8 @@ fn test_is_gnss() { let ts = TimeScale::TAI; assert!(!ts.is_gnss()); } + +#[test] +fn test_default() { + assert_eq!(TimeScale::default(), TimeScale::TAI); +}