summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAvik Sengupta <avik@apache.org>2002-12-12 09:02:26 +0000
committerAvik Sengupta <avik@apache.org>2002-12-12 09:02:26 +0000
commit7f57b18f314aa6b82ccf131f71011252935fdf6f (patch)
tree1474e5ef56b57a052d7e54f8d1e38f549c8e8d2c /src
parent44074f05982a37fc5fdddc80599d1a91b7eacbf9 (diff)
downloadpoi-7f57b18f314aa6b82ccf131f71011252935fdf6f.tar.gz
poi-7f57b18f314aa6b82ccf131f71011252935fdf6f.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xlsbin0 -> 6656 bytes
-rw-r--r--src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xlsbin0 -> 6656 bytes
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java38
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java19
4 files changed, 57 insertions, 0 deletions
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
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls
Binary files 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
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls
Binary files 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());
}
}