title: System call mktime ignores tm_isdst flag
body: <p>another one question regarding mktime and DST</p>
  
  <p>Linux, Ubuntu, time zone is set to Europe/Berlin i.e. current time is CEST:</p>
  
  <pre><code>&gt;date
  Mon Aug 22 16:08:10 CEST 2016
  &gt;date --utc
  Mon Aug 22 14:08:14 UTC 2016
  </code></pre>
  
  <p>everything okay so far.</p>
  
  <p>Now I try to run the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  int main()
  {
  
      struct tm   tm = {0};
      int secs;
  
      tm.tm_sec = 0;
      tm.tm_min = 0;
      tm.tm_hour = 12;
      tm.tm_mon = 9 - 1;
      tm.tm_mday = 30;
      tm.tm_year = 2016 - 1900;
  
      tm.tm_isdst = 0;
      secs = mktime(&amp;tm);
      printf("%i\n", secs);
  
      tm.tm_isdst = 1;
      secs = mktime(&amp;tm);
      printf("%i\n", secs);
  
      tm.tm_isdst = -1;
      secs = mktime(&amp;tm);
      printf("%i\n", secs);
  
      return 0;
  }
  </code></pre>
  
  <p>and get</p>
  
  <pre><code>1475233200
  1475233200
  1475233200
  </code></pre>
  
  <p>which is in all three cases wrong (1 hour offset):</p>
  
  <pre><code>&gt;date -d @1475233200
  Fri Sep 30 13:00:00 CEST 2016
  </code></pre>
  
  <p>So I am a bit puzzled now, is my timezone somehow broken? Why is tm_isdst flag ignored completely?</p>
  
  <p><strong>Edit: @Nominal Animal had the answer: mktime modifies tm_hour! I wonder where it is documented?!</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  
  void reset(struct tm* tm){
      (*tm) = (const struct tm){0};
  
      tm-&gt;tm_sec = 0;
      tm-&gt;tm_min = 0;
      tm-&gt;tm_hour = 12;
      tm-&gt;tm_mon = 9 - 1;
      tm-&gt;tm_mday = 30;
      tm-&gt;tm_year = 2016 - 1900;
  }
  
  int main()
  {
  
      struct tm   tm;
      int secs;
  
      reset(&amp;tm);
      tm.tm_isdst = 0;
      secs = mktime(&amp;tm);
      printf("%i\n", secs);
  
      reset(&amp;tm);
      tm.tm_isdst = 1;
      secs = mktime(&amp;tm);
      printf("%i\n", secs);
  
      reset(&amp;tm);    
      tm.tm_isdst = -1;
      secs = mktime(&amp;tm);
      printf("%i\n", secs);
  
      return 0;
  }
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>1475233200
  1475229600
  1475229600
  </code></pre>