필터 지우기
필터 지우기

Incorrect datetime UTCLeapSeconds conversion

조회 수: 5 (최근 30일)
James Tursa
James Tursa 2023년 8월 7일
댓글: James Tursa 2023년 8월 9일
I am working with leap second data, and as part of the calculations I did this for a particular leap second:
dt1 = datetime(1972,6,30,23,59,60,'TimeZone','UTCLeapSeconds')
dt1 = datetime
1972-06-30T23:59:60.000Z
dt2 = datetime(dt1,'TimeZone','UTCLeapSeconds')
dt2 = datetime
1972-06-30T23:59:59.000Z
dt2.TimeZone
ans = 'UTCLeapSeconds'
dt1 - dt2
ans = duration
00:00:01
Well, you can see what happened. Even though the input and output time zones are both 'UTCLeapSeconds', the datetime( ) function has changed the time of this and jumped backwards 1 second. So to get around this I am forced to write code like this:
if( isequal(dt1.TimeZone,'UTCLeapSeconds') )
dt2 = dt1
else
dt2 = datetime(dt1,'TimeZone','UTCLeapSeconds')
end
dt2 = datetime
1972-06-30T23:59:60.000Z
dt1 - dt2
ans = duration
00:00:00
Looks like a bug to me, but does someone have another explanation for why this might be happening?

답변 (1개)

Cris LaPierre
Cris LaPierre 2023년 8월 7일
편집: Cris LaPierre 2023년 8월 7일
Potentially a bug, which you can report here: https://www.mathworks.com/support/contact_us.html
It looks like you have applied the time zone twice. You can do this instead:
dt1 = datetime(1972,6,30,23,59,60,'TimeZone','UTCLeapSeconds')
dt1 = datetime
1972-06-30T23:59:60.000Z
dt2 = dt1
dt2 = datetime
1972-06-30T23:59:60.000Z
dt2.TimeZone
ans = 'UTCLeapSeconds'
dt1 - dt2
ans = duration
00:00:00
  댓글 수: 2
James Tursa
James Tursa 2023년 8월 7일
I submitted a bug report.
James Tursa
James Tursa 2023년 8월 9일
TMW has replied that this bug will be fixed in the R2023b.

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by