aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJaven O'Neal <onealj@apache.org>2017-01-20 05:35:57 +0000
committerJaven O'Neal <onealj@apache.org>2017-01-20 05:35:57 +0000
commit442e7cc7212a5c3b64d9b6801fcd7fab6b2e059a (patch)
tree5c7ff9d64d6e0ff0688772e059f571deacc5cc4b /src
parent6509f983a7bf7e5bcc06f17d476e05e4f5a6add9 (diff)
downloadpoi-442e7cc7212a5c3b64d9b6801fcd7fab6b2e059a.tar.gz
poi-442e7cc7212a5c3b64d9b6801fcd7fab6b2e059a.zip
bug 60031: DataFormatter parses months incorrectly when put at the end of date segment. Thanks to Andrzej Witecki
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1779564 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/poi/ss/usermodel/DataFormatter.java3
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java12
2 files changed, 15 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
index 61a5092f22..94740e9d2b 100644
--- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -582,6 +582,9 @@ public class DataFormatter implements Observer {
}
}
else {
+ if (Character.isWhitespace(c)){
+ ms.clear();
+ }
sb.append(c);
}
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
index 50276ae281..8e6e38932d 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -815,5 +815,17 @@ public class TestDataFormatter {
assertEquals("5.6789", formatter.formatCellValue(cell, evaluator));
wb.close();
+ }
+
+ /**
+ * bug 60031: DataFormatter parses months incorrectly when put at the end of date segment
+ */
+ @Test
+ public void testBug60031() {
+ // 23-08-2016 08:51:01 which is 42605.368761574071 as double will be parsed
+ // with format "yyyy-dd-MM HH:mm:ss" into "2016-23-51 08:51:01".
+ DataFormatter dfUS = new DataFormatter(Locale.US);
+ assertEquals("2016-23-08 08:51:01", dfUS.formatRawCellContents(42605.368761574071, -1, "yyyy-dd-MM HH:mm:ss"));
+ assertEquals("2017-12-01 January 09:54:33", dfUS.formatRawCellContents(42747.412892397523, -1, "yyyy-dd-MM MMMM HH:mm:ss"));
}
}