jackwener/OpenCLI · error · Error

定时发布时间必须在至少 2 小时后

Error message

定时发布时间必须在至少 2 小时后

What it means

validateTiming requires scheduled publish time to be at least 2 hours in the future (MIN_OFFSET = 7200). If unixSeconds is finite but earlier than now + 7200, it throws this Error meaning 'scheduled publish time must be at least 2 hours from now' — matching Douyin's scheduling constraints.

Source

Thrown at clis/douyin/_shared/timing.js:8

const MIN_OFFSET = 7200; // 2 hours
const MAX_OFFSET = 14 * 86400; // 14 days
export function validateTiming(unixSeconds) {
    if (!Number.isFinite(unixSeconds))
        throw new Error(`无效的时间戳: ${unixSeconds}`);
    const now = Math.floor(Date.now() / 1000);
    if (unixSeconds < now + MIN_OFFSET)
        throw new Error(`定时发布时间必须在至少 2 小时后`);
    if (unixSeconds > now + MAX_OFFSET)
        throw new Error(`定时发布时间不能超过 14 天`);
}
export function toUnixSeconds(input) {
    if (typeof input === 'number')
        return input;
    if (/^\d+$/.test(input)) {
        return Number(input);
    }
    const ms = new Date(input).getTime();
    if (isNaN(ms))
        throw new Error(`无效的时间格式: "${input}"`);
    return Math.floor(ms / 1000);
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pick a time at least 2 hours (and within 14 days) in the future and recompute the timestamp.
  2. Use Math.floor(Date.now() / 1000) + offset to build seconds-based timestamps, never Date.now() directly.
  3. Check timezone handling: construct the target time in the correct zone before converting to unix seconds.
  4. Validate the timing in UI/CLI code before invoking publish, using the same MIN_OFFSET rule.

Example fix

// before: 30 minutes ahead — rejected
const ts = Math.floor(Date.now() / 1000) + 1800;
// after: 3 hours ahead
const ts = Math.floor(Date.now() / 1000) + 3 * 3600;
validateTiming(ts);
Defensive patterns

Strategy: validation

Validate before calling

const MIN_OFFSET = 7200;
const now = Math.floor(Date.now() / 1000);
if (ts < now + MIN_OFFSET) {
  ts = now + MIN_OFFSET + 60; // push to just past the 2-hour minimum
}

Type guard

null

Try / catch

try {
  validateTiming(ts);
} catch (e) {
  if (e.message === '定时发布时间必须在至少 2 小时后') {
    ts = Math.floor(Date.now() / 1000) + 3 * 3600; // fall back to +3h
    validateTiming(ts);
  } else throw e;
}

Prevention

When it happens

Trigger: Timestamp 0–2 hours ahead of the current time, any timestamp in the past, or a timestamp computed with a wrong unit (milliseconds instead of seconds, which lands far in the past after division confusion).

Common situations: Users scheduling 'later today' within 2 hours; forgetting timezone conversion so local time is passed as UTC (or vice versa) shifting the value; passing Date.now() (milliseconds) instead of seconds; immediate-publish calls that accidentally include a near-now timing.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/7bcbf23af0906d88. Report an issue: GitHub.