Why does the highest supported date for both _gmtime32 and _gmtime64 fall on January 19, in different years?

Viewed 42

It's well-known that signed 32-bit time_t will run out on January 19, 2038 (the Y2038 problem).

The Windows function _gmtime64 takes a 64-bit time_t, so in principle it could support a vastly larger range of dates. But, it turns out it doesn't support dates past the year 3000. Specifically, the largest time_t that can be successfully passed to _gmtime64 is 32536846799, which is on January 19, 3001.

Is it just a coincidence that these two apparently-unrelated ranges both end on January 19? Why does _gmtime64 run out when it does?


Python code for computing the largest allowable time_t:

In [1]: from time import gmtime

# invariant: gmtime(low) is ok, gmtime(high) fails
In [2]: low, high = 0, 100000000000

In [3]: while high - low > 1:
   ...:     midpoint = low + (high - low) // 2
   ...:     try:
   ...:         gmtime(midpoint)
   ...:     except OSError:
   ...:         high = midpoint
   ...:     else:
   ...:         low = midpoint
   ...:

In [4]: low
Out[4]: 32536846799
0 Answers
Related