jackwener/OpenCLI · error · Error
无效的时间戳: ${unixSeconds}
Error message
无效的时间戳: ${unixSeconds} What it means
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.
Source
Thrown at clis/douyin/_shared/timing.js:5
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
- 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.
Example fix
// before
await publish(page, { timing: '2026-09-01T10:00:00' });
// after
import { toUnixSeconds } from './_shared/timing.js';
await publish(page, { timing: toUnixSeconds('2026-09-01T10:00:00') }); Defensive patterns
Strategy: validation
Validate before calling
import { toUnixSeconds } from './_shared/timing.js';
const ts = toUnixSeconds(input); // handles number and numeric/digit strings
if (!Number.isFinite(ts)) throw new Error(`bad schedule input: ${input}`); Type guard
function isValidUnixSeconds(v: unknown): v is number {
return typeof v === 'number' && Number.isFinite(v);
} Try / catch
try {
validateTiming(ts);
} catch (e) {
if (String(e.message).startsWith('无效的时间戳')) {
console.error('timestamp must be a finite number of seconds — use toUnixSeconds() to convert');
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 定时发布时间不能超过 14 天
- 定时发布时间必须在至少 2 小时后
- 抖音上传提交缺少 SessionKey
- douyin delete aweme_id cannot be empty
- douyin delete aweme_id must be a numeric id
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/333de2052b5fc1c0.
Report an issue: GitHub.