← 中文资源

简体中文版本

Cron 下次运行时间计算器

解析五字段 cron 表达式(列表、范围、步长、通配),以分钟精度计算给定时间之后的下次运行时刻(UTC)。

阅读英文原文

目标

实现 cron 解析与 nextRun:逐字段展开允许集合,从起始时间逐分钟推进直到五个字段全部命中,最多搜索 400 天。

要点

全部用 UTC 访问器(getUTCHours 等)保证时区无关;业务时段向量验证周五晚跳到周一 09:00 UTC;CLI 输出 YYYY-MM-DD HH:MM。

提示

只支持分钟精度;day-of-week 的 7 别名与命名月份不在范围内。

验证

node –test 五个用例含周末跳过向量;CLI 对业务时段表达式打印 2026-10-19 09:15。 复现命令:

node --test cron.test.mjs
node cron.mjs "*/15 9-17 * * 1-5"

预期输出要点:Given the expression */15 9-17 * * 1-5 and a Monday morning time, the CLI prints the next quarter-hour slot inside the business window.

实测证据:Node 22.23.2: node –test -> 5 passed; Friday-evening vector resolved to Monday 09:00 UTC; CLI printed 2026-10-19 09:15 for the business-hours expression.