[Python-Dev] Re: dateutil (original) (raw)

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Mar 16 19:12:44 EST 2004


Michael Chermside <mcherm at mcherm.com>:

+0.6 I do not feel as strongly as Greg does that use of + implies an alegbra (because it's glaringly obvious to me that the whole POINT of this library is to deal with the fact that date manipulations do NOT follow any sane algebra).

I wouldn't insist that all uses of '+' be strictly algebraic, but what we're talking about here is so far from it that I have trouble thinking of it as any kind of addition operation.

Perhaps individual transform objects which do just one thing at a time but can be combined into a single object which applies them in series:

>>> firstCombo = relativeDateDelta([nextMonth, prevDay]) >>> secondCombo = relativeDateDelta([prevDay, nextMonth]) >>> # or, alternative syntax: >>> firstCombo = nextMonth.andThen(prevDay)

I can't really see the advantage of having a special kind of object for this. We already have objects that represent operations in Python -- they're called functions! And it's easy to create one that combines others:

def thursday_next_month(d): return thursday_of(next_month(d))

Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg at cosc.canterbury.ac.nz +--------------------------------------+



More information about the Python-Dev mailing list