On Thu, Apr 16, 2009 at 3:45 AM, <s...@pobox.com> wrote: > >>> date(2008, 1, 30) + monthdelta(1) > datetime.date(2008, 2, 29) > > What would this loop would print? > > for d in range(1, 32): > print date(2008, 1, d) + monthdelta(1)
>>> for d in range(1, 32): ... print(date(2008, 1, d) + monthdelta(1)) ... 2008-02-01 2008-02-02 2008-02-03 2008-02-04 2008-02-05 2008-02-06 2008-02-07 2008-02-08 2008-02-09 2008-02-10 2008-02-11 2008-02-12 2008-02-13 2008-02-14 2008-02-15 2008-02-16 2008-02-17 2008-02-18 2008-02-19 2008-02-20 2008-02-21 2008-02-22 2008-02-23 2008-02-24 2008-02-25 2008-02-26 2008-02-27 2008-02-28 2008-02-29 2008-02-29 2008-02-29 > I have this funny feeling that arithmetic using monthdelta wouldn't always > be intuitive. I think that's true, especially since these calculations are not necessarily invertible: >>> date(2008, 1, 30) + monthdelta(1) datetime.date(2008, 2, 29) >>> date(2008, 2, 29) - monthdelta(1) datetime.date(2008, 1, 29) It could be that non-intuitivity is inherent in the problem of dealing with dates and months. I've aimed for a good compromise between the needs of the problem and the pythonic example of timedelta. I would submit that timedelta itself isn't intuitive at first blush, especially if one was weaned on the arcana of RDBMS date functions, but after one uses timedelta for just a bit it makes total sense. I hope the same may be said of monthdelta. cheers, Jess _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com