<changes>
<release version="3.7-SNAPSHOT" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">48872 - allow DateFormatter.formatRawCellContents to handle 1904 as well as 1900 dates</action>
<action dev="POI-DEVELOPERS" type="fix">48872 - handle MMMMM and elapsed time formatting rules in DataFormatter</action>
<action dev="POI-DEVELOPERS" type="fix">48872 - handle zero formatting rules, and better color detection in DataFormatter</action>
<action dev="POI-DEVELOPERS" type="fix">48872 - support for more kinds of formatting in DataFormatter</action>
* @see #formatCellValue(Cell)
*/
public String formatRawCellContents(double value, int formatIndex, String formatString) {
+ return formatRawCellContents(value, formatIndex, formatString, false);
+ }
+ /**
+ * Formats the given raw cell value, based on the supplied
+ * format index and string, according to excel style rules.
+ * @see #formatCellValue(Cell)
+ */
+ public String formatRawCellContents(double value, int formatIndex, String formatString, boolean use1904Windowing) {
// Is it a date?
if(DateUtil.isADateFormat(formatIndex,formatString) &&
DateUtil.isValidExcelDate(value)) {
// Hint about the raw excel value
((ExcelStyleDateFormatter)dateFormat).setDateToBeFormatted(value);
}
- Date d = DateUtil.getJavaDate(value);
+ Date d = DateUtil.getJavaDate(value, use1904Windowing);
return performDateFormatting(d, dateFormat);
}
// else Number
package org.apache.poi.ss.usermodel;
import java.util.Calendar;
-import java.util.Date;
import java.util.Locale;
-import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
-
import junit.framework.TestCase;
+import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
+
/**
* Tests of {@link DataFormatter}
*
assertEquals("60:00", dfUS.formatRawCellContents(1*hour, -1, "[mm]:ss"));
assertEquals("120:00", dfUS.formatRawCellContents(2*hour, -1, "[mm]:ss"));
}
+
+ public void testDateWindowing() {
+ DataFormatter dfUS = new DataFormatter(Locale.US);
+
+ assertEquals("1899-12-31 00:00:00", dfUS.formatRawCellContents(0.0, -1, "yyyy-mm-dd hh:mm:ss"));
+ assertEquals("1899-12-31 00:00:00", dfUS.formatRawCellContents(0.0, -1, "yyyy-mm-dd hh:mm:ss", false));
+ assertEquals("1904-01-01 00:00:00", dfUS.formatRawCellContents(0.0, -1, "yyyy-mm-dd hh:mm:ss", true));
+ }
}