[Python-Dev] Issue5434: datetime.monthdelta
jess.austin at gmail.com
Thu Apr 16 23:41:19 CEST 2009
Jon Ribbens <jon+python-dev at unequivocal.co.uk> wrote:
> On Thu, Apr 16, 2009 at 12:10:36PM +0400, Oleg Broytmann wrote:
>> > This patch adds a "monthdelta" class and a "monthmod" function to the
>> > datetime module. The monthdelta class is much like the existing
>> > timedelta class, except that it represents months offset from a date,
>> > rather than an exact period offset from a date.
>> I'd rather see the code merged with timedelta: timedelta(months=n).
> Unfortunately, that's simply impossible. A timedelta is a fixed number
> of seconds, and the time between one month and the next varies.
> I am very much in favour of there being the ability to add months to
> dates though. Obviously there is the question of what to do when you
> move forward 1 month from the 31st January; in my opinion an optional
> argument to specify different behaviours would be nice.
Others have suggested raising an exception when a month calculation
lands on an invalid date. Python already has that; it's spelled like
>>> dt = date(2008, 1, 31)
>>> dt.replace(month=dt.month + 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: day is out of range for month
What other behavior options besides "last-valid-day-of-the-month"
would you like to see?
More information about the Python-Dev