-
-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
utc_strftime("%j") fails when presented with a time near the end of the day #542
Comments
Here's another example of the most troublesome behavior associated with this:
This marches through the end of day 196, and then when crossing midnight, thinks it's on day 198. An excerpt of the output is here:
|
Even though I’ve never mixed them in my own code, I think it’s a reasonable expectation that |
@tj-murphy — Oh, and, you might try combining |
Sounds great, thanks for your support! |
All right, I tried moving some code around so that the two routines
|
This looks great! Thanks so much for the quick fix! |
Hi,
I'm trying to convert Skyfield dates into the format used for TLE epochs (last two digits of year, followed by a float representing the day of the year). I'm doing this because I want to determine a spacecraft's position throughout the past year, and I have all the TLE's issued for that spacecraft in the past year, so to get the position I first load up whichever TLE was the most current at that time.
I ran into what seems to be a bug - the utc_strftime("%j") is meant to return the day-of-year of a date. 1 for January 1, 31 for January 31, 32 for February 1, etc. If this is passed a Skyfield object which is very close to the end of a day, it will increment to the next day. The following short script demonstrates this:
These two times, both of which are very near to the end of January 1, give different results. The first correctly indicates that it is still January 1, but the second, which is 10^-19 seconds later, thinks the time has shifted to January 2.
I suspect this is a matter of running into the limits of floating point precision. It may be impossible to fix this within Skyfield, but in case it's fixable, I thought I'd post this as a notice of unintended behavior. Thanks!
In my original use case, where I want the day of the year and a fractional date (how far through that day time has progressed), this becomes especially frustrating, because my fractional date value, which is found by (3600 * hour + 60 * minute + second) / 86400 returns 1 - that is, it correctly finds that we are at the end of the day. Therefore when I take the day, which has rolled over to 2, and add the fractional day, I find that it's the start of January 3. If it's not possible to improve the strftime performance, it would be cool if
ts.utc(2021,1,1,23,59,59.9999798834251798497).utc
would roll over together with it and return 2021,1,2,0,0,0. That way, even though it's jumping the gun to January 2, at least it correctly says it's the very beginning of January 2 rather than the very end.The text was updated successfully, but these errors were encountered: