{"record":{"id":"da75bb7a4fd2cb19","repo":"jackwener/OpenCLI","slug":"s-yyyy-mm-dd","errorCode":null,"errorMessage":"日期格式错误：${s}，应为 YYYY-MM-DD","messagePattern":"日期格式错误：(.+?)，应为 YYYY-MM-DD","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/mubu/notes.js","lineNumber":38,"sourceCode":"}\n\nfunction validateMonth(month) {\n  if (!Number.isInteger(month) || month < 1 || month > 12) {\n    throw new ArgumentError(`月份非法：${month}，应为 1-12`);\n  }\n}\n\nfunction validateDay(year, month, day) {\n  const maxDay = lastDayOfMonth(year, month);\n  if (!Number.isInteger(day) || day < 1 || day > maxDay) {\n    throw new ArgumentError(`日期非法：${year}-${month}-${day}（${year} 年 ${month} 月共 ${maxDay} 天）`);\n  }\n}\n\nfunction parseDate(s) {\n  const parts = s.split('-').map(Number);\n  if (parts.length !== 3 || parts.some(isNaN)) {\n    throw new ArgumentError(`日期格式错误：${s}，应为 YYYY-MM-DD`);\n  }\n  const [year, month, day] = parts;\n  validateYear(year);\n  validateMonth(month);\n  validateDay(year, month, day);\n  return { year, month, day };\n}\n\nfunction parseMonth(s) {\n  const parts = s.split('-').map(Number);\n  if (parts.length !== 2 || parts.some(isNaN)) {\n    throw new ArgumentError(`月份格式错误：${s}，应为 YYYY-MM`);\n  }\n  const [year, month] = parts;\n  validateYear(year);\n  validateMonth(month);\n  return { year, month };\n}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mubu/notes.js#L20-L56","documentation":"parseDate splits an input string on '-' and requires exactly three numeric parts (YYYY-MM-DD). If the shape is wrong or any part is NaN, it throws ArgumentError telling the user the expected format.","triggerScenarios":"Passing '2024/01/05', '2024-1', 'today', or an empty string to parseDate (via --from/--to flags or the d/start/end helpers).","commonSituations":"Users use slash-formatted dates, pass human words like 'yesterday', or shell quoting strips a hyphen.","solutions":["Pass dates as YYYY-MM-DD, e.g. 2024-01-05.","Normalize separators: s.replace(/\\//g, '-') before parsing.","Pre-validate the string with /^\\d{4}-\\d{2}-\\d{2}$/.test(s)."],"exampleFix":"// before\nparseDate('2024/01/05');\n// after\nparseDate('2024-01-05');","handlingStrategy":"validation","validationCode":"const DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\nif (!DATE_RE.test(s)) throw new Error(`date must be YYYY-MM-DD, got: ${s}`);","typeGuard":"const isDateString = (s) => typeof s === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(s);","tryCatchPattern":"try {\n  const d = parseDate(input);\n} catch (e) {\n  if (/日期格式错误/.test(e.message)) console.error('Use YYYY-MM-DD format:', e.message);\n  else throw e;\n}","preventionTips":["Always pass ISO-style YYYY-MM-DD strings to --from/--to.","Reject free-text dates at the UI/script boundary before they reach the CLI.","Normalize '/' separators and trim whitespace before parsing."],"tags":["date-validation","argument-error","cli","format"],"backgroundTag":"invalid-date-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}