From 212604f51ee3ae2d2e7b19ef9e2eedea41aefbb8 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 7 Feb 2008 12:39:12 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../poi/hssf/usermodel/HSSFDateUtil.java | 6 +++--- .../poi/hssf/usermodel/TestHSSFDateUtil.java | 21 ++++++++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 2b017fee7b..aee0a20997 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 44373 - Have HSSFDateUtil.isADateFormat recognize more formats as being dates 37923 - Support for Excel hyperlinks Implement hashCode() and equals(obj) on HSSFFont and HSSFCellStyle 44345 - Implement CountA, CountIf, Index, Rows and Columns functions diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index feab74a973..084aba2afe 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 44373 - Have HSSFDateUtil.isADateFormat recognize more formats as being dates 37923 - Support for Excel hyperlinks Implement hashCode() and equals(obj) on HSSFFont and HSSFCellStyle 44345 - Implement CountA, CountIf, Index, Rows and Columns functions diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java b/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java index fb3a92df86..d0ad798afa 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java @@ -208,9 +208,9 @@ public class HSSFDateUtil // who knows what that starting bit is all about fs = fs.replaceAll("\\[\\$\\-.*?\\]", ""); - // Otherwise, check it's only made up of: - // y m d - / , - if(fs.matches("^[ymd\\-/, ]+$")) { + // Otherwise, check it's only made up, in any case, of: + // y m d h s - / , . : + if(fs.matches("^[yYmMdDhHsS\\-/,. :]+$")) { return true; } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java index 6b37f749ee..08874399eb 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java @@ -228,6 +228,7 @@ public class TestHSSFDateUtil "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-MM-YY", "DD-mm-YYYY", "dd\\-mm\\-yy", // Sometimes escaped // These crazy ones are valid @@ -242,9 +243,18 @@ public class TestHSSFDateUtil 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