MoonBit IANA 时区库 — 597 时区 + DST 三分支 + Hinnant civil↔days + RFC3339 + strftime/strptime,移植自 Rust chrono-tz 0.11.0
# moon.mod
import {
"walkzzz/chrono_tz-mbt/tz" @tz,
}let tz = @tz.Tz::from_str("Asia/Shanghai").unwrap()
let naive = @tz.NaiveDateTime::from_timestamp(0L)
let utc_tz = @tz.Tz::from_str("UTC").unwrap()
let off = utc_tz.offset_from_utc_date_time(naive)
let dt = @tz.DateTime::make(0L, off)
let shanghai_dt = dt.with_timezone(tz)
println(shanghai_dt.to_rfc3339()) // 1970-01-01T08:00:00+08:00enum LocalResult[T] {
Single(T) // Normal — 唯一解
Ambiguous(T, T) // 秋季回拨 — 两个解
None // 春季前跳 — 无解
}moon check # 类型检查(0 warnings)
moon test --target native # 运行测试(201 个,native target)
moon info && moon fmt # 更新接口 + 格式化注:WASM target 有 597 match arm local count 限制,需用 --target native。
Install
Download zipMoonBit IANA 时区库 — 597 时区 + DST 三分支 + Hinnant civil↔days + RFC3339 + strftime/strptime,移植自 Rust chrono-tz 0.11.0