|
Boost : |
From: Robert Bell (belvis_at_[hidden])
Date: 2004-04-13 20:30:46
Powell, Gary wrote:
>>Bob Bell wrote:
>>The interpretation that makes sense to me is: adding one month means the
>>same day of the next month, unless the date's not valid, in which case I
>>expect moving backwards to the latest date of said month. That's what
>>humans do when you say "next month", so I would think anything else
>>would be surprising.
>
>
> That would surprise me as well.
>
> date = January 30;
>
> add_month(date);
> add_month(date);
>
> date == March 30 ? Not March 28/29 No?
>
> Which means of course a lot of state has to be held by date, because otherwise February does rounding. As in the number of days until the end of the month.
I don't have a problem with your example because it shows two discrete
operations. I don't expect the date to remember its history and apply
future operations based on that history, which is what you'd need in
order to end up with March 30. Otherwise, the date's behavior becomes
very hard to predict, not to mention implement.
I just wouldn't use the two discrete add_months in your example _unless_
I wanted the behavior you see as surprising. Otherwise, I'd use
add_month(date, 2);
Bob
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk