jackwener/OpenCLI · error · ArgumentError

无法解析定时时间: ${raw}

Error message

无法解析定时时间: ${raw}

What it means

parseScheduleDate accepts epoch seconds/milliseconds (number) or a date string and throws ArgumentError when new Date(...) yields NaN — i.e. the value cannot be parsed as any recognizable date. The schedule time must be parseable before it is checked for being in the future.

Source

Thrown at clis/wechat-channels/publish.js:96

  }
  return resolved;
}

function parseTimeoutSeconds(raw) {
  const timeout = raw == null || raw === '' ? 600 : Number(raw);
  if (!Number.isInteger(timeout) || timeout < 30) {
    throw new ArgumentError('--timeout must be an integer >= 30 seconds');
  }
  return timeout;
}

function parseScheduleDate(raw) {
  if (!raw) return null;
  const dt = typeof raw === 'number'
    ? new Date(raw < 1e12 ? raw * 1000 : raw)
    : new Date(String(raw));
  if (Number.isNaN(dt.getTime())) {
    throw new ArgumentError(`无法解析定时时间: ${raw}`);
  }
  if (dt.getTime() <= Date.now()) {
    throw new ArgumentError('定时时间必须晚于当前时间');
  }
  return dt;
}

function parseBooleanFlag(raw) {
  return raw === true || raw === 'true' || raw === '1' || raw === 1;
}

function remainingMs(deadline, label) {
  const left = deadline - Date.now();
  if (left <= 0) {
    throw new CommandExecutionError(`${label}超时,请增加 --timeout 后重试`);
  }
  return left;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use an unambiguous format such as ISO 8601: --schedule '2026-09-01T10:00:00+08:00'.
  2. Pass an epoch timestamp (seconds or milliseconds) as a number.
  3. Pre-compute the timestamp: date -d 'tomorrow 10:00' +%s then pass that value.

Example fix

// before
node publish.js --schedule "tomorrow at 10am"
// after
node publish.js --schedule "2026-08-30T10:00:00+08:00"
Defensive patterns

Strategy: validation

Validate before calling

const dt = new Date(scheduleRaw);
if (Number.isNaN(dt.getTime())) {
  throw new Error(`Unparseable schedule time: ${scheduleRaw}; use ISO 8601 or epoch`);
}

Type guard

function isParseableDate(v) {
  return !Number.isNaN(new Date(typeof v === 'number' ? v : String(v)).getTime());
}

Try / catch

try {
  await publish({ schedule: scheduleRaw });
} catch (e) {
  if (/无法解析定时时间/.test(e.message)) {
    console.error('Use ISO 8601 like 2026-09-01T10:00:00+08:00');
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing --schedule 'tomorrow 5pm' (locale phrases), a malformed string like '2026/13/40 25:00', or an arbitrary non-date string.

Common situations: Human-readable relative dates, timezone-suffixed strings the JS Date parser rejects, shell quoting stripping characters, mixing DD/MM vs MM/DD expectations.

Related errors


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