avik 2002/12/12 01:02:26
Modified: src/testcases/org/apache/poi/hssf/usermodel
TestHSSFCell.java TestHSSFDateUtil.java
Added: src/testcases/org/apache/poi/hssf/data 1900DateWindowing.xls
1904DateWindowing.xls
Log:
PR:15037 - Unit Tests for 1904 date windowing; submitted by Dan Sherman
Revision Changes Path
1.1
jakarta-poi/src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls
<<Binary file>>
1.1
jakarta-poi/src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls
<<Binary file>>
1.3 +38 -0
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
Index: TestHSSFCell.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestHSSFCell.java 9 Oct 2002 20:38:00 -0000 1.2
+++ TestHSSFCell.java 12 Dec 2002 09:02:26 -0000 1.3
@@ -77,6 +77,7 @@
* 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
@@ -137,6 +138,43 @@
assertTrue("boolean value 0,2 = 1",c.getErrorCellValue() == 1);
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) {
1.2 +19 -0
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java
Index: TestHSSFDateUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestHSSFDateUtil.java 31 Jan 2002 02:23:52 -0000 1.1
+++ TestHSSFDateUtil.java 12 Dec 2002 09:02:26 -0000 1.2
@@ -65,6 +65,7 @@
*
*
* @author
+ * @author Dan Sherman (dsherman at isisph.com)
* @version %I%, %G%
*/
@@ -95,5 +96,23 @@
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());
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>