{"record":{"id":"ff9ea393997fa705","repo":"jackwener/OpenCLI","slug":"s-yyyy-mm","errorCode":null,"errorMessage":"月份格式错误：${s}，应为 YYYY-MM","messagePattern":"月份格式错误：(.+?)，应为 YYYY-MM","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/mubu/notes.js","lineNumber":50,"sourceCode":"  }\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}\n\nfunction dateToKey(d) {\n  return `${d.year}-${String(d.month).padStart(2, '0')}-${String(d.day).padStart(2, '0')}`;\n}\n\n/** 将各种时间参数统一解析为 {start, end} */\nfunction resolveRange(kwargs) {\n  const dateStr = kwargs.date;\n  const monthStr = kwargs.month;\n  const yearArg = kwargs.year;\n  const fromStr = kwargs.from;\n  const toStr = kwargs.to;","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mubu/notes.js#L32-L68","documentation":"parseMonth expects a YYYY-MM string: splitting on '-' must yield exactly two numeric parts. Anything else throws ArgumentError with the expected format.","triggerScenarios":"Calling parseMonth('2024'), parseMonth('2024-1-15'), or parseMonth('Jan 2024').","commonSituations":"Users pass a full date where a month is expected, omit the month entirely, or scripts pass ISO timestamps like 2024-01T00:00:00Z.","solutions":["Pass exactly YYYY-MM, e.g. 2024-01.","Trim a full ISO date down: s.slice(0, 7).","Pre-validate with /^\\d{4}-\\d{2}$/.test(s)."],"exampleFix":"// before\nparseMonth('2024-01-15');\n// after\nparseMonth('2024-01');","handlingStrategy":"validation","validationCode":"const MONTH_RE = /^\\d{4}-\\d{2}$/;\nif (!MONTH_RE.test(s)) throw new Error(`month must be YYYY-MM, got: ${s}`);","typeGuard":"const isMonthString = (s) => typeof s === 'string' && /^\\d{4}-\\d{2}$/.test(s);","tryCatchPattern":"try {\n  const m = parseMonth(input);\n} catch (e) {\n  if (/月份格式错误/.test(e.message)) console.error('Use YYYY-MM format:', e.message);\n  else throw e;\n}","preventionTips":["Slice full ISO dates (s.slice(0, 7)) when a month string is required.","Do not pass full dates or timestamps where YYYY-MM is expected.","Validate with a regex before invoking the parser."],"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"}