aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2010-06-01 15:31:51 +0000
committerNick Burch <nick@apache.org>2010-06-01 15:31:51 +0000
commit4a10622c7f4bfc9c0f7595434b3144fe654220f4 (patch)
tree389eb66ec7dd904d3d13f7f9fa03e394f1464213
parent6099faa72238b572e5f5c22500a7283690bde5f6 (diff)
downloadpoi-4a10622c7f4bfc9c0f7595434b3144fe654220f4.tar.gz
poi-4a10622c7f4bfc9c0f7595434b3144fe654220f4.zip
Fix inspired by bug #48872 - allow DateFormatter.formatRawCellContents to handle 1904 as well as 1900 dates
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@950117 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/ss/usermodel/DataFormatter.java10
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java13
3 files changed, 20 insertions, 4 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index d1cae47add..1b213bb52e 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<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>
diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
index 029f24cd40..d0d07c0a3e 100644
--- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -511,6 +511,14 @@ public class DataFormatter {
* @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)) {
@@ -519,7 +527,7 @@ public class DataFormatter {
// 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
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
index bc3bb67847..35be8c4ff1 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -18,13 +18,12 @@
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}
*
@@ -189,4 +188,12 @@ public class TestDataFormatter extends TestCase {
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));
+ }
}