Page 1 of 1

SerialDate.addMonths

Posted: Tue May 27, 2003 4:36 pm
by wildepete
:?

I am getting an "invalid month" exception when I try to add 2 months to a date in October. Upon investigation it looks like there is a problem with the calculation of the months in SerialDate.addMonths:

int mm = (12 * base.getYYYY() + base.getMonth() + months) % 12;

returns 0 for December when it should return 12

I would suggest the following change. instead of (x%12) the formula should read ((x-1) % 12) + 1

This way december will return 12 and not zero.

Thanks,
Peter

Posted: Thu May 29, 2003 10:46 am
by david.gilbert
Thanks for the report. I've fixed the bug and added a couple of JUnit tests to make sure it stays fixed.

Regards,

Dave Gilbert