Skip to content

Commit

Permalink
Likely bug to be fixed
Browse files Browse the repository at this point in the history
I think there is a bug in the Gregorian initialization because it does account for the hour in the reference epoch.

The gregorian initialization and formatter should account for the reference epoch of the time scale.
  • Loading branch information
ChristopherRabotin committed Jun 17, 2023
1 parent 53d6ca5 commit 5899c93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/timescale/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ impl TimeScale {
_ => 1900,
}
}

pub(crate) const fn ref_hour(&self) -> i64 {
match self {
TimeScale::ET | TimeScale::TDB => 0,
_ => 12,
}
}
}

#[cfg_attr(feature = "python", pymethods)]
Expand Down
12 changes: 7 additions & 5 deletions tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,11 +900,13 @@ fn test_from_str() {
}

#[test]
fn test_from_str_tdb() {
use core::str::FromStr;

let greg = "2020-01-31T00:00:00 TDB";
assert_eq!(greg, format!("{:e}", Epoch::from_str(greg).unwrap()));
fn test_ref_epoch_delta() {
let e_tai = Epoch::from_gregorian_at_noon(2022, 9, 6, TimeScale::TAI);
let e_tdb = Epoch::from_gregorian_at_noon(2022, 9, 6, TimeScale::TDB);
// Since we store the durations with respect to their time scale reference epochs,
// the difference between the same epoch but in different time scales should be
// exactly the difference between the reference epochs.
assert_eq!(e_tai.duration - e_tdb.duration, J2000_TO_J1900_DURATION);
}

#[test]
Expand Down

0 comments on commit 5899c93

Please sign in to comment.