dianping/cat · error · Error
Invalid date format.
Error message
Invalid date format.
What it means
datepicker's DPGlobal.parseFormat splits the format string into separators and date parts using the validParts regex (dd, d, DD, mm, m, MM, yy, yyyy). If the format contains no recognizable parts at all (parts is null/empty), the format object cannot be built and the constructor throws 'Invalid date format.'. It is thrown from the plugin's internals when it parses the format option or a data-date-format attribute.
Source
Thrown at cat-home/src/main/webapp/assets/js/uncompressed/date-time/bootstrap-datepicker.js:1462
clsName: 'years',
navFnc: 'FullYear',
navStep: 10
}],
isLeapYear: function(year){
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
},
getDaysInMonth: function(year, month){
return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
},
validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,
nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
parseFormat: function(format){
// IE treats \0 as a string end in inputs (truncating the value),
// so it's a bad format delimiter, anyway
var separators = format.replace(this.validParts, '\0').split('\0'),
parts = format.match(this.validParts);
if (!separators || !separators.length || !parts || parts.length === 0){
throw new Error("Invalid date format.");
}
return {separators: separators, parts: parts};
},
parseDate: function(date, format, language){
if (!date)
return undefined;
if (date instanceof Date)
return date;
if (typeof format === 'string')
format = DPGlobal.parseFormat(format);
var part_re = /([\-+]\d+)([dmwy])/,
parts = date.match(/([\-+]\d+)([dmwy])/g),
part, dir, i;
if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/.test(date)){
date = new Date();
for (i=0; i < parts.length; i++){
part = part_re.exec(parts[i]);
dir = parseInt(part[1]);View on GitHub (pinned to e815e74d4c)
Solutions
- Use only supported tokens: d, dd, D, DD, m, mm, M, MM, y, yy, yyyy (e.g. 'yyyy-mm-dd', 'dd/mm/yyyy').
- If the format is dynamic, validate it with /dd?|DD?|mm?|MM?|yy(?:yy)?/ before initializing the picker and fall back to a default.
- Check data-date-format attributes in markup for the same token rules.
Example fix
// before
$('#dp').datepicker({ format: 'YYYY-MM-DD' }); // throws
// after
$('#dp').datepicker({ format: 'yyyy-mm-dd' }); Defensive patterns
Strategy: validation
Validate before calling
var VALID_FORMAT = /dd?|DD?|mm?|MM?|yy(?:yy)?/;
function validDateFormat(f) {
return typeof f === 'string' && VALID_FORMAT.test(f.replace(VALID_FORMAT, '')) !== undefined &&
(f.match(/dd?|DD?|mm?|MM?|yy(?:yy)?/g) || []).length > 0;
}
var fmt = validDateFormat(userFormat) ? userFormat : 'yyyy-mm-dd';
$('#dp').datepicker({ format: fmt }); Type guard
function isParsableFormat(f) {
return typeof f === 'string' && f.length > 0 &&
/dd?|DD?|mm?|MM?|yy(?:yy)?/.test(f);
} Prevention
- Centralize date formats in one constant module using only d/dd/D/DD/m/mm/M/MM/y/yy/yyyy tokens.
- Never pass moment.js-style uppercase tokens to this datepicker.
- Validate formats coming from user preferences or server config before initializing pickers.
When it happens
Trigger: Calling $el.datepicker({format: 'YYYY-MM-DD'}) — uppercase YYYY/MM/DD are not valid parts in this version (it expects yyyy); passing an empty format string; passing a format like 'd-mmm-yyyy' (mmm not supported); passing a Date object or non-string where a format is expected.
Common situations: Porting code from another datepicker (e.g. jQuery UI or moment.js style 'YYYY-MM-DD HH:mm') without converting tokens; copy-pasting .NET or Java format strings ('dd/MM/yyyy' works but 'dd-MMM-yy' does not); dynamically building the format from a variable that is occasionally empty.
Related errors
- Must choose at least one picker
- No URL provided.
- You can't provide both 'acceptedFiles' and 'acceptedMimeType
- %sis illegal
- {regex}
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/207061031b324233.
Report an issue: GitHub.