Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #165 update/fix #257

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
49 changes: 20 additions & 29 deletions src/main/java/org/jfree/chart/date/SpreadsheetDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@
*/
package org.jfree.chart.date;

import java.time.Month;
import java.time.DayOfWeek;
import java.util.Calendar;
import java.util.Date;
import java.time.LocalDate;
import java.time.DateTimeException;

/**
* Represents a date using an integer, in a similar fashion to the
* implementation in Microsoft Excel. The range of dates supported is
* 1-Jan-1900 to 31-Dec-9999.
* implementation in Microsoft Excel.
* <P>
* Be aware that there is a deliberate bug in Excel that recognises the year
* 1900 as a leap year when in fact it is not a leap year. You can find more
Expand Down Expand Up @@ -73,7 +76,7 @@ public class SpreadsheetDate extends SerialDate {
/** The month of the year (1 to 12). */
private final int month;

/** The year (1900 to 9999). */
/** The year */
private final int year;

/**
Expand All @@ -84,32 +87,20 @@ public class SpreadsheetDate extends SerialDate {
* @param year the year (in the range 1900 to 9999).
*/
public SpreadsheetDate(int day, int month, int year) {

if ((year >= 1900) && (year <= 9999)) {
this.year = year;
}
else {
throw new IllegalArgumentException(
"The 'year' argument must be in range 1900 to 9999.");
}

if ((month >= MonthConstants.JANUARY)
&& (month <= MonthConstants.DECEMBER)) {
this.month = month;
}
else {
throw new IllegalArgumentException(
"The 'month' argument must be in the range 1 to 12.");
}

if ((day >= 1) && (day <= SerialDate.lastDayOfMonth(month, year))) {
this.day = day;
} else {
throw new IllegalArgumentException("Invalid 'day' argument.");
}

// the serial number needs to be synchronised with the day-month-year...
this.serial = calcSerial(day, month, year);
try {
LocalDate.of(year, month, day);

this.day = day;
this.month = month;
this.year = year;
this.serial = calcSerial(day, month, year);
}
catch (DateTimeException a) {
throw new IllegalArgumentException(
"The date is invalid!");
}


}

/**
Expand Down