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

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?

 採用された回答

Brendan Hamm
Brendan Hamm 2015 年 7 月 21 日

0 投票

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 件のコメント

Carl Finney
Carl Finney 2015 年 7 月 21 日
Thanks for the info
Peter Perkins
Peter Perkins 2015 年 7 月 23 日
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.

サインインしてコメントする。

その他の回答 (2 件)

the cyclist
the cyclist 2015 年 7 月 21 日
編集済み: the cyclist 2015 年 7 月 21 日
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 件のコメント

Carl Finney
Carl Finney 2015 年 7 月 21 日
This is a very good answer. Thanks for the test,
Brendan Hamm
Brendan Hamm 2015 年 7 月 21 日
編集済み: Brendan Hamm 2015 年 7 月 21 日
In fact the most recent was only last month on Tuesday, June 30, 2015 at 23:59:60 UTC
the cyclist
the cyclist 2015 年 7 月 21 日
I deliberately decided not to use the latest. I was unsure as to when the Time Lords decided to add leap seconds, and how long that might take to be implemented in MATLAB. That might prove to be an interesting test for Brendan's solution.
Carl Finney
Carl Finney 2015 年 7 月 22 日
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 2015 年 7 月 22 日
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by