Pure MoonBit port of SunCalc 2.0.1: solar and lunar observer calculations
moon add Zh666-lab/moonsuncalc@0.1.0moon check --target all --deny-warn
moon test --target wasm-gc
moon run examples/photography --target wasm-gc
moon run examples/solar_track --target wasm-gc
moon run examples/moon_watch --target wasm-gcimport { "Zh666-lab/moonsuncalc" @sun }let date = @sun.utc(2026, 9, 14).unwrap()
let site = @sun.observer(31.23, 121.47).unwrap()
let times = @sun.sun_times(date, site)
match times.event("sunrise") {
Some(time) => println(time.to_iso_utc())
None => println("该太阳日没有日出事件")
}| 示例 | 输入与处理 | 可检查的输出 |
|---|---|---|
| 摄影时刻表 | 上海、2026-09-14、20 m 地平线高度,加一个 -4° 自定义事件 | 日出 2026-09-13T21:36:43.120Z;北极圈案例返回极昼而不是无效日期 |
| 太阳轨迹 | 上海 UTC 日内每 10 分钟批量采样,144 点 | CSV;样本最高点 03:50Z,视高度约 62.2024°;与求解中天区分 |
| 月亮观察 | 上海 2026-09-14T10:00Z,计算位置、照明及升落 | 视高度约 16.6636°、照明比例约 11.9448%;包含上游极区问题回归 |
python tools/verify.py
# Windows 没有 Moon 可用的系统 C 编译器时,仅显式跳过 native 执行;仍做 native 严格检查:
python tools/verify.py --defer-nativepub(all) struct Observation {
time : Instant
sun : Position
moon : MoonPosition
illumination : Illumination
} derive(Eq, Debug)pub(all) struct SolarEvent {
angle : Double
rise_name : String
set_name : String
rise : Instant?
set : Instant?
state : HorizonState
} derive(Eq, Debug)pub(all) struct SunTimes {
solar_noon : Instant
nadir : Instant
events : Array[SolarEvent]
state : HorizonState
} derive(Eq, Debug)fn sample_observations(start : Instant, step_ms : Double, count : Int, site : Observer) -> Result[Array[Observation], InputError]fn solar_angle(angle : Double, rise_name : String, set_name : String) -> Result[SolarAngle, InputError]fn utc(year : Int, month : Int, day : Int, hour? : Int, minute? : Int, second? : Int, millisecond? : Int) -> Result[Instant, InputError]Install
Download zipPure MoonBit port of SunCalc 2.0.1: solar and lunar observer calculations