{"record":{"id":"207061031b324233","repo":"dianping/cat","slug":"invalid-date-format","errorCode":null,"errorMessage":"Invalid date format.","messagePattern":"Invalid date format\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/date-time/bootstrap-datepicker.js","lineNumber":1462,"sourceCode":"\t\t\t\tclsName: 'years',\n\t\t\t\tnavFnc: 'FullYear',\n\t\t\t\tnavStep: 10\n\t\t}],\n\t\tisLeapYear: function(year){\n\t\t\treturn (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));\n\t\t},\n\t\tgetDaysInMonth: function(year, month){\n\t\t\treturn [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];\n\t\t},\n\t\tvalidParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,\n\t\tnonpunctuation: /[^ -\\/:-@\\[\\u3400-\\u9fff-`{-~\\t\\n\\r]+/g,\n\t\tparseFormat: function(format){\n\t\t\t// IE treats \\0 as a string end in inputs (truncating the value),\n\t\t\t// so it's a bad format delimiter, anyway\n\t\t\tvar separators = format.replace(this.validParts, '\\0').split('\\0'),\n\t\t\t\tparts = format.match(this.validParts);\n\t\t\tif (!separators || !separators.length || !parts || parts.length === 0){\n\t\t\t\tthrow new Error(\"Invalid date format.\");\n\t\t\t}\n\t\t\treturn {separators: separators, parts: parts};\n\t\t},\n\t\tparseDate: function(date, format, language){\n\t\t\tif (!date)\n\t\t\t\treturn undefined;\n\t\t\tif (date instanceof Date)\n\t\t\t\treturn date;\n\t\t\tif (typeof format === 'string')\n\t\t\t\tformat = DPGlobal.parseFormat(format);\n\t\t\tvar part_re = /([\\-+]\\d+)([dmwy])/,\n\t\t\t\tparts = date.match(/([\\-+]\\d+)([dmwy])/g),\n\t\t\t\tpart, dir, i;\n\t\t\tif (/^[\\-+]\\d+[dmwy]([\\s,]+[\\-+]\\d+[dmwy])*$/.test(date)){\n\t\t\t\tdate = new Date();\n\t\t\t\tfor (i=0; i < parts.length; i++){\n\t\t\t\t\tpart = part_re.exec(parts[i]);\n\t\t\t\t\tdir = parseInt(part[1]);","sourceCodeStart":1444,"sourceCodeEnd":1480,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/date-time/bootstrap-datepicker.js#L1444-L1480","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n$('#dp').datepicker({ format: 'YYYY-MM-DD' }); // throws\n\n// after\n$('#dp').datepicker({ format: 'yyyy-mm-dd' });","handlingStrategy":"validation","validationCode":"var VALID_FORMAT = /dd?|DD?|mm?|MM?|yy(?:yy)?/;\nfunction validDateFormat(f) {\n  return typeof f === 'string' && VALID_FORMAT.test(f.replace(VALID_FORMAT, '')) !== undefined &&\n    (f.match(/dd?|DD?|mm?|MM?|yy(?:yy)?/g) || []).length > 0;\n}\nvar fmt = validDateFormat(userFormat) ? userFormat : 'yyyy-mm-dd';\n$('#dp').datepicker({ format: fmt });","typeGuard":"function isParsableFormat(f) {\n  return typeof f === 'string' && f.length > 0 &&\n    /dd?|DD?|mm?|MM?|yy(?:yy)?/.test(f);\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["datepicker","format-string","configuration","vendor"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}