Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
When will a 64 bit int run out of space to store epoch time?
1 point by andrewfromx on March 14, 2023 | hide | past | favorite | 2 comments
"A 64-bit integer can store a range of values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. If we assume that the epoch time is stored in Unix format, which is the number of seconds since January 1, 1970, at 00:00:00 UTC, then a 64-bit integer can represent times up to:

9,223,372,036,854,775,807 seconds / 60 seconds per minute / 60 minutes per hour / 24 hours per day / 365.25 days per year = 292,277,026,596 years

This means that a 64-bit integer will run out of space to store epoch time on or around the year 292,277,026,596 AD. However, it's worth noting that this is well beyond the predicted lifespan of our sun and the Earth, so this is not a practical concern for most applications."

Dang ChatGPT you state the end of the sun and Earth like it's no big deal!



This assumes you store seconds since the epoch started.

On a Mac, "as a non-portable extension, the clock_gettime_nsec_np() function will return the clock value in 64-bit nanoseconds":

    uint64_t clock_gettime_nsec_np(clockid_t clock_id);
I believe it combines the two parameters from structure

    struct timespec {
        time_t  tv_sec;     /* seconds */
        long    tv_nsec;    /* and nanoseconds */
    };
to give the number of nanoseconds since 1 January 1970.

  >>> import datetime
  >>> datetime.datetime(1970, 1, 1, 0, 0, 0) + \
  ...    datetime.timedelta(microseconds=(2**64-1) / 1000)
  datetime.datetime(2554, 7, 21, 23, 34, 33, 709552)
That's only a bit over five centuries away.

Also, there appears to be a problem with the stated calculation. I get:

  >>> (2**63-1 ) / 60 / 60 / 24 / 365.25
  292271023045.3132
292,271,023,045 years is slightly shorter than the 292,277,026,596 years you quoted.

Using the more precise 1 year = 365.2425 days that lanna pointed out gives 292,277,024,626 years, still not what ChatGPT gave.

ChatGPT's result implies 1 year = 365.2424975393588 days.


A year in the Gregorian calendar is 365.2425 days




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: