目录

Cron-Mbt

MoonBit CI MoonBit License

Cron-Mbt is a MoonBit cron expression library with a real parser, deterministic matcher, next-trigger calculator, and a usable CLI. The repository is being hardened for the MoonBit OSC2026 acceptance checklist, so the focus is on runnable examples, CI completeness, source clarity, and publish readiness rather than marketing-heavy claims.

What It Supports

  • Standard 5-field cron expressions: minute, hour, day-of-month, month, day-of-week.
  • Core operators: *, ?, ,, -, /, and L for the last day of month. L is accepted only in the day-of-month field; invalid placements return Err.
  • Macro aliases: @yearly, @annually, @monthly, @weekly, @daily, @midnight, @hourly.
  • Day matching semantics aligned with common cron behavior: when both day-of-month and day-of-week are constrained, either side may satisfy the schedule.
  • Sunday normalization for both 0 and 7.
  • A CLI that can parse expressions, check matches, and compute the next trigger time.

Why This Revision Matters

The organizer feedback highlighted several concrete gaps:

  • deprecated warnings blocked moon info / moon fmt style checks
  • CI did not cover the required check/build/fmt/info/test stages
  • the CLI was mostly a placeholder
  • the next-trigger logic was still minute-by-minute brute force and missed weekday constraints
  • Mooncakes metadata was incomplete

This revision addresses those issues directly.

Project Layout

src/cron/   core parser, matcher, scheduler, tests
src/cli/    command-line interface
docs/       architecture, API reference, acceptance notes, source notes
scripts/    validation and helper scripts
.github/    GitHub Actions workflow

Installation

Add the module to moon.mod:

[deps]
"cxh04/cron_mbt" = "0.2.1"

Library Usage

Parse and inspect an expression:

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

Check whether a timestamp matches:

let matched = expr.matches(
  year = 2026,
  minute = 15,
  hour = 9,
  day_of_month = 10,
  month = 6,
  day_of_week = 3,
)

Compute the next trigger time:

let expr = @cron.parse("30 9 * * 1").unwrap()
let current = {
  year: 2026,
  month: 6,
  day: 9,
  hour: 10,
  minute: 0,
}
let next = expr.next_time(current).unwrap()
// 2026-06-15 09:30

CLI Usage

Parse:

moon run src/cli parse "0 9 ? * 1-5"

Next trigger:

moon run src/cli next "30 9 * * 1" 2026 6 9 10 0

Match a timestamp:

moon run src/cli match "15 10 * * *" 2026 6 10 10 15 3

Verification

Local checks used during this hardening pass:

moon check --deny-warn
moon build
moon fmt
moon info
moon test --deny-warn
moon run src/cli parse "0 9 ? * 1-5"
moon run src/cli next "30 9 * * 1" 2026 6 9 10 0
pwsh ./scripts/verify_acceptance.ps1

The CI workflow uses the official MoonBit installer, prints moon version --all, and runs moon check --deny-warn, moon build, moon fmt, moon info, and moon test --deny-warn.

Mooncakes Status

  • Module name: cxh04/cron_mbt
  • Manifest version: 0.2.1
  • moon publish --dry-run validates packaging before publication
  • version 0.2.1 contains the OSC2026 acceptance feedback fixes

Documents

License

Apache-2.0

关于

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

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

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