0

I have a library which needs to know the number of seconds since a previous epoch. This needs to work across leap second boundaries. One of the functions to make it easier for users is to specify the time in unix time - which of course does not take account for leap seconds. This is easily handled if I know when leap seconds have (or will be) inserted (or removed).

Is there any standard way of getting a list of leap second events, other than just keeping a hardcoded table (or similar), which of course needs to be updated every couple of years?

Chris
  • 852
  • 1
  • 8
  • 19
  • Which programming language do you apply for your problem? Can you use Java? If yes then look at this post(http://stackoverflow.com/q/33698664/2491410). – Meno Hochschild Nov 25 '15 at 13:06
  • The one true language - C – Chris Dec 17 '15 at 02:53
  • Thanks for feedback, by the way, the well known tzdb repository hosted at "iana.org/tz" also contains a list of leap second events so you might connect or download that (but I don't know how to do this with C). – Meno Hochschild Dec 17 '15 at 04:38
  • Here's a leapsecond event list from NIST (built directly from IERS data) that's very easy to parse in any programming language: https://www.ietf.org/timezones/data/leap-seconds.list It also contains a great explanation in its header comments. – PM 2Ring May 27 '21 at 04:06

1 Answers1

1

Here are two partial answers to your problem:

  1. Because leap seconds are fundamentally unpredictable – they're caused by irregular variations in the rotation of the earth, due ultimately to the distribution of mass on the planet sloshing around – they're not defined more than a few months in advance. Therefore if you need to know leap seconds, you'll need an update every six months, even if the update is ‘no leap second this January/July’.

  2. If all you need is the number of seconds from a previous epoch, you don't have to use UTC. GPS time is essentially UTC without the leap seconds (that is, when a GPS device shows you civil time, it's essentially showing you GPS time plus a count of leap seconds). If you can get a hold of GPS time, therefore, you're sorted. You'd be able to get that from a GPS receiver. Alternatively, though I don't know, I'd be surprised if it wasn't possible to persuade an NTP server to give you GPS time.

Norman Gray
  • 11,978
  • 2
  • 33
  • 56
  • Thanks Norman, though that does not answer the question - I understand all this (I'm an astrophysicist) - I was hoping there might be a unix interface to get leap second record without rolling my own. – Chris Nov 24 '15 at 00:48
  • Ah, well in _that_ case, you might want to use `slalib` (though I don't have a ‘download it from here’ recipe – long story), or [SOFA](http://www.iausofa.org), or you might have to resort to [Tempo](https://en.wikipedia.org/wiki/Tempo_(astronomy)) (depending on what you need). `slalib` is built in to quite a few things, so it might be conveniently available once you know to look for it; failing that, I'd look at SOFA if I were you; Tempo is hammer-cracking-nut territory, though I've very little experience with it. Unix time is nasty (not linear) and fumbles leap seconds nastily. – Norman Gray Nov 24 '15 at 12:22
  • And @Chris, I see you're a radio person, in which case Tempo might be in your future anyway.... That, and the Explanatory Supplement. ‘Unix time’ is largely useless for precise work. – Norman Gray Nov 24 '15 at 12:25
  • Looking for something else, but clearly primed by this conversation, I today re-found a bookmark to [‘the unix leap second mess’](http://www.madore.org/~david/computers/unix-leap-seconds.html), which includes a link to a discussion of [NTP and leap seconds](https://www.eecis.udel.edu/~mills/leap.html). It seems my guess was wrong, and that GPS time _isn't_ available from an NTP service. ('nuff commenting, now...) – Norman Gray Nov 24 '15 at 22:33