Read more

Maximum representable value for a Ruby Time object

Henning Koch
February 22, 2011Software engineer at makandra GmbH

On 32bit systems, the maximum representable Time Show archive.org snapshot is 2038-01-19 03:14:07 in UTC or 2038-01-19 04:14:07 in CET. If you try to instantiate a Time with any later value, Ruby will raise an ArgumentError.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

If you need to represent later time values, use the DateTime Show archive.org snapshot class. This is also what Rails does when it loads a record from the database that has a DATETIME value which Time cannot represent. Note that there are some subtle differences Show archive.org snapshot between the APIs of Time and DateTime. Also DateTime is implemented in Ruby, while Time is implemented in C, making Time much more performant. So don't always use DateTime because it's more awesome all of the time, because it is not.

Our favorite time travel gem Timecop Show archive.org snapshot works with both Time and DateTime.

Posted by Henning Koch to makandra dev (2011-02-22 17:53)