View | Details | Raw Unified | Return to bug 55611
Collapse All | Expand All

(-)poi-3.9/src/java/org/apache/poi/ss/usermodel/DateUtil.java (-12 / +29 lines)
Lines 288-304 public class DateUtil { Link Here
288
     * @param formatIndex The index of the format, eg from ExtendedFormatRecord.getFormatIndex
288
     * @param formatIndex The index of the format, eg from ExtendedFormatRecord.getFormatIndex
289
     * @param formatString The format string, eg from FormatRecord.getFormatString
289
     * @param formatString The format string, eg from FormatRecord.getFormatString
290
     * @see #isInternalDateFormat(int)
290
     * @see #isInternalDateFormat(int)
291
     */
291
     */  
292
    public static boolean isADateFormat(int formatIndex, String formatString) {
292
    private static int lastFormatIndex = Integer.MIN_VALUE;
293
        // First up, is this an internal date format?
293
    private static String lastFormatString = null;
294
        if(isInternalDateFormat(formatIndex)) {
294
    private static boolean isADateFormatCache = false;
295
            return true;
295
    
296
        }
296
    public static synchronized boolean isADateFormat(int formatIndex, String formatString) {
297
297
       
298
        // If we didn't get a real string, it can't be
298
       if (formatIndex == lastFormatIndex && formatString != null && formatString.equals(lastFormatString)) {
299
        if(formatString == null || formatString.length() == 0) {
299
          return isADateFormatCache;
300
            return false;
300
       }
301
        }
301
       
302
       lastFormatIndex = formatIndex;
303
       lastFormatString = formatString;
304
       
305
       // First up, is this an internal date format?
306
       if (isInternalDateFormat(formatIndex)) {
307
          isADateFormatCache = true;
308
          return true;
309
       }
310
311
       // If we didn't get a real string, it can't be
312
       if (formatString == null || formatString.length() == 0) {
313
          isADateFormatCache = false;
314
          return false;
315
       }
302
316
303
        String fs = formatString;
317
        String fs = formatString;
304
        /*if (false) {
318
        /*if (false) {
Lines 348-353 public class DateUtil { Link Here
348
362
349
        // short-circuit if it indicates elapsed time: [h], [m] or [s]
363
        // short-circuit if it indicates elapsed time: [h], [m] or [s]
350
        if(date_ptrn4.matcher(fs).matches()){
364
        if(date_ptrn4.matcher(fs).matches()){
365
            isADateFormatCache = true;
351
            return true;
366
            return true;
352
        }
367
        }
353
368
Lines 367-373 public class DateUtil { Link Here
367
        // Otherwise, check it's only made up, in any case, of:
382
        // Otherwise, check it's only made up, in any case, of:
368
        //  y m d h s - \ / , . :
383
        //  y m d h s - \ / , . :
369
        // optionally followed by AM/PM
384
        // optionally followed by AM/PM
370
        return date_ptrn3.matcher(fs).matches();
385
        boolean result = date_ptrn3.matcher(fs).matches();
386
        isADateFormatCache = result;
387
        return result;
371
    }
388
    }
372
389
373
    /**
390
    /**

Return to bug 55611