From 809522b9ac372abf49e516da019a0cdc8567b2b2 Mon Sep 17 00:00:00 2001 From: Johan Westin Date: Thu, 2 Oct 2025 09:52:34 +0000 Subject: [PATCH 1/2] add test for ephemeris time to python datetime conversion --- tests/python/test_epoch.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/python/test_epoch.py b/tests/python/test_epoch.py index 44b0947..9b24a59 100644 --- a/tests/python/test_epoch.py +++ b/tests/python/test_epoch.py @@ -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) From 7d5ad9aef4c4efa7d01a4bb5e642673e5b6f5608 Mon Sep 17 00:00:00 2001 From: Johan Westin Date: Thu, 2 Oct 2025 12:09:02 +0000 Subject: [PATCH 2/2] convert duration to utc in todatetime method --- src/epoch/python.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/epoch/python.rs b/src/epoch/python.rs index 8de6aef..471f39c 100644 --- a/src/epoch/python.rs +++ b/src/epoch/python.rs @@ -964,7 +964,7 @@ impl Epoch { /// :rtype: datetime.datetime fn todatetime<'py>(&self, py: Python<'py>) -> Result, 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)?;