open-space-toolkit-physics
open-space-toolkit-physics copied to clipboard
[fix] Timezone conversion issue when creating an Instant from a python datetime
Describe the bug A clear and concise description of what the bug is. Describe if the bug appears in the cpp code, in the bindings, if it affects the unit tests, the compilation steps. Provide the versions of the library that are used in your setup or the hash of the images used (if any).
Steps to reproduce
- Set system time to a time zone other than UTC, run the following code block
- note how ostk_instant has an unexpected offset from the utc datetime object even when printed with utc time
import datetime
from ostk.physics.time import Instant, Interval, Scale
from ostk.physics.time import DateTime
dt = datetime.datetime(2024, 4, 19, 0, 0, 0, tzinfo=datetime.timezone.utc)
ostk_instant = Instant.date_time(dt, Scale.UTC)
print(dt)
print(dt.astimezone(tz=datetime.timezone.utc))
print(ostk_instant.to_string(Scale.TT))
print(ostk_instant.to_string(Scale.UTC))
Example output of the bug:
Don't hesitate to add screenshots if that helps.
Expected behavior
Additional context Setting system time to UTC fixes the issue
Potential suggestion Issue is likely here (from Lucas) https://github.com/open-space-collective/open-space-toolkit-physics/blob/main/bindings/python/src/OpenSpaceToolkitPhysicsPy/Time/DateTime.cpp#L79