{"record":{"id":"8fe73fd25a30d3b3","repo":"can1357/oh-my-pi","slug":"querytime-must-be-null-an-iso-date-string-or-a-v","errorCode":null,"errorMessage":"queryTime must be null, an ISO date string, or a valid Date","messagePattern":"queryTime must be null, an ISO date string, or a valid Date","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/beam/recall.ts","lineNumber":412,"sourceCode":"\treturn Math.exp(-ageHours / Math.max(halfLifeHours, 0.001));\n}\n\nexport function parseQueryTime(value: RecallOptionsInternal[\"queryTime\"]): Date {\n\tif (value == null) return new Date();\n\tif (value instanceof Date) {\n\t\tif (!Number.isFinite(value.getTime())) throw new RangeError(\"Invalid query time\");\n\t\treturn value;\n\t}\n\tif (typeof value === \"string\") {\n\t\tconst normalized = /^\\d{4}-\\d{2}-\\d{2}$/.test(value)\n\t\t\t? `${value}T00:00:00.000Z`\n\t\t\t: /(?:Z|[+-]\\d{2}:?\\d{2})$/.test(value)\n\t\t\t\t? value\n\t\t\t\t: `${value}Z`;\n\t\tconst parsed = new Date(normalized);\n\t\tif (Number.isFinite(parsed.getTime())) return parsed;\n\t}\n\tthrow new TypeError(\"queryTime must be null, an ISO date string, or a valid Date\");\n}\n\nexport function temporalBoost(timestamp: unknown, queryTime: Date, halfLifeHours: number): number {\n\tconst raw = asString(timestamp);\n\tif (raw.length === 0) return 0;\n\tconst parsed = Date.parse(raw);\n\tif (!Number.isFinite(parsed)) return 0;\n\tconst distanceHours = Math.max(0, queryTime.getTime() - parsed) / 3_600_000;\n\treturn Math.exp(-distanceHours / Math.max(halfLifeHours, 0.001));\n}\n\nfunction inferTemporalOptions(query: string, options: RecallOptionsInternal): RecallOptionsInternal {\n\tconst copy: RecallOptionsInternal = { ...options };\n\tconst info = extractTemporal(query, options.queryTime ?? undefined);\n\tif (info.event_date !== null) {\n\t\tcopy.queryTime ??= info.event_date;\n\t\tcopy.temporalWeight ??= 0.35;\n\t}","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/beam/recall.ts#L394-L430","documentation":"parseQueryTime in recall.ts throws a TypeError when the `queryTime` option is neither null/undefined, a Date, nor a string parseable as ISO-8601 with UTC/offset semantics. Plain date strings get midnight-UTC appended; strings lacking Z/offset get Z appended; anything still unparseable is rejected rather than silently defaulting to now.","triggerScenarios":"Passing queryTime as a number (epoch ms), a non-ISO string like `\"March 5, 2024\"`, or an ISO string with an unparseable component, to recall options consumed by decay/scoreCandidate/eventBoost.","commonSituations":"Passing epoch milliseconds (number) where a string/Date is expected; locale-formatted dates from UI date pickers; undefined-vs-null confusion is fine (treated as now), but wrong types are not.","solutions":["Wrap numbers in `new Date(epochMs)` and verify it is valid before passing.","Convert display-formatted dates to ISO-8601 (`2024-03-05` or `2024-03-05T00:00:00Z`).","Omit queryTime (or pass null) if you intend 'now' — do not pass an empty string."],"exampleFix":"// before\nrecall(query, { queryTime: Date.now() }); // number not accepted\n// after\nrecall(query, { queryTime: new Date(Date.now()) });","handlingStrategy":"type-guard","validationCode":"function asQueryTime(v: unknown): string | Date | null {\n  if (v == null) return null;\n  if (v instanceof Date) return v;\n  if (typeof v === \"number\") return new Date(v); // convert epoch ms\n  if (typeof v === \"string\" && /^\\d{4}-\\d{2}-\\d{2}/.test(v)) return v;\n  throw new TypeError(`Unsupported queryTime: ${String(v)}`);\n}","typeGuard":"function isQueryTime(v: unknown): v is string | Date | null {\n  return v == null || v instanceof Date || typeof v === \"string\";\n}","tryCatchPattern":"try {\n  return recall(query, { queryTime });\n} catch (e) {\n  if (e instanceof TypeError && e.message.startsWith(\"queryTime must be\")) {\n    return recall(query, { queryTime: null }); // 'now'\n  }\n  throw e;\n}","preventionTips":["Type the option as `string | Date | null` in your wrapper so numbers/objects fail at compile time.","Convert epoch numbers with new Date(ms) before passing.","Normalize UI date-picker output to ISO-8601 strings at the boundary."],"tags":["date","typeerror","validation","api-usage"],"backgroundTag":"invalid-query-time-option","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}