comparing datetime with date

Gerrit gerrit at nl.linux.org
Wed Sep 15 07:55:26 CEST 2004


Andrew Durdin wrote:
> On Tue, 14 Sep 2004 17:16:58 -0400, Tim Peters <tim.peters at gmail.com> wrote:
> > [Donnal Walter]
> > > >>> x = datetime.date(2004, 9, 14)
> > > >>> y = datetime.datetime(2004, 9, 14, 6, 43, 15)
> > > >>> print x == y
> > > True
> > >
> > > How can these two objects be considered equal?
> > 
> > They should not be.  Please open a bug report.  The problem is due to that
> > datetime.datetime is a subclass of datetime.date:
> 
> Why should this be considered a bug? In my conception, a datetime.date
> covers the whole range of times within the date, so that this equality
> makes sense. It also allows for intuitive inequality comparisons
> between datetime.datetime and datetime.date.

Then, __contains__ would IMHO be the correct way to go:

>>> datetime.datetime(2004, 9, 14, 6, 43, 15) in datetime.date(2004, 9, 14)
True

regards,
Gerrit.

-- 
Weather in Twenthe, Netherlands 15/09 07:25:
	12.0°C Few clouds mostly clear wind 5.4 m/s SSW (57 m above NAP)
-- 
Gerrit Holl - 2nd year student of Applied Physics, Twente University, NL.
Experiences with Asperger's Syndrome:
	EN http://topjaklont.student.utwente.nl/english/
	NL http://topjaklont.student.utwente.nl/



More information about the Python-list mailing list