目录

cron_mbt

MoonBit CI

a simple and fast cron expression parser and scheduler written in MoonBit. created for the 2026 OSC Track 1 MoonBit Competition.

features

  • parses standard 5-field cron expressions
  • supports macros like @hourly, @daily, etc.
  • calculates the next execution time based on current time
  • lexer and ast based, zero dependencies

usage

add to moon.mod.json:

{
  "deps": {
    "cxh0404/cron_mbt": "0.1.0"
  }
}

simple parsing and matching:

let expr = @cron.parse("*/5 8-10 * * 1-5").unwrap()

let is_match = expr.matches(
  minute = 15,
  hour = 9,
  day_of_month = 10,
  month = 6,
  day_of_week = 3
)
// true

getting next execution time:

let expr = @cron.parse("@hourly").unwrap()
let current_time = { year: 2026, month: 6, day: 10, hour: 9, minute: 14 }
let next_trigger = expr.next_time(current_time).unwrap()
// 10:00

dev

run tests:

moon test

license

Apache 2.0

关于

核心解析引擎 (Parser): 接收如 */5 * * * *、0 12 * * 1-5 这样标准的 Cron 字符串,能够识别星号(*)、列表(,)、范围(-)和步长(/)等特殊语法,并转化为计算机可高效读取的内部结构。 调度验证器 (Matcher): 提供一个核心方法:输入任意一个指定的时间点(年、月、日、时、分),系统能够迅速判断该时间是否被当前的 Cron 规则所命中(即:是否应该触发

946.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号