how to make sense of epochs? #281
-
I was reviewing some of the code for this library to better understand some of the differences (in detail) between it and OK, so I'm looking at this code: Lines 60 to 64 in 822c0a0 And this code: Lines 63 to 67 in 822c0a0 To check my understanding, I wanted to try and write a datetime calculation that arrived at these numbers. So I wrote this program. First, [package]
publish = false
name = "datetime"
version = "0.1.0"
edition = "2021"
[dependencies]
hifitime = "3.9.0"
[[bin]]
name = "datetime"
path = "main.rs" And fn main() {
let t1 = hifitime::Epoch::from_gregorian_utc(1900, 1, 1, 12, 0, 0, 0);
let d = hifitime::Duration::from_parts(0, 2_208_988_800_000_000_000);
println!("unix: {t1:?} + {d:?} = {:?}", t1 + d);
let t1 = hifitime::Epoch::from_gregorian_utc(1900, 1, 1, 12, 0, 0, 0);
let d = hifitime::Duration::from_parts(0, 3_155_716_800_000_000_000);
println!("J2000: {t1:?} + {d:?} = {:?}", t1 + d);
} The first block is meant to create a datetime corresponding to the J1900 epoch, add the number of seconds used above to get to the Unix epoch and see what comes out. I then did the same thing in the second block, but for getting from the J1900 epoch to J2000. The output of this program is:
My understanding here is that the output should have been this:
That is, the J2000 epoch should be 24 hours earlier and the Unix epoch should be 12 hours earlier. I did a little digging, and it seems like the J2000 epoch is actually
Which means the actual output is 12 hours ahead of both epochs (instead of being 12 hours ahead of one and 24 hours ahead of the other). What am I missing? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Thanks for looking into hifitime. I'm currently traveling without access to a laptop, but I'll get back to you when I return. The examples you show make me question whether something is wrong, so I want to run other tests to double check. In general, Hifitime epochs are currently converted to TAI from any time system that they were initialized in. However, the duration operations will operate on the original time scale. For example, if an epoch was initialized in UTC near the boundary with a leap second, and ten seconds are added to that epoch, then a full ten seconds in UTC are added (ie the leap second is "uncounted"). The next version of hifitime is expected to change this behavior (although it shouldn't lead to any changes to the results of the external api). @gwbres put a lot of really good work into making the time scale change lazy. In that testing, we got all of the tests to pass apart from the TDB time scale initialization which was exactly twelve hours off, similar to what you've seen. That said, the test suite is exhaustive and I suspect that if there is an error, it ends up being masked away by another shift of twelve hours. |
Beta Was this translation helpful? Give feedback.
-
You're correct that there is an issue with this constant: #282. It's used in the conversion to/from astrodynamical time systems (specifically ET and TDB), and in practice, it hides the fact that there's a twelve hour error in the definition of the J1900 reference time. As you have noted, hifitime keeps track of epochs as an offset from the reference of the given time scale. This offset is then used to convert to/from the Gregorian representation of time on demand. (I would argue that is the only correct way to define time physically speaking.) This bug is likely related to #261 as well. This shows that I need to pick up work on hifitime, ha! A quick question for you, as a highly prolific contributor to the Rust ecosystem: in fixing this bug, I'll necessarily introduce breaking changes to those who expect the buggy behavior. Therefore, should this lead to a new major version? Thanks P.S.: I'm keeping this discussion open until I resolve the ticket. |
Beta Was this translation helpful? Give feedback.
-
Just a quick update on this discussion from a renewed understanding from working the bug fix (for version 4.0). The variable Hence, the variable J1900 to J2000 should be the equivalent of 36524 days ... but the hifitime reference is the zeroth hour of 01 Jan 1900, so the variable is incorrectly named but correctly sets the J2000 offset. I'll be removing this error promptly. For posterity, I checked this math in SPICE. However, SPICE initializes everything in UTC, and incorrectly assumes that there were nine leap seconds before the first leap second of 1972, so let's just ignore the seconds here.
|
Beta Was this translation helpful? Give feedback.
Just a quick update on this discussion from a renewed understanding from working the bug fix (for version 4.0). The variable
J2000_TO_J1900_DURATION
suffered from two errors that "canceled" each other out. First, I incorrectly noted J1900 as being the "prime epoch" of NTP: the original hifitime referenced NTP, and I incorrectly thought that J1900 and NTP started at the same time, but they don't (J1900 starts at noon, NTP at zero hours). The second error is that the 20th century, from 1900 to 2000, only had 36524 days, instead of 36525 days, because 1900 was not a leap year. However, a century is defined as 36425 days (even though a century only has that many days every fourth century).He…