[LEAPSECS] leapseconds, converting between GPS time (week, second) and UTC
Tom Van Baak
tvb at LeapSecond.com
Tue Jan 15 13:50:10 EST 2019
Jim -- I'm replying via the LEAPSECS list because we love leap second questions here.
List -- Jim is a long-time member of time-nuts, works at JPL, and does wonderful stuff.
>From Jim Lux:
> I'm working with a variety of things which work in UTC or GPS
> week/millisecond, so we're doing a lot of conversion back and forth.
> (the spacecraft puts out time in week:millisecond, all the ground
> systems processing is in UTC)
>
> The question comes up when converting back and forth, and whether
> various libraries handle leap seconds correctly.
> For now, I can use a hack of not computing back to 6 Jan 1980, but use
> an epoch like 15 Dec 2018 (week 2031: 518,400.000 seconds) and hope
> there's no leap second in the offing.
Yes, that's one way. But that doesn't sound safe or correct to me.
> For instance, in Python, if I do a datetime(2016,12,31,0,0,0) +
> timedelta(hours=30) does it come out as 1/1/2017 6:00:00 or 5:59:59 (it
> comes out 0600)
>
> Similarly, does Excel's time formatting allow for some minutes having an
> extra second, or does it just assume all minutes are 60 seconds.
Nope. All minutes have 60 seconds in Excel. And in Windows. And in Unix/POSIX. Really any computer system that uses a fixed "epoch" and a ticking "counter" is ruined by leap seconds. The systems differ in their epoch's, they all differ in their counters, they can all be set to UTC, except they all fail when there's a positive or negative leap second.
> I'll probably test it for the cases I'm interested in (Ruby, Python,
> Excel, Matlab, Octave), but if someone else has already done it, then
> I've got something to cross check against.
This is a good question for LEAPSECS. I suspect those packages are well-known here.
> (python does NOT know about leap seconds)
>
> import datetime
>
> d = datetime.datetime(2016,12,31)
>
> dt = datetime.timedelta(hours=30)
>
> d
> Out[4]: datetime.datetime(2016, 12, 31, 0, 0)
>
> dt
> Out[5]: datetime.timedelta(1, 21600)
>
> d+dt
> Out[6]: datetime.datetime(2017, 1, 1, 6, 0)
Right, this is typical for almost any software developed anywhere. Leap seconds are such a weird exception, almost no commercial software, web frontend or backend, or mobile phones, or mobile apps deal with them correctly.
I'm hoping a number of LEAPSECS members can chime in. There are astronomers here who must be used to solving issues like this, in python or other tools, so their input would be valuable.
/tvb
More information about the LEAPSECS
mailing list