{"record":{"id":"333de2052b5fc1c0","repo":"jackwener/OpenCLI","slug":"unixseconds","errorCode":null,"errorMessage":"无效的时间戳: ${unixSeconds}","messagePattern":"无效的时间戳: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/douyin/_shared/timing.js","lineNumber":5,"sourceCode":"const MIN_OFFSET = 7200; // 2 hours\nconst MAX_OFFSET = 14 * 86400; // 14 days\nexport function validateTiming(unixSeconds) {\n    if (!Number.isFinite(unixSeconds))\n        throw new Error(`无效的时间戳: ${unixSeconds}`);\n    const now = Math.floor(Date.now() / 1000);\n    if (unixSeconds < now + MIN_OFFSET)\n        throw new Error(`定时发布时间必须在至少 2 小时后`);\n    if (unixSeconds > now + MAX_OFFSET)\n        throw new Error(`定时发布时间不能超过 14 天`);\n}\nexport function toUnixSeconds(input) {\n    if (typeof input === 'number')\n        return input;\n    if (/^\\d+$/.test(input)) {\n        return Number(input);\n    }\n    const ms = new Date(input).getTime();\n    if (isNaN(ms))\n        throw new Error(`无效的时间格式: \"${input}\"`);\n    return Math.floor(ms / 1000);\n}\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/douyin/_shared/timing.js#L1-L23","documentation":"validateTiming checks a scheduled-publish unix timestamp. If the value is not a finite number (NaN, Infinity, string, null), it throws a plain Error with this Chinese message meaning 'invalid timestamp'. It is an input-validation guard before the range checks.","triggerScenarios":"Passing a non-numeric or non-finite value: an unparseable date string, NaN from a failed Number() conversion, undefined/null from missing config, or an ISO string that was never converted via toUnixSeconds.","commonSituations":"Users passing an ISO date string directly instead of converting with toUnixSeconds; config file with a quoted or empty timestamp; timezone-parsing helpers returning NaN; CLI flag parsed as string.","solutions":["Convert the input with the library's toUnixSeconds() helper before calling validateTiming.","Check the value with Number.isFinite() at the call site to catch NaN early.","Fix the config/CLI parsing so the timestamp is numeric, not a string.","Validate date parsing (new Date(input).getTime()) and reject NaN results upstream."],"exampleFix":"// before\nawait publish(page, { timing: '2026-09-01T10:00:00' });\n// after\nimport { toUnixSeconds } from './_shared/timing.js';\nawait publish(page, { timing: toUnixSeconds('2026-09-01T10:00:00') });","handlingStrategy":"validation","validationCode":"import { toUnixSeconds } from './_shared/timing.js';\nconst ts = toUnixSeconds(input); // handles number and numeric/digit strings\nif (!Number.isFinite(ts)) throw new Error(`bad schedule input: ${input}`);","typeGuard":"function isValidUnixSeconds(v: unknown): v is number {\n  return typeof v === 'number' && Number.isFinite(v);\n}","tryCatchPattern":"try {\n  validateTiming(ts);\n} catch (e) {\n  if (String(e.message).startsWith('无效的时间戳')) {\n    console.error('timestamp must be a finite number of seconds — use toUnixSeconds() to convert');\n  }\n  throw e;\n}","preventionTips":["Always convert user input with toUnixSeconds() before validateTiming","Reject non-numeric CLI/config values at parse time","Beware Date.parse/new Date(...) returning NaN for odd formats","Keep timestamps as seconds, not milliseconds, throughout the pipeline"],"tags":["douyin","validation","timestamp","scheduling"],"backgroundTag":"invalid-timestamp","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}