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

조회 수: 10 (최근 30일)
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일
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
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월 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.

댓글을 달려면 로그인하십시오.


James Tursa
James Tursa 2015년 7월 21일
편집: James Tursa 2015년 7월 21일

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by