[Python-Dev] datetime module enhancements (original) (raw)

Georg Brandl g.brandl at gmx.net
Sat Mar 10 00:14:03 CET 2007


Robert Brewer schrieb:

Brett Cannon wrote:

On 3/9/07, Collin Winter <collinw at gmail.com> wrote: > On the subject of datetime enhancements, I came across an SF patch > (#1673403) the other day that proposed making it possible to compare > date and datetime objects...

I personally like the current solution. The proposal to just assume midnight goes against EIBTI in my mind. Yeah, but the current solution goes against, um, APBP*. Not in my mind, but in my code. Repeatedly. I can't count how many times I've written code like: if created > fdate: when I "should" have written: if isinstance(created, datetime.date): dateversionofcreated = created else: dateversionofcreated = created.date() if dateversionofcreated > fdate: But it gets better, because: >>> isinstance(datetime.datetime(x, y, z), datetime.date) True So the above won't work, you must remember to reverse the if/else: if isinstance(created, datetime.datetime): dateversionofcreated = created.date() else: dateversionofcreated = created if dateversionofcreated > fdate:

Why not just give date objects a date() method that returns self? That way you can write

if created.date() > fdate:

Georg



More information about the Python-Dev mailing list