Will converting the difference between 2 datenums to seconds contain leap seconds or not?

5 visualizzazioni (ultimi 30 giorni)
I have a GPS logger that provides a .CSV record of location and speed for every second in the format 'mm/dd/yyyy,HH:MM:SS AM'. Assuming the date and time are in GPS time rather than UTC, when I take the datenum difference between this and the GPS epoch will the leap seconds be included or not?
GPSsecond = 24*60*60*(datenum( strTime, 'mm/dd/yyyy,HH:MM:SS AM' ) - datenum( 1980, 1, 6, 0, 0, 0 ));
Should I add the (current) 17 leap seconds or not?

Risposta accettata

Brendan Hamm
Brendan Hamm il 21 Lug 2015
datenum does not handle leap seconds. datetime variables on the other hand can handle this (requires you have 2014b or later) provided you specify the appropriate TimeZone .
  2 Commenti
Peter Perkins
Peter Perkins il 23 Lug 2015
Just to be clear, datenum does not support leap seconds, but then again GPS time doesn't have leap seconds. If all the arithmetic you're doing is "in" GPS time, and you're never converting to UTC, and not getting the current system time, and not using timestamps from anything other than GPS clocks, then I think datenum actually does what you want. (If you have R2014b or later, so would "unzoned" datetimes, and more elegantly.) It's all a question of what interpretation you put on the values.
If your goal is converting to UTC or some civil time zone, then that's a different story. You'd have to account for the lack of leap seconds in GPS time.
datetime (R2014b or later) provides a version of UTC that completely ignores the existence of leap seconds (lots of people want to act as if leap seconds don't exist), as well as a version that accounts for leap seconds.

Accedi per commentare.

Più risposte (2)

the cyclist
the cyclist il 21 Lug 2015
Modificato: the cyclist il 21 Lug 2015
An easy test to show that datenum does not handle this is
ds1 = '07/01/1972,00:00:00 AM';
ds2 = '06/29/1972,00:00:00 AM';
GPSsecond = 24*60*60*(datenum( ds1, 'mm/dd/yyyy,HH:MM:SS AM' ) - datenum( ds2, 'mm/dd/yyyy,HH:MM:SS AM' )) - 172800
Note that according to the Wikipedia page on leap seconds, one was inserted on June 30, 1972. So, the above test would have given 1 instead of 0 if the leap second had been in there.
  5 Commenti
Carl Finney
Carl Finney il 22 Lug 2015
I'm running R2015a, but haven't checked to see if the latest leap second this year has been incorporated. What I'm trying to do is correlate data from a GPS logger that's exported in local time zone strings to data that's time tagged in GPS seconds (i.e. seconds since 1/6/1980 00:00:00).
Steven Lord
Steven Lord il 22 Lug 2015
It does, as described in this Bug Report for release R2014b. Technically you could quibble about whether this is a bug, since the leap second was announced in January 2015 which was after release R2014b shipped, but I think the bug report exists mainly so we could attach a patch.

Accedi per commentare.


James Tursa
James Tursa il 21 Lug 2015
Modificato: James Tursa il 21 Lug 2015

Categorie

Scopri di più su Time Series Objects in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by