{"record":{"id":"75794f2a9a60f3e9","repo":"jackwener/OpenCLI","slug":"14","errorCode":null,"errorMessage":"定时发布时间不能超过 14 天","messagePattern":"定时发布时间不能超过 14 天","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/douyin/_shared/timing.js","lineNumber":10,"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 also caps scheduled publish time at 14 days in the future (MAX_OFFSET = 14 * 86400). If unixSeconds exceeds now + MAX_OFFSET, it throws this Error meaning 'scheduled publish time cannot exceed 14 days', enforcing Douyin's maximum scheduling window.","triggerScenarios":"Timestamp more than 14 days ahead — e.g. scheduling next month's post, a milliseconds-vs-seconds mixup inflating the value, or a user entering a far-future date.","commonSituations":"Users trying to schedule a campaign weeks out; unit confusion where a ms timestamp makes the value appear enormous; timezone misconversion pushing the time days ahead; hardcoded far-future defaults in scripts.","solutions":["Choose a time within the next 14 days and recompute the timestamp in seconds.","Clamp or validate with unixSeconds <= Math.floor(Date.now()/1000) + 14*86400 before calling publish.","Fix any milliseconds-vs-seconds unit mistakes (Date.now() vs Date.now()/1000).","Split long-horizon campaigns into multiple scheduled posts within the 14-day window."],"exampleFix":"// before: 30 days out — rejected\nconst ts = Math.floor(Date.now() / 1000) + 30 * 86400;\n// after: clamp to just under the 14-day cap\nconst cap = Math.floor(Date.now() / 1000) + 14 * 86400 - 3600;\nconst ts = Math.min(desiredTs, cap);\nvalidateTiming(ts);","handlingStrategy":"validation","validationCode":"const MAX_OFFSET = 14 * 86400;\nconst now = Math.floor(Date.now() / 1000);\nif (ts > now + MAX_OFFSET) {\n  ts = now + MAX_OFFSET - 3600; // clamp to just inside the 14-day window\n}","typeGuard":"null","tryCatchPattern":"try {\n  validateTiming(ts);\n} catch (e) {\n  if (e.message === '定时发布时间不能超过 14 天') {\n    console.error('pick a date within the next 14 days');\n  }\n  throw e;\n}","preventionTips":["Keep schedules within a 14-day horizon; split longer campaigns","Sanity-check timestamp magnitude to catch ms-vs-seconds bugs","Clamp far-future defaults in scripts to the 14-day cap","Show the allowed window (now+2h .. now+14d) to users entering dates"],"tags":["douyin","validation","scheduling","timestamp"],"backgroundTag":"scheduled-time-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}