]> source.dussan.org Git - poi.git/commitdiff
bug 60031: DataFormatter parses months incorrectly when put at the end of date segmen...
authorJaven O'Neal <onealj@apache.org>
Fri, 20 Jan 2017 05:35:57 +0000 (05:35 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 20 Jan 2017 05:35:57 +0000 (05:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1779564 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/usermodel/DataFormatter.java
src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java

index 61a5092f2264a91015f44399fed298b488a724f3..94740e9d2b97b379ae7f8b324fa76344438ae282 100644 (file)
@@ -582,6 +582,9 @@ public class DataFormatter implements Observer {
                 }
             }
             else {
+                if (Character.isWhitespace(c)){
+                    ms.clear();
+                }
                 sb.append(c);
             }
         }
index 50276ae2812846c1631c77b12e99f2ce6967b1ad..8e6e38932d5be2c220384ca1f74602b72ca7fc9b 100644 (file)
@@ -815,5 +815,17 @@ public class TestDataFormatter {
         assertEquals("5.6789", formatter.formatCellValue(cell, evaluator));
 
         wb.close();
+    }\r
+    
+    /**
+     * bug 60031: DataFormatter parses months incorrectly when put at the end of date segment
+     */\r
+    @Test\r
+    public void testBug60031() {\r
+        // 23-08-2016 08:51:01 which is 42605.368761574071 as double will be parsed\r
+        // with format "yyyy-dd-MM HH:mm:ss" into "2016-23-51 08:51:01".\r
+        DataFormatter dfUS = new DataFormatter(Locale.US);\r
+        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"));\r
     }
 }