Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/epoch/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ impl Epoch {
/// :rtype: datetime.datetime
fn todatetime<'py>(&self, py: Python<'py>) -> Result<Bound<'py, PyDateTime>, PyErr> {
let (y, mm, dd, hh, min, s, nanos) =
Epoch::compute_gregorian(self.duration, TimeScale::UTC);
Epoch::compute_gregorian(self.to_utc_duration(), TimeScale::UTC);

let datetime = PyDateTime::new(py, y, mm, dd, hh, min, s, nanos / 1_000, None)?;

Expand Down
15 changes: 15 additions & 0 deletions tests/python/test_epoch.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ def test_interop():
)


def test_ephemeris_time_todatetime():
"""
Test for the issue highlighted by [issue 421][issue-421].

[issue-421]: https://github.com/nyx-space/hifitime/issues/421
"""
test_epoch = Epoch("2025-03-07T12:01:09.185475585 ET")

actual_datetime = test_epoch.todatetime()
expected_datetime = datetime(year=2025, month=3, day=7, hour=12, minute=0)

# Before fixing, `actual_datetime = (1925, 3, 8, 0, 1, 9, 185475)`.
assert actual_datetime == expected_datetime


def test_polynomial():
t_gpst = Epoch.from_gregorian(2020, 1, 1, 0, 0, 0, 0, TimeScale.GPST)

Expand Down