mirror of https://github.com/apache/poi.git
Apply fix reported in bug 47661 and add unit tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1680642 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5209d15d1c
commit
f3872cbcf4
|
@ -567,7 +567,7 @@ public class DateUtil {
|
||||||
|
|
||||||
private static int daysInPriorYears(int yr, boolean use1904windowing)
|
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");
|
throw new IllegalArgumentException("'year' must be 1900 or greater");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -349,6 +347,7 @@ public final class TestHSSFDateUtil {
|
||||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls");
|
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls");
|
||||||
HSSFSheet sheet = workbook.getSheetAt(0);
|
HSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
InternalWorkbook wb = workbook.getWorkbook();
|
InternalWorkbook wb = workbook.getWorkbook();
|
||||||
|
assertNotNull(wb);
|
||||||
|
|
||||||
HSSFRow row;
|
HSSFRow row;
|
||||||
HSSFCell cell;
|
HSSFCell cell;
|
||||||
|
@ -481,6 +480,25 @@ public final class TestHSSFDateUtil {
|
||||||
assertEquals("Checking absolute day (1 Jan 1901)", 366, HSSFDateUtil.absoluteDay(calendar, false));
|
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
|
@Test
|
||||||
public void convertTime() {
|
public void convertTime() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue