<div dir="ltr"><div><br></div><div>Hi,<br><br></div><div>I found that sometimes the localtime() won&#39;t work properly, if sp-&gt;defaulttype is not set properly.  For example, given the following code:<br><br>    time_t epoch = 0;<br>
<br>    setenv(&quot;TZ&quot;, &quot;UTC+00&quot;, 1);<br>    tzset();<br>    printf(&quot;%s&quot;, ctime(&amp;epoch)); // (a)<br><br>    setenv(&quot;TZ&quot;, &quot;Asia/Taipei&quot;, 1);<br>    tzset();<br>    printf(&quot;%s&quot;, ctime(&amp;epoch)); // (b)<br>
<br>    setenv(&quot;TZ&quot;, &quot;UTC+00&quot;, 1);<br>    tzset();<br>    printf(&quot;%s&quot;, ctime(&amp;epoch)); // (c)<br><br>The expected output should be:<br><br>    Thu Jan  1 00:00:00 1970<br>    Thu Jan  1 08:00:00 1970<br>
    Thu Jan  1 00:00:00 1970<br><br>However, the output is:<br><br>    Thu Jan  1 00:00:00 1970<br>    Thu Jan  1 08:00:00 1970<br>    Thu Jan  1 08:00:00 1970<br><br></div><div>This is due to the fact that sp-&gt;defaulttype is set to 1 when we are using &quot;Asia/Taipei&quot; as the timezone, but it is not reset after we change the timezone to &quot;UTC+00&quot;.  As the result, the old value in sp-&gt;types[sp-&gt;defaulttype] is incorrectly used.  The attached patch should resolve this issue.  Please have a look.  Thanks.<br>
<br></div><div>Sincerely,<br>Logan<br></div></div>