skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.4k stars 211 forks source link

timescale zero based for minutes only? #638

Closed zapper44 closed 2 years ago

zapper44 commented 2 years ago

Does timescale use zero-based minutes whereas the other units do not?

Python 3.7.3 Skyfield v1.39

For example:

from skyfield.api import EarthSatellite, load, wgs84

ts = load.timescale()

for min in range(0, 3):

    t = ts.utc(2021, 9, 18, 10, min, 30)

    utc_hrs = t.utc_strftime('%H')
    utc_min = t.utc_strftime('%M') 
    utc_sec = t.utc_strftime('%S')

    print(t.utc_strftime('%Y %b %d %H:%M:%S'), utc_hrs, utc_min, utc_sec, t)

Generates the following output:

2021 Sep 18 10:00:30 10 01 30 <Time tt=2459475.9178146296>
2021 Sep 18 10:01:30 10 02 30 <Time tt=2459475.918509074>
2021 Sep 18 10:02:30 10 03 30 <Time tt=2459475.9192035184>

Notice how only minutes is zero based, whereas seconds and hours is not.

Is this a feature or a bug?

brandon-rhodes commented 2 years ago

This behavior is to agree with how almanacs display time: if an almanac shows only minutes, then it's rounding to the nearest minute using the seconds. The documentation for the method you're calling —

https://rhodesmill.org/skyfield/api-time.html#skyfield.timelib.Time.utc_strftime

— describes the behavior down at the bottom:

If the smallest time unit in your format is minutes or seconds, then the time is rounded to the nearest minute or second. Otherwise the value is truncated rather than rounded.

I'll bet that I need to move that info up so that people can find it. I'll see about putting the word "round" in the first line somewhere.

zapper44 commented 2 years ago

Oh, I'm such a noob when it comes to converting timestamps and understanding how this all fits together, haha.. Thanks for holding my hand here and pointing me to my misinterpretation. I also think I got the 'zero-based' title somewhat wrong but at least you instantly knew what I was talking about.

Back to reading the API page a bit more.. ;-)