View | Details | Raw Unified | Return to bug 15037
Collapse All | Expand All

(-)src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java (+38 lines)
Lines 77-82 Link Here
77
 * Tests various functionity having to do with HSSFCell.  For instance support for
77
 * Tests various functionity having to do with HSSFCell.  For instance support for
78
 * paticular datatypes, etc.
78
 * paticular datatypes, etc.
79
 * @author Andrew C. Oliver (andy at superlinksoftware dot com)
79
 * @author Andrew C. Oliver (andy at superlinksoftware dot com)
80
 * @author  Dan Sherman (dsherman at isisph.com)
80
 */
81
 */
81
82
82
public class TestHSSFCell
83
public class TestHSSFCell
Lines 137-142 Link Here
137
            assertTrue("boolean value 0,2 = 1",c.getErrorCellValue() == 1);
138
            assertTrue("boolean value 0,2 = 1",c.getErrorCellValue() == 1);
138
139
139
            in.close();
140
            in.close();
141
    }
142
143
    /**
144
    * Checks that the recognition of files using 1904 date windowing
145
    *  is working properly. Conversion of the date is also an issue,
146
    *  but there's a separate unit test for that.
147
    */
148
    public void testDateWindowing() throws Exception {
149
        GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
150
        Date date = cal.getTime();
151
        String path = System.getProperty("HSSF.testdata.path");
152
153
        // first check a file with 1900 Date Windowing
154
        String filename = path + "/1900DateWindowing.xls";
155
        FileInputStream stream   = new FileInputStream(filename);
156
        POIFSFileSystem fs       = new POIFSFileSystem(stream);
157
        HSSFWorkbook    workbook = new HSSFWorkbook(fs);
158
        HSSFSheet       sheet    = workbook.getSheetAt(0);
159
160
        assertEquals("Date from file using 1900 Date Windowing",
161
                        date.getTime(),
162
                           sheet.getRow(0).getCell((short)0)
163
                              .getDateCellValue().getTime());
164
        stream.close();
165
        
166
        // now check a file with 1904 Date Windowing
167
        filename = path + "/1904DateWindowing.xls";
168
        stream   = new FileInputStream(filename);
169
        fs       = new POIFSFileSystem(stream);
170
        workbook = new HSSFWorkbook(fs);
171
        sheet    = workbook.getSheetAt(0);
172
173
        assertEquals("Date from file using 1904 Date Windowing",
174
                        date.getTime(),
175
                           sheet.getRow(0).getCell((short)0)
176
                              .getDateCellValue().getTime());
177
        stream.close();
140
    }
178
    }
141
179
142
    public static void main(String [] args) {
180
    public static void main(String [] args) {
(-)src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java (+19 lines)
Lines 65-70 Link Here
65
 *
65
 *
66
 *
66
 *
67
 * @author
67
 * @author
68
 * @author  Dan Sherman (dsherman at isisph.com)
68
 * @version %I%, %G%
69
 * @version %I%, %G%
69
 */
70
 */
70
71
Lines 95-99 Link Here
95
            assertEquals("Checking hour = " + hour, date.getTime().getTime(),
96
            assertEquals("Checking hour = " + hour, date.getTime().getTime(),
96
                         HSSFDateUtil.getJavaDate(excelDate).getTime());
97
                         HSSFDateUtil.getJavaDate(excelDate).getTime());
97
        }
98
        }
99
        
100
        // check 1900 and 1904 date windowing conversions
101
        double excelDate = 36526.0;
102
                 // with 1900 windowing, excelDate is Jan. 1, 2000
103
                 // with 1904 windowing, excelDate is Jan. 2, 2004
104
        GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
105
        Date dateIf1900 = cal.getTime();
106
        cal.add(GregorianCalendar.YEAR,4); // now Jan. 1, 2004
107
        cal.add(GregorianCalendar.DATE,1); // now Jan. 2, 2004
108
        Date dateIf1904 = cal.getTime();
109
        // 1900 windowing
110
        assertEquals("Checking 1900 Date Windowing",
111
                        dateIf1900.getTime(),
112
                           HSSFDateUtil.getJavaDate(excelDate,false).getTime());
113
        // 1904 windowing
114
        assertEquals("Checking 1904 Date Windowing",
115
                        dateIf1904.getTime(),
116
                           HSSFDateUtil.getJavaDate(excelDate,true).getTime());
98
    }
117
    }
99
}
118
}

Return to bug 15037