Skip to content

Use microseconds in epoch #35

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,23 @@ mod tests {
Ok(())
}

#[test]
fn test_epoch_has_subsecond_precision() {
let lines = "1 25544U 98067A 20148.21301450 .00001715 00000-0 38778-4 0 9992
2 25544 51.6435 92.2789 0002570 358.0648 144.9972 15.49396855228767";
let tle = TwoLineElement::from_lines(lines).unwrap();
assert_eq!(tle.epoch().unwrap().nanosecond(), 452_818_000);
let t = NaiveDate::from_ymd_opt(2020, 5, 29)
.unwrap()
.and_hms_micro_opt(1, 2, 3, 0)
.unwrap()
.and_utc();
let position = tle.propagate_to(t).unwrap().position;
assert_eq!((position[0] * 1e3) as i64, 4_262_298);
assert_eq!((position[1] * 1e3) as i64, 403_136);
assert_eq!((position[2] * 1e3) as i64, -5_284_434);
}

#[test]
fn test_julian_day_identity() {
let t = Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap();
Expand Down
15 changes: 6 additions & 9 deletions src/sgp4_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,12 @@ pub(crate) fn julian_day_to_datetime(jd: c_double) -> DateTime<Utc> {
);
}

Utc.with_ymd_and_hms(
year,
month as u32,
day as u32,
hour as u32,
minute as u32,
second as u32,
)
.unwrap()
let usec = (second.fract() * 1e6).floor();
NaiveDate::from_ymd_opt(year, month as u32, day as u32)
.unwrap()
.and_hms_micro_opt(hour as u32, minute as u32, second as u32, usec as u32)
.unwrap()
.and_utc()
}

pub(crate) fn datetime_to_julian_day(d: DateTime<Utc>) -> c_double {
Expand Down