[Python-Dev] Negative timedelta strings

Xavier Morel python-dev at masklinn.net
Wed Apr 2 15:12:14 CEST 2014


On 2014-04-02, at 15:04 , Skip Montanaro <skip at pobox.com> wrote:

> 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?

FWIW dateutil has a slightly different logic there:

>>> date(2014, 2, 28) + relativedelta(months=+1)
datetime.date(2014, 3, 28)
>>> date(2014, 1, 31) + relativedelta(months=+1)
datetime.date(2014, 2, 28)



More information about the Python-Dev mailing list