目录

MoonCron

MoonCron is a pure MoonBit library and command-line tool for parsing, validating, explaining, and evaluating classic five-field cron expressions.

Project status: early MVP. The core parser and evaluator work, but the public API may still change before the first stable release.

Features

  • Classic five-field syntax: minute, hour, day of month, month, day of week
  • Wildcards, lists, ranges, and steps: *, ,, -, /
  • Month and weekday names such as JAN and MON-FRI
  • Common aliases including @hourly, @daily, @weekly, and @monthly
  • Structured validation errors
  • Time matching and field-jumping next-occurrence calculation
  • Vixie-style day-of-month/day-of-week semantics
  • Timezone-free Gregorian calendar model
  • Bilingual English and Simplified Chinese natural-language explanations
  • CLI commands for validation, explanation, and schedule preview
  • Tests on Wasm, Wasm GC, JavaScript, and native backends

Quick start

Validate an expression:

moon run cmd/main -- check "*/15 9-17 * * MON-FRI"

Explain an expression in English or Simplified Chinese:

moon run cmd/main -- explain "0 9 * * MON-FRI" en
moon run cmd/main -- explain "0 9 * * MON-FRI" zh

Expected output:

Runs at 09:00 on Monday through Friday.
在09:00执行,适用于星期一至星期五。

List the next three matching times after a civil date-time:

moon run cmd/main -- next "0 9 * * MON-FRI" 2026-08-08T12:00 3

Expected output:

2026-08-10 09:00
2026-08-11 09:00
2026-08-12 09:00

Library example

///|
test "README example" {
  let schedule = parse("*/30 9-17 * * MON-FRI").unwrap()
  let start : CivilDateTime = {
    year: 2026,
    month: 8,
    day: 10,
    hour: 8,
    minute: 45,
  }
  inspect(schedule.next_after(start).unwrap().to_string(), content="2026-08-10 09:00")
  assert_eq(
    schedule.explain_en(),
    "Runs every 30 minutes during hours 9 through 17 on Monday through Friday.",
  )
  assert_eq(
    schedule.explain_zh(),
    "在9时至17时期间每30分钟执行,适用于星期一至星期五。",
  )
}

Supported syntax

Feature Example Status
Wildcard * * * * * Supported
List 0 9,12,18 * * * Supported
Range 0 9-17 * * * Supported
Step */15 * * * * Supported
Named month 0 0 1 JAN * Supported
Named weekday 0 9 * * MON-FRI Supported
Aliases @daily Supported
Seconds field 0 */5 * * * * Not supported
Quartz modifiers L, W, #, ? Not supported
Time zones / DST IANA zone names Not supported in the core MVP

See docs/compatibility.md for precise cron semantics and docs/explanations.md for explanation behavior.

next_after skips disallowed months, calendar days, hours, and minutes instead of scanning every civil minute. The optional search_limit_minutes argument remains an exact bound on civil-minute distance, including for sparse annual schedules.

Development

moon fmt --check
moon check --target all --deny-warn
moon test --target all --deny-warn
moon info

Run the standalone example:

moon run examples/basic

Roadmap

  • Add richer source-span diagnostics
  • Add deterministic cross-implementation test vectors
  • Add a small WebAssembly playground
  • Publish the package to mooncakes.io after API review

License

Apache-2.0. See LICENSE.

关于

使用纯 MoonBit 实现的 Cron 表达式解析、校验、自然语言解释和执行时间计算工具,支持中英文解释及 Wasm、Wasm GC、JavaScript、Native 多后端。

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

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