mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-28 15:13:36 +00:00
Adds broad inline comments and JSDoc for CLI, cron, outbound/channel, plugin SDK, ACP, shared helpers, net policy, and related utility contracts. Proof: git diff --check on latest exact head plus focused cron tests passed; CI had no failing checks observed before merge attempt.
36 lines
971 B
TypeScript
36 lines
971 B
TypeScript
import { parseStrictPositiveInteger } from "../infra/parse-finite-number.js";
|
|
|
|
const ISO_TZ_RE = /(Z|[+-]\d{2}:?\d{2})$/i;
|
|
const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
const ISO_DATE_TIME_RE = /^\d{4}-\d{2}-\d{2}T/;
|
|
|
|
function normalizeUtcIso(raw: string) {
|
|
if (ISO_TZ_RE.test(raw)) {
|
|
return raw;
|
|
}
|
|
if (ISO_DATE_RE.test(raw)) {
|
|
return `${raw}T00:00:00Z`;
|
|
}
|
|
if (ISO_DATE_TIME_RE.test(raw)) {
|
|
return `${raw}Z`;
|
|
}
|
|
return raw;
|
|
}
|
|
|
|
/** Parses absolute cron timestamps from epoch milliseconds or ISO-like strings normalized to UTC. */
|
|
export function parseAbsoluteTimeMs(input: string): number | null {
|
|
const raw = input.trim();
|
|
if (!raw) {
|
|
return null;
|
|
}
|
|
if (/^\d+$/.test(raw)) {
|
|
const n = parseStrictPositiveInteger(raw);
|
|
if (n !== undefined && Number.isFinite(new Date(n).getTime())) {
|
|
return n;
|
|
}
|
|
return null;
|
|
}
|
|
const parsed = Date.parse(normalizeUtcIso(raw));
|
|
return Number.isFinite(parsed) ? parsed : null;
|
|
}
|