I have the following doubt on the usage of tm_isdst flag in the tm structure. As per man pages and googled results, I understand that its value is interpreted as follows
A. A value of 0 indicates DST is not in effect for the represented time
B. A value of 1 indicates DST is in effect
C. A value of -1 causes mktime to check whether DST is in effect or not.
It is this third point which is confusing me. My doubt is how mktime can figure out whether DST has to be applied or not accurately.
For example
My Time Zone = GMT + 3:00
DST shifting = +1 Hour at 5:00 AM in January (to keep it simple)
Current UTC time = "01/Jan/2012 00:00:00"
UTC time in seconds time_t timetUTC = X seconds
Hence my time is = "01/Jan/2012 03:00:00"
As time passes, my time value changes as follows
"01/Jan/2012 04:00:00" (X + 1 * 60 * 60)
"01/Jan/2012 05:00:00" (X + 2 * 60 * 60)
"01/Jan/2012 05:59:59" (X + 2 * 60 * 60 + 59)
"01/Jan/2012 05:00:00" (X + 3 * 60 * 60)
"01/Jan/2012 06:00:00" (X + 4 * 60 * 60)
As per my understanding
tm tmMyTime = localtime_r(X + 2 * 60 * 60) will set tmMyTime.tm_isdst to 0
tm tmMyTime = localtime_r(X + 3 * 60 * 60) will set tmMyTime.tm_isdst to 1
This way, even though all other components of tm structure are equal in both cases, mktime(tmMyTime) can return proper UTC value, depending on tm_isdst value.
Now, if I set tmMyTime.tm_isdst = -1, what value would mktime return? I read about TZ variable, time database etc etc. In spite of all that, logically how can mktime() figure out whether to apply DST correction or not for those tm values that can occur twice?
We do not have DST in our time zone. Hence I am not very sure whether my understanding is correct. Please correct me if I am wrong. Your help is much appreciated.