Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

J1900 and J2000 references mix up, causing older Julian dates to be wrong #282

Closed
ChristopherRabotin opened this issue Feb 28, 2024 · 1 comment · Fixed by #307
Closed

Comments

@ChristopherRabotin
Copy link
Member

ChristopherRabotin commented Feb 28, 2024

Internally, there is a mix up between the J1900 reference and the J2000 reference. Specifically, the J2000_TO_J1900_DURATION constant is a duration of 36524 days 12 h but it should be 36525 days, i.e. a duration of one century exactly.

As pointed out in #281, the J2000 reference epoch is at noon not at midnight as that specific constant points to.

This bug affects only this constant, and does not affect the external API. This is because the constant is only used in the time system conversions to ET and TDB which are validated against NAIF SPICE. Other conversions that rely on the Julian epochs use the J1900_OFFSET and J2000_OFFSET constants, which fix that twelve hour difference. In other words, this constant fixes the glitch introduced by the reference epoch being wrong by twelve hours.

Example

use hifitime::{Epoch, TimeUnits, J1900_REF_EPOCH, J2000_REF_EPOCH, J2000_TO_J1900_DURATION};

#[test]
fn discuss() {
    println!("{J2000_TO_J1900_DURATION}");
    println!("{}", Epoch::from_utc_duration(0_f64.nanoseconds()));
    println!(
        "{}",
        Epoch::from_utc_duration(0_f64.nanoseconds()).to_jde_utc_days()
    );
    println!(
        "{}",
        Epoch::from_jde_tai(2451545.0).to_gregorian_str(hifitime::TimeScale::TAI)
    );
    println!(
        "{}",
        J1900_REF_EPOCH.to_gregorian_str(hifitime::TimeScale::TAI)
    );
    println!(
        "{}",
        J2000_REF_EPOCH.to_gregorian_str(hifitime::TimeScale::TAI)
    );
}

Output

36524 days 12 h                      // --> This should be 36525 days exactly
1900-01-01T00:00:00 UTC
2415020.5                                // --> A zero duration UTC should be J1900 exactly, whose Julian date is 2415020.0
2000-01-01T12:00:00 TAI      // --> This matches SPICE J2000: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/FORTRAN/spicelib/j2000.html
1900-01-01T00:00:00 TAI     // --> Wrong by twelve hours
2000-01-01T12:00:00 TAI     // --> Correct
test discuss ... ok

Fix acceptance

  • This issue should deprecate this constant entirely, and remove its usage in the code base.
  • The J1900 reference epoch should be corrected so that an initialization at zero duration returns noon on 01 Jan 1900 instead of midnight. (Maybe?)

This bug is directly related to the test failed in #280 and #261.

@ChristopherRabotin
Copy link
Member Author

Slight correction: the 20th century, i.e. from 1900 to 2000, only had 36524 days because 1900 was not a leap year. The definition of one century is 36525 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant