{"record":{"id":"cf07b2b620ab36ef","repo":"affaan-m/ECC","slug":"now-must-be-a-valid-timestamp","errorCode":null,"errorMessage":"--now must be a valid timestamp","messagePattern":"--now must be a valid timestamp","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/loop-status.js","lineNumber":167,"sourceCode":"    return path.resolve(options.home);\n  }\n  return process.env.HOME || process.env.USERPROFILE || os.homedir();\n}\n\nfunction getNow(options = {}) {\n  if (!options.now) {\n    return new Date();\n  }\n\n  if (options.now === 'now') {\n    return new Date();\n  }\n\n  const now = /^\\d+$/.test(String(options.now))\n    ? new Date(Number(options.now))\n    : new Date(options.now);\n  if (Number.isNaN(now.getTime())) {\n    throw new Error('--now must be a valid timestamp');\n  }\n  return now;\n}\n\nfunction walkJsonlFiles(dir, result = { errors: [], files: [] }) {\n  if (!fs.existsSync(dir)) {\n    return result;\n  }\n\n  let entries;\n  try {\n    entries = fs.readdirSync(dir, { withFileTypes: true });\n  } catch (error) {\n    result.errors.push({\n      code: error.code || null,\n      message: error.message,\n      transcriptPath: dir,\n    });","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/loop-status.js#L149-L185","documentation":"getNow in scripts/loop-status.js resolves the --now override into a Date. Numeric strings are treated as epoch milliseconds; anything else is handed to the Date constructor. If the resulting Date is NaN (unparseable timestamp), the script throws '--now must be a valid timestamp' so downstream age/status computations never see an invalid clock.","triggerScenarios":"Running `node scripts/loop-status.js --now 'not-a-date'`, `--now 2026-13-45` (invalid month/day), or an empty --now value.","commonSituations":"Hand-editing timestamps in shell scripts, timezone-related malformed strings, passing a formatted date that Date cannot parse in the local runtime, or shell quoting stripping the value.","solutions":["Pass epoch milliseconds: `--now 1735689600000`.","Use an ISO 8601 string: `--now 2026-01-01T12:00:00Z`.","Validate the timestamp in your wrapper first, e.g. `node -e \"new Date(process.argv[1])\"` or `date -d` to sanity-check.","If generating the value in a script, use `Date.now()` or `new Date().toISOString()` instead of hand-built strings."],"exampleFix":"// before\nnode scripts/loop-status.js --now 'yesterday maybe'\n// after\nnode scripts/loop-status.js --now \"$(date +%s)000\"","handlingStrategy":"validation","validationCode":"function isValidTimestamp(v){ return /^\\d+$/.test(String(v)) || !Number.isNaN(new Date(v).getTime()); }\nif (!isValidTimestamp(nowValue)) throw new Error('invalid --now');","typeGuard":"const isValidDate = (v) => !Number.isNaN(new Date(v).getTime());","tryCatchPattern":"try { run(args); } catch (e) { if (e.message.includes('--now')) { console.error('Use epoch ms or ISO 8601 for --now'); process.exitCode = 2; } else throw e; }","preventionTips":["Prefer Date.now() / toISOString() when generating timestamps in scripts","Sanity-check timestamps with `new Date(v)` in a wrapper","Quote date strings carefully in shell to avoid token splitting"],"tags":["cli","date-parsing","validation"],"backgroundTag":"invalid-date-format","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}