///|
fn event_text(event : @sun.Instant?) -> String {
match event {
Some(t) => t.to_iso_utc()
None => "这个 UTC 日没有该事件"
}
}
///|
fn report(date : @sun.Instant, site : @sun.Observer) -> String {
let p = @sun.moon_position(date, site)
let light = @sun.moon_illumination(date)
let t = @sun.moon_times(date, site)
let direction = if light.waxing { "盈月" } else { "亏月" }
let visibility = if p.altitude > 0.0 {
"月球视中心在地平线上方"
} else {
"月球视中心在地平线下方"
}
let state = match t.state {
Crosses => "当日有升/落事件"
AlwaysAbove => "当日始终在升落阈值上方"
AlwaysBelow => "当日始终在升落阈值下方"
}
"时刻:" +
date.to_iso_utc() +
"\n" +
"方位角(北起顺时针):" +
p.azimuth.to_string() +
"°\n" +
"视高度角:" +
p.altitude.to_string() +
"°," +
visibility +
"\n" +
"地心距离:" +
p.distance.to_string() +
" km\n" +
"照明比例:" +
light.fraction.to_string() +
";连续月相:" +
light.phase.to_string() +
"(" +
direction +
")\n" +
"亮边相对天顶角:" +
(light.angle - p.parallactic_angle).to_string() +
"°\n" +
"月升:" +
event_text(t.rise) +
"\n月落:" +
event_text(t.set) +
"\n" +
state +
"\n"
}
///|
fn main {
println("上海观月查询:2026-09-14 10:00 UTC(当地 18:00)")
println(
report(
@sun.utc(2026, 9, 14, hour=10).unwrap(),
@sun.observer(31.23, 121.47).unwrap(),
),
)
println("高纬对照:2022-01-14,78°N 78°E")
println(
report(
@sun.utc(2022, 1, 14, hour=12).unwrap(),
@sun.observer(78.0, 78.0).unwrap(),
),
)
println(
"升落扫描窗口是 UTC 00:00—24:00,不是上海民用日。照明比例不是能见度,也不表示天气。",
)
}