3

As described here and here, there is a difference between UTC and GPS Time because UTC occasionally has a leap second applied.

As of 2021 the difference is 18 seconds. So currently the equation is:

var gpsTime = utcDate.AddSeconds(18);

I need to calculate the gpsTime for all kinds of dates (past and near future). I could store a list of leap seconds and work out the GPS delta in play at any particular date. But I don't want the future maintainers of this code to have to remember to manually update the list whenever a new leap second comes along. Rather, it would be nice to use a library (maintained by the open source community) which is always up to date.

So is anyone aware of a library which can either:

  1. Convert UTC to GPS time, or
  2. Provide a list of Leap seconds?

Do any of these exist within the .NET framework or in some library on Nuget?

Fidel
  • 7,027
  • 11
  • 57
  • 81
  • https://en.wikipedia.org/wiki/Leap_second "The irregularity and unpredictability of UTC leap seconds is problematic for several areas, especially computing " – Dmitry Bychenko Aug 25 '20 at 11:12
  • Haha indeed Dmitry – Fidel Aug 25 '20 at 11:12
  • You can try a ZCount lookup tools. GPS time is based on ZCount which is every 1.5 seconds and rolls over every 19 years. The last time the roll over occurred was in April. So the GPS time is really a ZCount. So if you take the lookup tools you will get GPS Time and UTC time. See : https://www.labsat.co.uk/index.php/en/gps-time-calculator. so if you get current zcount and subtract the zcount (multiply by 1.5 seconds) you want then convert to Time you may UTC time you are looking for. – jdweng Aug 25 '20 at 11:26
  • 1
    For past: you have the data. For future, keep it constant to 18. it is possible (probable) than in next few years there will be no more leap seconds on UTC: this is in discussion since various years, but now it seems probable. [And it doesn't matter much, most of us have more then few second offset with true local geo-solar time] – Giacomo Catenazzi Aug 25 '20 at 13:27
  • Thanks Giacomo, fascinating – Fidel Aug 25 '20 at 13:31
  • Can you just download that leap second list at runtime and parse it yourself? – glen3b Sep 07 '20 at 17:42
  • Hi Glen, yes definitely. It's true that the ietf.org website is unlikely to go offline or change formats, so downloading & parsing does make sense. But in my case this software is never connected to the internet, which is why I thought the next best thing is for the list to be updated whenever say, a Nuget library is updated (and the software is redeployed). Thanks for the suggestion though! – Fidel Sep 07 '20 at 22:06
  • 1
    If the machine is offline, you can ignore few second differences. If you are connected to a GPS (e.g. to get time), you should get the number of leap seconds, and eventually the next change (adding or removing seconds). So GPS data should provide you such information – Giacomo Catenazzi Sep 16 '20 at 15:02

0 Answers0