diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/poi/ss/usermodel/DateUtil.java | 2 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java | 24 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/java/org/apache/poi/ss/usermodel/DateUtil.java b/src/java/org/apache/poi/ss/usermodel/DateUtil.java index 79512ef102..31dbce424d 100644 --- a/src/java/org/apache/poi/ss/usermodel/DateUtil.java +++ b/src/java/org/apache/poi/ss/usermodel/DateUtil.java @@ -567,7 +567,7 @@ public class DateUtil { 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"); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java index f5ea7a1ccc..2e34d6f602 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java @@ -17,9 +17,7 @@ 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; @@ -349,6 +347,7 @@ public final class TestHSSFDateUtil { HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls"); HSSFSheet sheet = workbook.getSheetAt(0); InternalWorkbook wb = workbook.getWorkbook(); + assertNotNull(wb); HSSFRow row; HSSFCell cell; @@ -482,6 +481,25 @@ public final class TestHSSFDateUtil { } @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() { final double delta = 1E-7; // a couple of digits more accuracy than strictly required |