]> source.dussan.org Git - poi.git/commitdiff
Fix bug #45087 - Correctly detect date formats like [Black]YYYY as being date based
authorNick Burch <nick@apache.org>
Wed, 28 May 2008 10:03:00 +0000 (10:03 +0000)
committerNick Burch <nick@apache.org>
Wed, 28 May 2008 10:03:00 +0000 (10:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@660889 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java

index 831149c3b1ff50c6ea028338734c190c2facf723..08aebb79d0d8eaa228ea46baf57cb92e08f61228 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.1-final" date="2008-06-??">
+           <action dev="POI-DEVELOPERS" type="fix">45087 - Correctly detect date formats like [Black]YYYY as being date based</action>
            <action dev="POI-DEVELOPERS" type="add">45060 - Improved token class transformation during formula parsing</action>
            <action dev="POI-DEVELOPERS" type="add">44840 - Improved handling of HSSFObjectData, especially for entries with data held not in POIFS</action>
            <action dev="POI-DEVELOPERS" type="add">45043 - Support for getting excel cell comments when extracting text</action>
index d9052130c27c645c67959cbceb92f2a64e03a486..0431bd3fdeecdb990e087abe80d907d01b1e02e2 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-final" date="2008-06-??">
+           <action dev="POI-DEVELOPERS" type="fix">45087 - Correctly detect date formats like [Black]YYYY as being date based</action>
            <action dev="POI-DEVELOPERS" type="add">45060 - Improved token class transformation during formula parsing</action>
            <action dev="POI-DEVELOPERS" type="add">44840 - Improved handling of HSSFObjectData, especially for entries with data held not in POIFS</action>
            <action dev="POI-DEVELOPERS" type="add">45043 - Support for getting excel cell comments when extracting text</action>
index 910d2737c2b1fbfffec36b2c90f73fb74484ebea..be590c3a2d18eb2b13f31c994d9c5dc02d5137a2 100644 (file)
@@ -220,9 +220,13 @@ public class HSSFDateUtil
        //  switching stuff, which we can ignore
        fs = fs.replaceAll(";@", "");
        
-       // If it starts with [$-...], then it is a date, but
+       // If it starts with [$-...], then could be a date, but
        //  who knows what that starting bit is all about
-       fs = fs.replaceAll("\\[\\$\\-.*?\\]", "");
+       fs = fs.replaceAll("^\\[\\$\\-.*?\\]", "");
+       
+       // If it starts with something like [Black] or [Yellow],
+       //  then it could be a date
+       fs = fs.replaceAll("^\\[[a-zA-Z]+\\]", "");
        
        // Otherwise, check it's only made up, in any case, of:
        //  y m d h s - / , . :
index 6540f8f091e71693a2c59e507b04d6a3651f3907..2ac4eb825f9e7d06fe27d0ca1a7b5d58c5d52365 100644 (file)
@@ -257,9 +257,15 @@ public class TestHSSFDateUtil extends TestCase {
                 // (who knows what they mean though...)
                 "[$-F800]dddd\\,\\ mmm\\ dd\\,\\ yyyy",
                 "[$-F900]ddd/mm/yyy",
+                // These ones specify colours, who knew that was allowed?
+                "[BLACK]dddd/mm/yy",
+                "[yeLLow]yyyy-mm-dd"
         };
         for(int i=0; i<formats.length; i++) {
-            assertTrue( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
+            assertTrue(
+                       formats[i] + " is a date format", 
+                       HSSFDateUtil.isADateFormat(formatId, formats[i])
+            );
         }
         
         // Then time based ones too
@@ -270,7 +276,10 @@ public class TestHSSFDateUtil extends TestCase {
                 "mm/dd HH:MM PM", "mm/dd HH:MM pm" 
         };
         for(int i=0; i<formats.length; i++) {
-            assertTrue( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
+            assertTrue(
+                       formats[i] + " is a datetime format", 
+                       HSSFDateUtil.isADateFormat(formatId, formats[i])
+            );
         }
         
         // Then invalid ones
@@ -278,10 +287,14 @@ public class TestHSSFDateUtil extends TestCase {
                 "yyyy*mm*dd", 
                 "0.0", "0.000",
                 "0%", "0.0%",
+                "[]Foo", "[BLACK]0.00%",
                 "", null
         };
         for(int i=0; i<formats.length; i++) {
-            assertFalse( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
+            assertFalse( 
+                       formats[i] + " is not a date or datetime format",
+                       HSSFDateUtil.isADateFormat(formatId, formats[i])
+            );
         }
         
         // And these are ones we probably shouldn't allow,