utc_strftime does not handle day-of-year (j) properly
See original GitHub issueI think I found a bug in utc_strftime. Let’s define a time in skyfield as:
ts = load.timescale()
t= ts.utc(2020, 9, 29, 10, 20, 0)
This seems to work and give a sensible timestamp:
print(str(t))
<Time tt=2459121.9313562964>
I now want to use the function utc_strftime to print this time as a string in a few different ways. First works fine:
print(t.utc_strftime('%Y.%m.%d.%H:%M:%S'))
2020.09.29.10:20:00
I also want to print this in a different format, using “day of year” (which is 273 for this date). According to https://rhodesmill.org/skyfield/api-time.html#skyfield.timelib.Time.utc_strftime the function utc_strftime “calls Python’s time.strftime() to format the date and time.” and “You can find the full list, along with options that control field widths and leading zeros, at: https://docs.python.org/3/library/time.html#time.strftime”. At this python-doc-page we see “%j | Day of the year as a decimal number [001,366].” so we should get 273 here. But we don’t! Instead:
print(t.utc_strftime('%Y.%j.%H:%M:%S'))
2020.001.10:20:00
001 is wrong! It should be 273. If I try a quick workaround, we indeed find 273:
print(t.utc_datetime().strftime('%Y.%j.%H:%M:%S'))
2020.273.10:20:00
So, it seems that pythons “strftime” does work as intended, but skyfield’s “utc_strftime” does not. I would expect the two to give the same result. Or am I missing something here?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Apologies for the late response - busy days.
I have verified that version 1.30 works as intended, thanks!
I have just released 1.30 with this fix included. Let me know if you run into any problems with the new feature. Thanks!