From 7f57b18f314aa6b82ccf131f71011252935fdf6f Mon Sep 17 00:00:00 2001 From: Avik Sengupta Date: Thu, 12 Dec 2002 09:02:26 +0000 Subject: 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 --- .../org/apache/poi/hssf/data/1900DateWindowing.xls | Bin 0 -> 6656 bytes .../org/apache/poi/hssf/data/1904DateWindowing.xls | Bin 0 -> 6656 bytes .../apache/poi/hssf/usermodel/TestHSSFCell.java | 38 +++++++++++++++++++++ .../poi/hssf/usermodel/TestHSSFDateUtil.java | 19 +++++++++++ 4 files changed, 57 insertions(+) create mode 100644 src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls create mode 100644 src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls (limited to 'src') diff --git a/src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls b/src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls new file mode 100644 index 0000000000..e6d966456e Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls differ diff --git a/src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls b/src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls new file mode 100644 index 0000000000..142d3148f3 Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index 278230b0b1..23a2004a54 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -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"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java index 1528f91bfc..6cd377f8cd 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java @@ -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()); } } -- cgit v1.2.3