Patch from bug #44373 - Have HSSFDateUtil.isADateFormat support more date formats
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@619382 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ab1c14b324
commit
1777e68b03
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.1-beta1" date="2008-??-??">
|
<release version="3.1-beta1" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">44373 - Have HSSFDateUtil.isADateFormat recognize more formats as being dates</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">37923 - Support for Excel hyperlinks</action>
|
<action dev="POI-DEVELOPERS" type="add">37923 - Support for Excel hyperlinks</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Implement hashCode() and equals(obj) on HSSFFont and HSSFCellStyle</action>
|
<action dev="POI-DEVELOPERS" type="add">Implement hashCode() and equals(obj) on HSSFFont and HSSFCellStyle</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">44345 - Implement CountA, CountIf, Index, Rows and Columns functions</action>
|
<action dev="POI-DEVELOPERS" type="fix">44345 - Implement CountA, CountIf, Index, Rows and Columns functions</action>
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.1-beta1" date="2008-??-??">
|
<release version="3.1-beta1" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">44373 - Have HSSFDateUtil.isADateFormat recognize more formats as being dates</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">37923 - Support for Excel hyperlinks</action>
|
<action dev="POI-DEVELOPERS" type="add">37923 - Support for Excel hyperlinks</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Implement hashCode() and equals(obj) on HSSFFont and HSSFCellStyle</action>
|
<action dev="POI-DEVELOPERS" type="add">Implement hashCode() and equals(obj) on HSSFFont and HSSFCellStyle</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">44345 - Implement CountA, CountIf, Index, Rows and Columns functions</action>
|
<action dev="POI-DEVELOPERS" type="fix">44345 - Implement CountA, CountIf, Index, Rows and Columns functions</action>
|
||||||
|
@ -208,9 +208,9 @@ public class HSSFDateUtil
|
|||||||
// who knows what that starting bit is all about
|
// who knows what that starting bit is all about
|
||||||
fs = fs.replaceAll("\\[\\$\\-.*?\\]", "");
|
fs = fs.replaceAll("\\[\\$\\-.*?\\]", "");
|
||||||
|
|
||||||
// Otherwise, check it's only made up of:
|
// Otherwise, check it's only made up, in any case, of:
|
||||||
// y m d - / ,
|
// y m d h s - / , . :
|
||||||
if(fs.matches("^[ymd\\-/, ]+$")) {
|
if(fs.matches("^[yYmMdDhHsS\\-/,. :]+$")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,6 +228,7 @@ public class TestHSSFDateUtil
|
|||||||
"yyyy-mm-dd", "yyyy/mm/dd", "yy/mm/dd", "yy/mmm/dd",
|
"yyyy-mm-dd", "yyyy/mm/dd", "yy/mm/dd", "yy/mmm/dd",
|
||||||
"dd/mm/yy", "dd/mm/yyyy", "dd/mmm/yy",
|
"dd/mm/yy", "dd/mm/yyyy", "dd/mmm/yy",
|
||||||
"dd-mm-yy", "dd-mm-yyyy",
|
"dd-mm-yy", "dd-mm-yyyy",
|
||||||
|
"DD-MM-YY", "DD-mm-YYYY",
|
||||||
"dd\\-mm\\-yy", // Sometimes escaped
|
"dd\\-mm\\-yy", // Sometimes escaped
|
||||||
|
|
||||||
// These crazy ones are valid
|
// These crazy ones are valid
|
||||||
@ -242,9 +243,18 @@ public class TestHSSFDateUtil
|
|||||||
assertTrue( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
|
assertTrue( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Then time based ones too
|
||||||
|
formats = new String[] {
|
||||||
|
"yyyy-mm-dd hh:mm:ss", "yyyy/mm/dd HH:MM:SS",
|
||||||
|
"mm/dd HH:MM", "yy/mmm/dd SS",
|
||||||
|
};
|
||||||
|
for(int i=0; i<formats.length; i++) {
|
||||||
|
assertTrue( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
|
||||||
|
}
|
||||||
|
|
||||||
// Then invalid ones
|
// Then invalid ones
|
||||||
formats = new String[] {
|
formats = new String[] {
|
||||||
"yyyy:mm:dd",
|
"yyyy*mm*dd",
|
||||||
"0.0", "0.000",
|
"0.0", "0.000",
|
||||||
"0%", "0.0%",
|
"0%", "0.0%",
|
||||||
"", null
|
"", null
|
||||||
@ -252,6 +262,15 @@ public class TestHSSFDateUtil
|
|||||||
for(int i=0; i<formats.length; i++) {
|
for(int i=0; i<formats.length; i++) {
|
||||||
assertFalse( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
|
assertFalse( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// And these are ones we probably shouldn't allow,
|
||||||
|
// but would need a better regexp
|
||||||
|
formats = new String[] {
|
||||||
|
"yyyy:mm:dd",
|
||||||
|
};
|
||||||
|
for(int i=0; i<formats.length; i++) {
|
||||||
|
// assertFalse( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user