Skip to content

Commit

Permalink
Merge pull request #170 from gwbres/hash
Browse files Browse the repository at this point in the history
epoch: derive Hash
  • Loading branch information
ChristopherRabotin authored Nov 6, 2022
2 parents 0b25940 + 0a1b05d commit ed2090d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern crate core;
use core::cmp::Ordering;
use core::convert::TryInto;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};

#[cfg(feature = "std")]
Expand Down Expand Up @@ -82,6 +83,13 @@ impl PartialEq for Duration {
}
}

impl Hash for Duration {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.centuries.hash(hasher);
self.nanoseconds.hash(hasher);
}
}

impl Default for Duration {
fn default() -> Self {
Duration::ZERO
Expand Down
7 changes: 7 additions & 0 deletions src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
};
use core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
use core::fmt;
use core::hash::{Hash, Hasher};
use core::ops::{Add, AddAssign, Sub, SubAssign};

use crate::ParsingErrors;
Expand Down Expand Up @@ -250,6 +251,12 @@ impl PartialEq for Epoch {
}
}

impl Hash for Epoch {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.duration_since_j1900_tai.hash(hasher);
}
}

impl PartialOrd for Epoch {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(
Expand Down
2 changes: 1 addition & 1 deletion src/timescale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub const UNIX_REF_EPOCH: Epoch = Epoch::from_tai_duration(Duration {
});

/// Enum of the different time systems available
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TimeScale {
Expand Down

0 comments on commit ed2090d

Please sign in to comment.