PR:15037 - Unit Tests for 1904 date windowing; submitted by Dan Sherman
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d4aab6f574
commit
737b732f1a
BIN
src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls
Normal file
Binary file not shown.
BIN
src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls
Normal file
Binary file not shown.
@ -77,6 +77,7 @@ import java.util.GregorianCalendar;
|
||||
* Tests various functionity having to do with HSSFCell. For instance support for
|
||||
* paticular datatypes, etc.
|
||||
* @author Andrew C. Oliver (andy at superlinksoftware dot com)
|
||||
* @author Dan Sherman (dsherman at isisph.com)
|
||||
*/
|
||||
|
||||
public class TestHSSFCell
|
||||
@ -139,6 +140,43 @@ extends TestCase {
|
||||
in.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the recognition of files using 1904 date windowing
|
||||
* is working properly. Conversion of the date is also an issue,
|
||||
* but there's a separate unit test for that.
|
||||
*/
|
||||
public void testDateWindowing() throws Exception {
|
||||
GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
|
||||
Date date = cal.getTime();
|
||||
String path = System.getProperty("HSSF.testdata.path");
|
||||
|
||||
// first check a file with 1900 Date Windowing
|
||||
String filename = path + "/1900DateWindowing.xls";
|
||||
FileInputStream stream = new FileInputStream(filename);
|
||||
POIFSFileSystem fs = new POIFSFileSystem(stream);
|
||||
HSSFWorkbook workbook = new HSSFWorkbook(fs);
|
||||
HSSFSheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
assertEquals("Date from file using 1900 Date Windowing",
|
||||
date.getTime(),
|
||||
sheet.getRow(0).getCell((short)0)
|
||||
.getDateCellValue().getTime());
|
||||
stream.close();
|
||||
|
||||
// now check a file with 1904 Date Windowing
|
||||
filename = path + "/1904DateWindowing.xls";
|
||||
stream = new FileInputStream(filename);
|
||||
fs = new POIFSFileSystem(stream);
|
||||
workbook = new HSSFWorkbook(fs);
|
||||
sheet = workbook.getSheetAt(0);
|
||||
|
||||
assertEquals("Date from file using 1904 Date Windowing",
|
||||
date.getTime(),
|
||||
sheet.getRow(0).getCell((short)0)
|
||||
.getDateCellValue().getTime());
|
||||
stream.close();
|
||||
}
|
||||
|
||||
public static void main(String [] args) {
|
||||
System.out
|
||||
.println("Testing org.apache.poi.hssf.usermodel.TestHSSFCell");
|
||||
|
@ -65,6 +65,7 @@ import java.util.GregorianCalendar;
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* @author Dan Sherman (dsherman at isisph.com)
|
||||
* @version %I%, %G%
|
||||
*/
|
||||
|
||||
@ -95,5 +96,23 @@ public class TestHSSFDateUtil
|
||||
assertEquals("Checking hour = " + hour, date.getTime().getTime(),
|
||||
HSSFDateUtil.getJavaDate(excelDate).getTime());
|
||||
}
|
||||
|
||||
// check 1900 and 1904 date windowing conversions
|
||||
double excelDate = 36526.0;
|
||||
// with 1900 windowing, excelDate is Jan. 1, 2000
|
||||
// with 1904 windowing, excelDate is Jan. 2, 2004
|
||||
GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
|
||||
Date dateIf1900 = cal.getTime();
|
||||
cal.add(GregorianCalendar.YEAR,4); // now Jan. 1, 2004
|
||||
cal.add(GregorianCalendar.DATE,1); // now Jan. 2, 2004
|
||||
Date dateIf1904 = cal.getTime();
|
||||
// 1900 windowing
|
||||
assertEquals("Checking 1900 Date Windowing",
|
||||
dateIf1900.getTime(),
|
||||
HSSFDateUtil.getJavaDate(excelDate,false).getTime());
|
||||
// 1904 windowing
|
||||
assertEquals("Checking 1904 Date Windowing",
|
||||
dateIf1904.getTime(),
|
||||
HSSFDateUtil.getJavaDate(excelDate,true).getTime());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user