title: Offsetting time_t in C++
body: <p>I am dealing with timestamps generated by a system where the epoch is not the standard UNIX epoch of seconds since midnight of Jan 1, 1970 (it starts somewhere in 1965 instead). <a href="https://stackoverflow.com/questions/20521750/ticks-between-unix-epoch-and-gps-epoch">This</a> question is kind of related. So, I have a "fixup" function to deal with this offset:</p>
  
  <pre><code>time_t fix_time(uint32_t raw_time)
  {
      const int32_t epoch_offset = 157680000; /* offset wrt UNIX epoch */
      time_t fixedTime = static_cast&lt;time_t&gt;(raw_time - epoch_offset);
      return fixedTime;
  }
  </code></pre>
  
  <p>and continue using the standard library functions in rest of the code: </p>
  
  <pre><code>uint32_t raw_time;
  time_t timestamp = fix_timestamp(raw_time);
  struct tm timeinfo;
  gmtime_r(&amp;timestamp, &amp;timeinfo);
  </code></pre>
  
  <p>It seems to work as intended (held up to a mix of real and synthetic test data, so far). However, is there a better way to deal with this scenario? Are there any subtle ways in which this might break? Additional info if it matters: the timestamps are spread out over 1981 to the current day and the program runs on a Linux machine.</p>