On 2009-04-16 13:42, Paul Moore wrote:
2009/4/16 Ned Deily<n...@acm.org>:
In article
<b8ad139e0904152318p5473cbe5yb5f55a19894cc...@mail.gmail.com>,
  Jess Austin<jess.aus...@gmail.com>  wrote:
I'm new to python core development, and I've been advised to write to
python-dev concerning a feature/patch I've placed at
http://bugs.python.org/issue5434, with Rietveld at
http://codereview.appspot.com/25079.
Without having looked at the code, I wonder whether you've looked at
python-dateutil.   I believe its relativedelta type does what you
propose, plus much more, and it has the advantage of being widely used
and tested.

The key thing missing (I believe) from dateutil is any equivalent of monthmod.

Hmm, it might be possible via relativedelta(d1,d2), but it's not clear
to me from the documentation precisely what attributes/methods of a
relativedelta object are valid for getting data *out* of it.

I thought the examples were quite clear. relativedelta() has an alternate constructor precisely suited to these calculations but is general and handles more than just months.

>>> from dateutil.relativedelta import *
>>> dt = relativedelta(months=1)
>>> dt
relativedelta(months=+1)
>>> from datetime import datetime
>>> datetime(2009, 1, 15) + dt
datetime.datetime(2009, 2, 15, 0, 0)
>>> datetime(2009, 1, 31) + dt
datetime.datetime(2009, 2, 28, 0, 0)
>>> dt.months
1
>>> datetime(2009, 1, 31) + relativedelta(years=-1)
datetime.datetime(2008, 1, 31, 0, 0)

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to