*/
private static final Pattern date_ptrn1 = Pattern.compile("^\\[\\$\\-.*?\\]");
private static final Pattern date_ptrn2 = Pattern.compile("^\\[[a-zA-Z]+\\]");
- private static final Pattern date_ptrn3 = Pattern.compile("^[\\[\\]yYmMdDhHsS\\-/,. :\"\\\\]+0*[ampAMP/]*$");
+ private static final Pattern date_ptrn3a = Pattern.compile("[yYmMdDhHsS]");
+ private static final Pattern date_ptrn3b = Pattern.compile("^[\\[\\]yYmMdDhHsS\\-/,. :\"\\\\]+0*[ampAMP/]*$");
// elapsed time patterns: [h],[m] and [s]
private static final Pattern date_ptrn4 = Pattern.compile("^\\[([hH]+|[mM]+|[sS]+)\\]");
fs = fs.substring(0, fs.indexOf(';'));
}
- // Otherwise, check it's only made up, in any case, of:
- // y m d h s - \ / , . :
+ // Ensure it has some date letters in it
+ // (Avoids false positives on the rest of pattern 3)
+ if (! date_ptrn3a.matcher(fs).find()) {
+ return false;
+ }
+
+ // If we get here, 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();
+ return date_ptrn3b.matcher(fs).matches();
}
/**
assertEquals(valueToTest.getTime(), returnedValue.getTime());
}
-
+ /**
+ * DateUtil.isCellFormatted(Cell) should not true for a numeric cell
+ * that's formatted as ".0000"
+ */
+ public void testBug54557() throws Exception {
+ final String format = ".0000";
+ boolean isDateFormat = HSSFDateUtil.isADateFormat(165, format);
+
+ assertEquals(false, isDateFormat);
+ }
}