mktime and tm_isdst flag
<p>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</p>

<p>A. A value of 0 indicates DST is not in effect for the represented time</p>

<p>B. A value of 1 indicates DST is in effect</p>

<p>C. A value of -1 causes mktime to check whether DST is in effect or not.</p>

<p>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.</p>

<p>For example</p>

<pre><code>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"
</code></pre>

<p>As time passes, my time value changes as follows</p>

<pre><code>"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)
</code></pre>

<p>As per my understanding</p>

<pre><code>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
</code></pre>

<p>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.</p>

<p>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?</p>

<p>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.</p>

<p>thanks,
Reji</p>
