[Python-Dev] datetime module enhancements

Jon Ribbens jon+python-dev at unequivocal.co.uk
Sat Mar 10 19:10:57 CET 2007

Steven Bethard <steven.bethard at gmail.com> wrote:
> I don't see why the docs can't be explicit about what subtraction
> means given that there are a number of possible interpretations.

I don't see why the docs can't be explicit about what comparison
means given that there are a number of possible interpretations.

> You can draw the analogy here with integer addition::
>
>     >>> int(1) + int(.75)
>     1
>     >>> int(1) + int(1.25)
>     2

You're making my point for me. An integer (in the abstract sense)
*is* the same as a float with a zero fractional part. You're agreeing
that datetime treats dates as datetimes with a midnight time part.

> However, assuming that a date() is a datetime() with a time of
> midnight will clearly break that logic.

Could you please explain how? It doesn't look to me like it breaks
anything. I think you're assuming that "date" means "the whole of
that day" - if so then why do you think that assumption is valid?

Using your suggested analogy above, if you consider "date"s to be
"ints" and "datetime"s to be "floats", then it seems to be that
everything makes sense and is logical and coherent.

> I still don't see why my more careful comparison would be bad for any
> of your code. Could you give an example where it would be bad for all
> the following to be False::
>      date(2006, 1, 1) < datetime(2006, 1, 1, 0, 0, 0)
>      date(2006, 1, 1) > datetime(2006, 1, 1, 0, 0, 0)
>      date(2006, 1, 1) == datetime(2006, 1, 1, 0, 0, 0)

You need me to explain why "a < b", "a > b" and "a == b" all being
false simultaneously is bad!? What would "a != b" return? What would
"cmp(a, b)" return?

> even though the following would be True::
>      date(2006, 1, 1) < datetime(2006, 1, 2, 0, 0, 0)
>      date(2006, 1, 1) > datetime(2005, 12, 31, 0, 0, 0)

Actually, your suggestion would be much better than the current
behaviour, for my uses, even though it's totally illogical.