title: How safe is it to assume time_t is in seconds?
body: <p>I'm doing a lot of calculations with times, building time objects relative to other time objects by adding seconds. The code is supposed to run on embedded devices and servers. Most documentations say about <code>time_t</code> that it's some arithmetic type, storing usually the time since the epoch. How safe is it to assume that <code>time_t</code> store a number of seconds since something? If we can assume that, then we can just use addition and subtraction rather than <code>localtime</code>, <code>mktime</code> and <code>difftime</code>.</p>
  
  <p>So far I've solved the problem by using a <code>constexpr bool time_tUsesSeconds</code>, denoting whether it is safe to assume that <code>time_t</code> uses seconds. If it's non-portable to assume <code>time_t</code> is in seconds, is there a way to initialize that constant automatically?</p>
  
  <pre><code>time_t timeByAddingSeconds(time_t theTime, int timeIntervalSeconds) {
      if (Time_tUsesSeconds){
          return theTime + timeIntervalSeconds;
      } else {
          tm timeComponents = *localtime(&amp;theTime);
          timeComponents.tm_sec += timeIntervalSeconds;
          return mktime(&amp;timeComponents);
      }
  }
  </code></pre>