? mypatch.patch Index: src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java =================================================================== RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java,v retrieving revision 1.2 diff -u -r1.2 TestHSSFCell.java --- src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java 9 Oct 2002 20:38:00 -0000 1.2 +++ src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java 3 Dec 2002 22:20:58 -0000 @@ -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) { Index: src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java =================================================================== RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 TestHSSFDateUtil.java --- src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java 31 Jan 2002 02:23:52 -0000 1.1.1.1 +++ src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java 3 Dec 2002 22:20:58 -0000 @@ -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()); } }