SerialDate.addMonths

A discussion forum for the JCommon class library.
Post Reply
wildepete
Posts: 3
Joined: Tue May 27, 2003 4:31 pm
Location: NYC
Contact:

SerialDate.addMonths

Post by 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.

Thanks,
Peter

david.gilbert
JFreeChart Project Leader
Posts: 11666
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by 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.

Regards,

Dave Gilbert

Post Reply