question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

utc_strftime does not handle day-of-year (j) properly

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vareniuscommented, Oct 12, 2020

Apologies for the late response - busy days.

I have verified that version 1.30 works as intended, thanks!

0reactions
brandon-rhodescommented, Oct 11, 2020

I have just released 1.30 with this fix included. Let me know if you run into any problems with the new feature. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

strptime: Date-time Conversion Functions to and from Character
strftime is a wrapper for format.POSIXlt , and it and format.POSIXct first convert to class "POSIXlt" by calling as.POSIXlt (so they also work...
Read more >
Date And Time Functions - SQLite
The "localtime" modifier (14) assumes the time value to its left is in Universal Coordinated Time (UTC) and adjusts that time value so...
Read more >
Python Datetime : use strftime() with a timezone-aware date
So, real UTC date is 19th March 2009 23:12:00, right ? Now I need to format my date in string, I use >>>...
Read more >
datetime — Basic date and time types — Python 3.11.1 ...
These tzinfo objects capture information about the offset from UTC time, the time zone name, and whether daylight saving time is in effect....
Read more >
1751381 – perl Time::Piece does not respect julian day
This bug has been fixed, and the `strptime()` method provided by the `Time::Piece` module now handles Julian dates properly. Clone Of: Environment:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found