A discussion forum for the JCommon class library.


Postby wildepete » Tue May 27, 2003 4:36 pm


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.

Posts: 3
Joined: Tue May 27, 2003 4:31 pm
Location: NYC

Postby david.gilbert » Thu May 29, 2003 10:46 am

Thanks for the report. I've fixed the bug and added a couple of JUnit tests to make sure it stays fixed.


Dave Gilbert
JFreeChart Project Leader
Posts: 11664
Joined: Fri Mar 14, 2003 10:29 am

Return to JCommon

Who is online

Users browsing this forum: No registered users and 3 guests