Bug
Posted: Thu May 07, 2009 10:01 am
I think I've found a pretty major bug in the 'private int calcSerial(final int d, final int m, final int y)' function of the SpreadsheetDate class in the jcommon library.
if (m > MonthConstants.FEBRUARY) {
should be replaced with either:
if (m >= MonthConstants.FEBRUARY) {
or
if (m > 1) {
Maybe something like this:
public static int calcSerial(final int d, final int m, final int y)
{
final int yy = ((y - 1900) * 365) + SerialDate.leapYearCount(y - 1);
int mm = AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH[m];
if (m > 1 && SerialDate.isLeapYear(y))
return yy + mm + d + 2;
return yy + mm + d + 1;
}
Cheers, Bob
if (m > MonthConstants.FEBRUARY) {
should be replaced with either:
if (m >= MonthConstants.FEBRUARY) {
or
if (m > 1) {
Maybe something like this:
public static int calcSerial(final int d, final int m, final int y)
{
final int yy = ((y - 1900) * 365) + SerialDate.leapYearCount(y - 1);
int mm = AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH[m];
if (m > 1 && SerialDate.isLeapYear(y))
return yy + mm + d + 2;
return yy + mm + d + 1;
}
Cheers, Bob