{"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":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","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/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/loop-status.js#L149-L185","documentation":"getNow parses the --now value: the literal 'now' and an unset value both yield new Date(); an all-digit value is treated as an epoch milliseconds timestamp; anything else is handed to the Date constructor. If the resulting date is Invalid Date (getTime() is NaN), the script throws. It is the single source of truth for 'now' across the status computation, used to classify session recency.","triggerScenarios":"Passing a malformed ISO string like `--now 2025-13-40`. Passing a locale-formatted date with spaces/symbols the Date constructor rejects. Passing a non-numeric, non-date string like `--now yesterday`. Passing a numeric with units like `--now 1700000000s`.","commonSituations":"Pasting a date from a log without quoting or normalizing. Mixing epoch-seconds and epoch-milliseconds (the script assumes milliseconds for all-digit input, so seconds-sized values point to 1970 but still parse — they will not throw, but are wrong; only truly unparseable strings throw).","solutions":["Use `--now now` for current time, or omit --now entirely.","Use an ISO 8601 UTC string: `--now 2025-08-12T10:30:00.000Z`.","For epoch, pass milliseconds (13 digits): `--now 1723459800000`.","Quote any string with punctuation to avoid shell splitting."],"exampleFix":"# before\nnode scripts/loop-status.js --now '2025-08-12 10:30'\n\n# after\nnode scripts/loop-status.js --now '2025-08-12T10:30:00.000Z'","handlingStrategy":"validation","validationCode":"// Validate --now up front: 'now', all-digit (ms epoch), or ISO string parseable to a valid Date.\nfunction isValidNow(v) {\n  if (!v || v === 'now') return true;\n  if (/^\\d+$/.test(String(v))) return Number(v) > 0;\n  return !Number.isNaN(new Date(v).getTime());\n}","typeGuard":null,"tryCatchPattern":"try { parseArgs(process.argv); }\ncatch (err) { if (/--now must be a valid timestamp/.test(err.message)) { console.error(err.message); printHelp(2); } else throw err; }","preventionTips":["Prefer ISO 8601 UTC strings (`...Z`) over locale formats.","For epoch, use milliseconds (13 digits).","Quote date strings to avoid shell tokenization."],"tags":["cli","date-parsing","usage"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}