What is the point of the DateTime class?

date, datetime, ruby, ruby-on-rails, time

Solution

`DateTime` had an advantage over `Time` on 32 bit machines in Rubies < 1.9.2 - `Time` was a victim of the Y2K38 problem and limited to a 32 bit range. This problem is solved either on 64 bit machines and/or in recent Ruby versions. You still may need to use `DateTime` if for example 1.8 compatibility is a must or you rely on using methods from its API which often deviates from that of `Time`.

Problem

The `DateTime` class seems redundant, and after reading this bit in the documentation for the Rails extension of the class, it also seems potentially dangerous: DateTimes aren’t aware of DST rules, so use a consistent non-DST offset when creating a DateTime with an offset in the local zone There's also this, in the Rails documentation for `DateTime#to_time`: Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class. If self has an offset other than 0, self will just be returned unaltered, since there’s no clean way to map it to a Time. I assume that last part is due to `DateTime` not recognizing DST. It seems to me we have this: - The `Date` class represents a simple date without a time. - The `Time` class represents a specific point in time, which implicitly includes the date. - The `DateTime` class is the same as the `Time` class, but doesn't understand DST and sometimes can't convert to a regular `Time` class. So should `DateTime` just be banished from the code base or does it serve a useful purpose which I am missing?

Original source