comparing datetime with date
Donnal Walter
donnal at donnal.net
Wed Sep 15 10:00:13 EDT 2004
Steve Holden wrote:
> Comparing a datetime and a time makes little sense to me, and I'd prefer
> to be forced to extract the time explicitly from the datetime before
> comparison. A time specifies a point during *any* day, a datetime
> specifies a single point in the time continuum.
Perhaps I am guilty of not explaining what I was trying to do. I have an
abstract class (called Cell) that implements a form of the observable
pattern. When x.set(...) is called, it check to see if the new value is
different from the old value before making the change and notifying
observers. The abstract Cell class has a lot of other functionality, as
well, but this is the critical feature. Then I have at least three
subclasses: one for text (strings), one for numbers, and one for
timepoints. Althought the internal value representation is different for
all three, they all use the same basic set(...) method. In my first
implementation, the internal representation for TimePoint was going to
be a datetime.datetime object. Sometimes, however, one knows a date
without knowing the time (date of birth, for example, before knowing the
time of birth, and this is important in newborn intensive care). I
wanted to be able to enter the date of birth in a way that indicates
that the time is unknown at present, so I used a datetime.date. Then
later after the actual time is learned, it could be changed to a
datetime.datetime. How else would the associated presenter (presentation
object) know whether or not the time was unknown? But this means that
for my implementation dt.date should not evaluate as equal to the
corresponding dt.datetime.
My solution now (as a result of this thread) is to use a three-tuple for
date of birth and a five-tuple for date and time of birth. These two
representations obviously do evaluate as different. I still convert to
datetime.datetime (with or without DST information) for calculations of
intervals, but storage is the basic time tuple.
Kind regards,
Donnal Walter
Arkansas Children's Hospital
More information about the Python-list
mailing list