private static int daysInPriorYears(int yr, boolean use1904windowing)
{
- if ((!use1904windowing && yr < 1900) || (use1904windowing && yr < 1900)) {
+ if ((!use1904windowing && yr < 1900) || (use1904windowing && yr < 1904)) {
throw new IllegalArgumentException("'year' must be 1900 or greater");
}
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.io.IOException;
import java.text.ParseException;
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls");
HSSFSheet sheet = workbook.getSheetAt(0);
InternalWorkbook wb = workbook.getWorkbook();
+ assertNotNull(wb);
HSSFRow row;
HSSFCell cell;
assertEquals("Checking absolute day (1 Jan 1901)", 366, HSSFDateUtil.absoluteDay(calendar, false));
}
+ @Test
+ public void absoluteDayYearTooLow() {
+ GregorianCalendar calendar = new GregorianCalendar(1899, 0, 1);
+ try {
+ HSSFDateUtil.absoluteDay(calendar, false);
+ fail("Should fail here");
+ } catch (IllegalArgumentException e) {
+ // expected here
+ }
+
+ try {
+ calendar = new GregorianCalendar(1903, 0, 1);
+ HSSFDateUtil.absoluteDay(calendar, true);
+ fail("Should fail here");
+ } catch (IllegalArgumentException e) {
+ // expected here
+ }
+ }
+
@Test
public void convertTime() {