[Python-Dev] Issue5434: datetime.monthdelta

skip at pobox.com skip at pobox.com
Fri Apr 17 02:18:35 CEST 2009


    >> I have this funny feeling that arithmetic using monthdelta wouldn't
    >> always be intuitive.

    Jess> I think that's true, especially since these calculations are not
    Jess> necessarily invertible:

    >>> date(2008, 1, 30) + monthdelta(1)
    datetime.date(2008, 2, 29)
    >>> date(2008, 2, 29) - monthdelta(1)
    datetime.date(2008, 1, 29)

    Jess> It could be that non-intuitivity is inherent in the problem of
    Jess> dealing with dates and months.

To which I would respond:

    >>> import this
    The Zen of Python, by Tim Peters

    ...
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    ...

>From the discussion I've seen so far, it's not clear that there is one
obvious way to do it, and the ambiguity of the problem forces people to
guess.  

My recommendations after letting it roll around in the back of my brain for
the day:

    * I think it would be best to leave the definition of monthdelta up to
      individual users.  That is, add nothing to the datetime module and let
      them write a function which does what they want it to do.

    * The idea/implementation probably needs to bake on the python-ideas
      list and perhaps comp.lang.python for a bit to see if some concensus
      can be reached on reasonable functionality.

(I'm a bit behind on this thread.  Hopefully someone else has already
suggested these two things.)

Skip


More information about the Python-Dev mailing list