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.
Written by Adam Stankiewicz
Related protips
1 Response
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#