[Python-Dev] Negative timedelta strings

M.-A. Lemburg mal at egenix.com
Wed Apr 2 15:18:23 CEST 2014


On 02.04.2014 15:04, Skip Montanaro 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?

I'm not really satisfied with this solution either.

The problem is that the qualifier "+ 1 month" is not defined for
dates with don't have a corresponding day in the following month.

This should probably either raise an exception or use some
parameter to "solve" the problem, by e.g. choosing the last day
of the month or using the current scheme:

mxDateTime skips to the first of the next month and then advances
the number of days defined in the left hand DateTime value,
i.e. Date(2014, 2, 1) + 30 * oneDay.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Apr 02 2014)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2014-04-09: PyCon 2014, Montreal, Canada ...                7 days to go
2014-04-29: Python Meeting Duesseldorf ...                 27 days to go

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-Dev mailing list