mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

M.-A. Lemburg mal at egenix.com
Mon Oct 12 20:00:09 CEST 2009


Tim Chase wrote:
>> Month arithmetic is a bit of a mess, since it's not clear how
>> to map e.g. Jan 31 + one month.
> 
> "Jan 31 + one month" usually means "add one to the month value and then
> keep backing off the day if you get an exception making the date", so
> you'd get Feb 31, exception, Feb 30, exception, Feb 29, possibly an
> exception, and possibly/finally Feb 28th.  This makes pretty intuitive
> sense to most folks and is usually what's meant.

Well, yes, but that's just one way to solve the problem. I guess
I'll just add all possible solutions and then let the user decide
what's best in some way.

> I've found that issues and confusion stem more from the non-commutative
> reality that "Jan 31 + (1 month) + (-1 month) != Jan 31 + (-1 month) +
> (1 month)" or the non-associative "Jan 31 + (1 month + 1 month) != (Jan
> 31 + 1 month) + 1 month" :-/

That's why mxDateTime actually returning a day in March...

>>> mx.DateTime.DateTime(2009, 1, 31) + mx.DateTime.RelativeDateTime(months=+1)
<mx.DateTime.DateTime object for '2009-03-03 00:00:00.00' at 2ba43f93ebe0>

That's intuitive for mathematicians only, though ;-)

> So yes, messy it is!

Indeed.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 12 2009)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new 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-list mailing list