AndrewAnnex / SpiceyPy

SpiceyPy: a Pythonic Wrapper for the SPICE Toolkit.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spiceypy.et2datetime(et) issue around the date where a leapsecond is added

VitalianoGentile opened this issue · comments

Using the spiceypy.et2datetime(et) function there seems to be a problem when it needs to convert epoch seconds around the date where a leapsecond is added.

Example:

spiceypy.et2datetime(488980866.184127) = 2015-06-30 23:59:59+00:00
spiceypy.et2datetime(488980868.184127) = 2015-07-01 00:00:00+00:00
spiceypy.et2datetime(488980867.184127) = ValueError: second must be in 0..59

Leapsecond added on 2015-07-01 23:59:60+00:00

The inverse function works correctly:

spiceypy.datetime2et(datetime.fromisoformat('2015-06-30T23:59:59.000')) = 488980866.184127
spiceypy.datetime2et(datetime.fromisoformat('2015-07-01T00:00:00.000')) = 488980868.184127

@VitalianoGentile this looks to be a shortcoming of the python datetime class that just doesn't support leap seconds in this way https://docs.python.org/dev/library/datetime.html#datetime.date.fromtimestamp

Not sure if there is a work around for this yet.

I'm closing this issue for now as it's a fundamental limitation of the python datetime object rather than a specific bug in spiceypy, however I am willing to re-open the issue to better support workarounds if they exist.

it's a fundamental limitation of the python datetime object rather than a specific bug in spiceypy

I stumbled upon this error myself just now, and came to the same conclusion. It might be nice, however, if SpiceyPy provided an exception message that was a bit more informative. I may submit a PR myself with a proposal for such a thing.

@cgobat sure a pull request would be great if limited to the fromisoformat helper function... which should probably be moved to the support_types.py file also.