I’ve been using ruby for years, but I’ve never had a good use for
DateTime. Since there’s so much discussion about it recently, maybe I
could ask again, why does it exist?
If it’s really meant to be a Date plus fractional values for the time of
day, then I think it should ignore time zones and utc offset completely
because it’s ambiguous. Date does not have a zone: only when you compare
times should you compare zones.
It ignores tzinfo, so moving over daylight savings time doesn’t
change the offset:
I’m not sure what to think of the “%s %z” patch for DateTime.strptime
since I never use it. It makes sense that it should be consistent with
Time, but maybe DateTime itself is wrong-headed to begin with?
Time is a wrapper around Unix-Epoch.
Date (and DateTime) use rational and a “day zero” for storage. So Time
is faster but the upper and lower bounds are tied to epoch time (which
for 32bit epoch times is something around 1970-2040 - not even enough to
represent the birthday of my parents) while Date (and DateTime) have an
almost infinite range but are terribly slow
The pickaxe Ruby says:
The date library implements classes Date and DateTime, which provide a
comprehensive set of facilities for storing, manipulating, and
converting dates
with or without time components. The classes can represent and
manipulate civil,
ordinal, commercial, Julian, and standard dates, starting January 1,
4713 BCE. The
DateTime class extends Date with hours, minutes, seconds, and fractional
seconds,
and it provides some support for time zones. The classes also provide
support for
parsing and formatting date and datetime strings.
It appears this date/datetime code was written by Tadayoshi F.
1998-present and documented by William W.
I didn’t see any benchmarks in trunk about speed increases, but I didn’t
look very carefully.
-Benjamin
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.