Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -584,32 +584,8 @@ public static boolean isADateFormatUncached(Short formatIndex, String formatStri
if (StringUtils.isEmpty(formatString)) {
return false;
}
String fs = formatString;
final int length = fs.length();
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char c = fs.charAt(i);
if (i < length - 1) {
char nc = fs.charAt(i + 1);
if (c == '\\') {
switch (nc) {
case '-':
case ',':
case '.':
case ' ':
case '\\':
// skip current '\' and continue to the next char
continue;
}
} else if (c == ';' && nc == '@') {
i++;
// skip ";@" duplets
continue;
}
}
sb.append(c);
}
fs = sb.toString();

String fs = sanitizeString(formatString);

// short-circuit if it indicates elapsed time: [h], [m] or [s]
if (date_ptrn4.matcher(fs).matches()) {
Expand Down Expand Up @@ -649,6 +625,30 @@ public static boolean isADateFormatUncached(Short formatIndex, String formatStri
return result;
}

private static String sanitizeString(String fs) {
final int length = fs.length();
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char c = fs.charAt(i);
if (i < length - 1) {
char nc = fs.charAt(i + 1);
if (c == '\\' && isEscapableChar(nc)) {
continue;
} else if (c == ';' && nc == '@') {
i++;
// skip ";@" duplets
continue;
}
}
sb.append(c);
}
return sb.toString();
}

private static boolean isEscapableChar(char c) {
return c == '-' || c == ',' || c == '.' || c == ' ' || c == '\\';
}

/**
* Given a format ID this will check whether the format represents an internal excel date format or not.
*
Expand Down
Loading