rzusman
Posts: 333
Joined: Fri Jan 01, 2016 10:27 pm

What does mtkime with tm_isdst = -1 do during DST transition?

Tue Oct 30, 2018 2:08 am

I just found a bug in my code, due to me not explicitly setting tm_isdst to -1 when updating the time using mktime. It took me a long time to detect, since I live in Arizona, and we don’t observe DST. Changing the time update routine to have tm_isdst = -1 seems to fix the time update issue I was having in other timezones. But, after reading up on what this field does, a number of people have posted that during the ST->DST and DST->ST transitions, what mktime does is undefined (or at least poorly defined). So, I am curious - does anyone know what mktime and tm_isdst = -1 does during the 1 hour of uncertainty?

BTW, a lot of people suggest simply avoiding the problem by not changing the time during those two uncertain times, but this is an embedded system, and the time may get updated automatically via cellular modem, so I would like to know what to expect.

User avatar
buja
Posts: 484
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: What does mtkime with tm_isdst = -1 do during DST transition?

Tue Oct 30, 2018 4:56 am

No real answer I am afraid. My first thought was that tm_isdt should never be negative, but K&R says this:
tm_isdt is positive if Daylight Saving Time is in effect, zero if not, and negative if the information is not available.
If behavior is undefined I think the only options is to test what the behavior is in your case. If DST information is not available I would expect local time to be based on the time zone information without DST as a best guess.

Return to “C/C++”