From 46349c1bac5fd5aad8eb40686b6098bb056c652c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jonglez?= <clement@jonglez.space> Date: Sun, 26 Apr 2020 16:02:25 +0200 Subject: [PATCH] Force python datetime to stay at second=59.999999 during a leap second --- python_files/pyhelpers.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/python_files/pyhelpers.py b/python_files/pyhelpers.py index 4505978..86f19a7 100644 --- a/python_files/pyhelpers.py +++ b/python_files/pyhelpers.py @@ -104,13 +104,19 @@ def absolutedate_to_datetime(orekit_absolutedate): or_date = or_comp.getDate() or_time = or_comp.getTime() seconds = or_time.getSecond() + seconds_int = int(math.floor(seconds)) + microseconds = int(1000000.0 * (seconds - math.floor(seconds))) + if seconds_int > 59: # This can take the value 60 during a leap second + seconds_int = 59 + microseconds = 999999 # Also modifying microseconds to ensure that the time flow stays monotonic + return datetime(or_date.getYear(), or_date.getMonth(), or_date.getDay(), or_time.getHour(), or_time.getMinute(), - int(math.floor(seconds)), - int(1000000.0 * (seconds - math.floor(seconds)))) + seconds_int, + microseconds) def datetime_to_absolutedate(dt_date): -- GitLab