https://issues.apache.org/bugzilla/show_bug.cgi?id=55611
--- Comment #6 from Luca Della Toffola <[email protected]> --- Comment on attachment 30946 --> https://issues.apache.org/bugzilla/attachment.cgi?id=30946 Patch for poi-3.9 (synchronized) >diff -rupN -x '.*' poi-3.9/src/java/org/apache/poi/ss/usermodel/DateUtil.java >poi-3.9-patch/src/java/org/apache/poi/ss/usermodel/DateUtil.java >--- poi-3.9/src/java/org/apache/poi/ss/usermodel/DateUtil.java 2012-11-25 >13:28:05.000000000 +0100 >+++ poi-3.9-patch/src/java/org/apache/poi/ss/usermodel/DateUtil.java >2013-10-17 17:32:51.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; > } > > /** -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
