--- poi-3.9/src/java/org/apache/poi/ss/usermodel/DateUtil.java 2012-11-25 13:28:05.000000000 +0100 +++ poi-3.9/src/java/org/apache/poi/ss/usermodel/DateUtil.java 2013-10-19 17:19:57.000000000 +0200 @@ -288,17 +288,31 @@ public class DateUtil { * @param formatIndex The index of the format, eg from ExtendedFormatRecord.getFormatIndex * @param formatString The format string, eg from FormatRecord.getFormatString * @see #isInternalDateFormat(int) - */ - public static boolean isADateFormat(int formatIndex, String formatString) { - // First up, is this an internal date format? - if(isInternalDateFormat(formatIndex)) { - return true; - } - - // If we didn't get a real string, it can't be - if(formatString == null || formatString.length() == 0) { - return false; - } + */ + private static int lastFormatIndex = Integer.MIN_VALUE; + private static String lastFormatString = null; + private static boolean isADateFormatCache = false; + + public static synchronized boolean isADateFormat(int formatIndex, String formatString) { + + if (formatIndex == lastFormatIndex && formatString != null && formatString.equals(lastFormatString)) { + return isADateFormatCache; + } + + lastFormatIndex = formatIndex; + lastFormatString = formatString; + + // First up, is this an internal date format? + if (isInternalDateFormat(formatIndex)) { + isADateFormatCache = true; + return true; + } + + // If we didn't get a real string, it can't be + if (formatString == null || formatString.length() == 0) { + isADateFormatCache = false; + return false; + } String fs = formatString; /*if (false) { @@ -348,6 +362,7 @@ public class DateUtil { // short-circuit if it indicates elapsed time: [h], [m] or [s] if(date_ptrn4.matcher(fs).matches()){ + isADateFormatCache = true; return true; } @@ -367,7 +382,9 @@ public class DateUtil { // Otherwise, check it's only made up, in any case, of: // y m d h s - \ / , . : // optionally followed by AM/PM - return date_ptrn3.matcher(fs).matches(); + boolean result = date_ptrn3.matcher(fs).matches(); + isADateFormatCache = result; + return result; } /**