Skip to content

Commit

Permalink
Merge pull request #133 from mkolopanis/epoch_derive_ord
Browse files Browse the repository at this point in the history
derive Ord and Eq for Epoch
  • Loading branch information
ChristopherRabotin authored Aug 2, 2022
2 parents bec98a0 + 59cb437 commit 07168d9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const USUAL_DAYS_PER_MONTH: [u8; 12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
/// Defines an Epoch in TAI (temps atomique international) in seconds past 1900 January 01 at midnight (like the Network Time Protocol).
///
/// Refer to the appropriate functions for initializing this Epoch from different time systems or representations.
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Epoch(Duration);

impl Sub for Epoch {
Expand Down Expand Up @@ -2198,4 +2198,16 @@ mod tests {
Epoch::from_gregorian_tai_hms(2022, 5, 20, 18, 0, 0)
);
}

#[test]
fn test_ord() {
let epoch1 =
Epoch::maybe_from_gregorian(2020, 1, 8, 16, 1, 17, 100, TimeSystem::TAI).unwrap();
let epoch2 =
Epoch::maybe_from_gregorian(2020, 1, 8, 16, 1, 17, 200, TimeSystem::TAI).unwrap();

assert_eq!(epoch1.max(epoch2), epoch2);
assert_eq!(epoch2.min(epoch1), epoch1);
assert_eq!(epoch1.cmp(&epoch1), core::cmp::Ordering::Equal);
}
}

0 comments on commit 07168d9

Please sign in to comment.