The end of the world is nigh

January 29, 2008

According to Ruby, the world ends -- or at least gets seriously reshuffled -- on Tuesday the 19th of January 2038, at 7 seconds past 3:14 AM UTC. ```ruby >> Time.utc(2038, 1, 19, 3, 14, 7, 999999) => Tue Jan 19 03:14:07 UTC 2038 >> Time.utc(2038, 1, 19, 3, 14, 7, 999999).succ => Fri Dec 13 20:45:52 UTC 1901 ``` One second after that moment, and we're back in 1901. Surprise! This is the classic [Year 2038 problem](https://en.wikipedia.org/wiki/Year_2038_problem) -- time is stored as a signed 32-bit integer counting seconds from the Unix epoch, and that integer overflows right at this boundary. What's a bit surprising is that Ruby doesn't handle this more gracefully. A `Fixnum` automatically promotes to a `Bignum` when it exceeds `2**30`, so you might expect `Time` to pull off a similar trick internally. But it doesn't -- at least not in the Ruby versions of this era. The internal representation just wraps around, catapulting you back to the early 20th century without so much as a warning. Something to keep in mind if you're ever working with dates far into the future.
Questions or thoughts? Get in touch.