Skip to content

Commit

Permalink
Merge pull request #176 from gwbres/timescale-default
Browse files Browse the repository at this point in the history
epoch, timescale: implement default trait
  • Loading branch information
ChristopherRabotin authored Nov 17, 2022
2 parents 7d6708c + 27d8e41 commit 2fdd90a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down
12 changes: 12 additions & 0 deletions src/timescale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions tests/timescale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 2fdd90a

Please sign in to comment.