[Python-Dev] Negative timedelta strings

M.-A. Lemburg mal at egenix.com
Wed Apr 2 14:52:01 CEST 2014


n 31.03.2014 21:09, Chris Barker wrote:
> On Fri, Mar 28, 2014 at 2:52 PM, Fred Drake <fred at fdrake.net> wrote:
> 
>> On Fri, Mar 28, 2014 at 5:19 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
>> wrote:
>>> ISO 8601 doesn't seem to define a representation for
>>> negative durations, though, so it wouldn't solve the
>>> original problem.
>>
>> Aside from the horribleness of the ISO 8601 notation for a duration, it's
>> best not to confuse the notions of duration and delta.  Notionally, a delta
>> contains more information than a duration.
> 
> 
> and less -- really it's different.
> 
> A duration would be really useful actually, for things like "next month",
> etc,. IIRC, mxDateTime has something for this, but it's NOT the same as a
> timedelta.

mxDateTime has DateTimeDelta objects which represent a time delta
(in the mathematical sense) between two points in DateTime and
RelativeDateTime objects which allow defining deltas in terms
of qualifiers which are applied to the left hand side of an operation.

With RelativeDateTime you can do things like e.g.

first_of_next_month = now() + RelativeDateTime(months=+1, day=1)

There are some other concepts you can emulate with these, like e.g.
a specific time frame (DateTime + one of the above deltas), a
reoccurring time (start_time + one of the deltas + number
occurrences + exceptions), an age concept (difference between two
DateTime values expressed in RelativeDateTime terms), etc.

Some examples:

>>> from mx.DateTime import *

>>> print RelativeDateTime(months=+1, day=1)
YYYY-(+01)-01 HH:MM:SS

>>> print now() + RelativeDateTime(months=+1, day=1)
2014-05-01 14:49:05.83

>>> print Age(now(), Date(1969,4,6))
(+0044)-(+11)-(+27) (+14):(+49):(+02)

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