From 320891847c8b5e977150d0822a2598a1c03160d1 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 28 May 2008 10:03:00 +0000 Subject: [PATCH] Fix bug #45087 - Correctly detect date formats like [Black]YYYY as being date based git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@660889 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../poi/hssf/usermodel/HSSFDateUtil.java | 8 ++++++-- .../poi/hssf/usermodel/TestHSSFDateUtil.java | 19 ++++++++++++++++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 831149c3b1..08aebb79d0 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 45087 - Correctly detect date formats like [Black]YYYY as being date based 45060 - Improved token class transformation during formula parsing 44840 - Improved handling of HSSFObjectData, especially for entries with data held not in POIFS 45043 - Support for getting excel cell comments when extracting text diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index d9052130c2..0431bd3fde 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 45087 - Correctly detect date formats like [Black]YYYY as being date based 45060 - Improved token class transformation during formula parsing 44840 - Improved handling of HSSFObjectData, especially for entries with data held not in POIFS 45043 - Support for getting excel cell comments when extracting text diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java b/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java index 910d2737c2..be590c3a2d 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java @@ -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 - / , . : diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java index 6540f8f091..2ac4eb825f 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java @@ -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