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
This commit is contained in:
Nick Burch 2008-05-28 10:03:00 +00:00
parent 990adc85b0
commit 320891847c
4 changed files with 24 additions and 5 deletions

View 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>

View 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>

View 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 - / , . :

View 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,