[Python-Dev] Issue5434: datetime.monthdelta

James Y Knight foom at fuhm.net
Fri Apr 17 01:11:51 CEST 2009


On Apr 16, 2009, at 5:47 PM, Antoine Pitrou wrote:
> IMHO, the question is rather what the use case is for the behaviour  
> you are
> proposing. In which kind of situation is it acceptable to turn 31/2  
> silently
> into 29/2?

Essentially any situation in which you'd actually want a "next month"  
operation it's acceptable to do that.

It's a human-interface operation, and as such, everyone (ahem) "knows  
what it means" to say "2 months from now", but the details don't  
usually have to be thought about too much. Of course when you have a  
computer program, you actually need to tell it what you really mean.

I do a fair amount of date calculating, and use two different kinds of  
"add-month":

Option 1)
Add n to the month number, truncate day number to fit the month you  
end up in.

Option 2)
As above, but with the additional caveat that if the original date is  
the last day of its month, the new day should also be the last day of  
the new month. That is:
April 30th + 1 month = May 31st, instead of May 30th.

They're both useful behaviors, in different circumstances.

James


More information about the Python-Dev mailing list