[Python-Dev] Negative timedelta strings

Skip Montanaro skip at pobox.com
Wed Apr 2 15:04:51 CEST 2014


On Wed, Apr 2, 2014 at 7:52 AM, M.-A. Lemburg <mal at egenix.com> wrote:
> >>> print now() + RelativeDateTime(months=+1, day=1)
> 2014-05-01 14:49:05.83

I find this sort date arithmetic unintuitive, though I'm at a loss to
come up with better logic than you have:

>>> d = Date(2014, 2, 28)
>>> d + RelativeDateTime(months=+1)
<mx.DateTime.DateTime object for '2014-03-28 00:00:00.00' at 1eda8c8>
>>> d = Date(2014, 1, 31)
>>> d + RelativeDateTime(months=+1)
<mx.DateTime.DateTime object for '2014-03-03 00:00:00.00' at 1eda870>

I guess the assumption is that one month is the length in days of the
current month, though, you wind up with situations where shorter
months can be skipped altogether. Is there a way to talk in terms of
"months" but not have short months get skipped?

Thx,

Skip


More information about the Python-Dev mailing list