r35b-g
Last Updated: February 25, 2016
·
663
· sheerun
Photo on 08.01.2013 at 04.15

Prefer DateTime over Time

The reason is: Time is POSIX-standard time, i.e. number of seconds since January 1, 1970. Although it contains concrete date, it does not support dates before 1970 and after Jan 18, 2038.

On other hand DateTime can easily represent 4,712 BCE as well as 21,000 years in the future. So it should be preferred if you don't want your application to break in edge cases.

1 Response
Add your response

224
546cb399441344941ff1052fae9563b4

Are you sure? Ruby 1.9.3 represents a Time as 64 bit wide timestamp. Some experiments yielded:

pry(main)> Time.mktime(-4371,1,1)
=> -4371-01-01 00:00:00 +0053
pry(main)> Time.mktime(23012,1,1)
=> 23012-01-01 00:00:00 +0100

over 1 year ago ·