As we are not calling a "set" operation but an "addMonthsToDate" operation and as a result we find this behavior surprising - and a little non-intuitive.
Calendar does not "skip" a month when using "add" month, the days are adjusted to the end of the next month to prevent month "skipping".
It does behave as described with a month "skip" if using "set" month instead.
See also: http://stackoverflow.com/a/14618664/1341731
git tells me CalendarUtil.java is the same in 2.7 and 2.8RC2. So yes, the code should behave the same.But the above behaviour is not wrong because it's standard Java behaviour.
Whether you use Date.setMonth(n) or Calendar.set(Calendar.MONTH, n) Java behaves the same way. That is, if you start on August 31, and set the month to September, then you find you are on October 1.
On Thu, Sep 1, 2016 at 10:01 AM, Daniel Kurka <kurka.daniel@gmail.com> wrote:
Does this code do the same thing in 2.7?
On Wed, Aug 31, 2016 at 11:41 PM Paul Robinson <ukcueman@gmail.com> wrote:
You don't say what part of this you think is a bug. I presume it's the fact that Aug 31 plus one month is Oct 1. If so, this is not a bug.
Adding one month should do literally that, so you get September 31. But there are only 30 days in September, so this automatically becomes October 1.
Paul
No comments:
Post a Comment