A pure MoonBit astronomical calculations library: Julian dates, sunrise/sunset, solar position, twilight, golden hour and moon phases.
moon add jiujitong/skycal// Sunrise/sunset for Beijing on the 2026 summer solstice
let pos = @skycal.make_geo(39.9042, 116.4074)
match @skycal.sun_times(2026, 6, 21, pos) {
Some(times) => {
println(@skycal.jd_to_local_string(times.get_sunrise(), 8.0)) // 2026-06-21 04:46
println(@skycal.format_minutes(times.daylight_minutes())) // 15h 00m
}
None => println("polar day or night")
}
// Moon phase right now
let moon = @skycal.moon_phase(@skycal.julian_date(2026, 11, 23, 12, 0, 0))
println(moon.get_phase().name()) // e.g. "Waxing Gibbous"
println(moon.get_illumination()) // 0..1
// Moonrise / moonset / transit (10-min scan + interpolation)
match @skycal.moon_times(2026, 11, 23, pos) {
Some(mt) => println(@skycal.jd_to_local_string(mt.get_transit(), 8.0))
None => ()
}
// 24 solar terms for a year
for term in @skycal.solar_terms(2026) {
println(term.get_index()) // 0 = 春分 (March equinox), 23 = 惊蛰
}
// Planetary position (Jupiter tonight)
let jup = @skycal.planet_altaz(@skycal.jupiter(), jd, pos)
println(jup.0) // altitude, degrees
// Golden hour (photography): sun between -6° and +6°
match @skycal.golden_hours(2026, 6, 21, pos) {
Some(g) => println(@skycal.jd_to_local_string(g.get_evening_start(), 8.0))
None => ()
}moon run cmd/main # worked example (Beijing, 2026-06-21)
moon run cmd/main -- 35.6762 139.6503 9 2026 12 21 # Tokyo winter solstice| Quantity | Accuracy | Notes |
|---|---|---|
| Solar declination / altitude | ±0.03° | NOAA low-precision equations, valid 1900-2100 |
| Sunrise / sunset | ±2 min | vs USNO published tables (see tests) |
| Sunrise / sunset (precise) | ±0.5 min | iterative variant, event-time solar parameters |
| Equation of time | ±0.1 min | |
| Moon illumination | ~1% | Meeus truncated series |
| Moon phase timing | ~1 hour | |
| Moon ecliptic position | ~0.3° / ~0.01° / ~500 km | longitude / latitude / distance (Meeus dominant terms) |
| Moonrise / moonset | ±5 min | 10-min scan + linear interpolation |
| 24 solar terms | ±1 min | apparent-longitude bisection |
| Planet geocentric position | ~0.5° | JPL mean elements + light-time, 1800-2050 |
| GMST | ~0.1 s | Meeus 12.4 polynomial |
moon check --deny-warn # zero warnings policy
moon test # 65 deterministic tests
moon fmt && moon info # format + refresh interface
moon run cmd/main # CLI demolet pos = @skycal.make_geo(39.9042, 116.4074) // 北京
match @skycal.sun_times(2026, 6, 21, pos) {
Some(t) => println(@skycal.jd_to_local_string(t.get_sunrise(), 8.0)) // 2026-06-21 04:46
None => println("polar day or night")
}pub struct GoldenHours {
morning_start : Double
morning_end : Double
evening_start : Double
evening_end : Double
}pub struct MoonPhase {
elongation : Double
phase_angle : Double
illumination : Double
age_days : Double
phase : Phase
}pub struct MoonPosition {
longitude : Double
latitude : Double
distance : Double
right_ascension : Double
declination : Double
}pub struct MoonTimes {
moonrise : Double?
moonset : Double?
transit : Double
}pub enum Phase {
NewMoon
WaxingCrescent
FirstQuarter
WaxingGibbous
FullMoon
WaningGibbous
LastQuarter
WaningCrescent
}pub struct PlanetPosition {
right_ascension : Double
declination : Double
distance : Double
longitude : Double
}pub struct SolarTerm {
index : Int
jd : Double
}pub struct SunPosition {
altitude : Double
azimuth : Double
declination : Double
right_ascension : Double
}pub struct SunTimes {
sunrise : Double
sunset : Double
solar_noon : Double
}pub struct YearDaylight {
total_hours : Double
longest_day : Double
longest_date : (Int, Int)
shortest_day : Double
shortest_date : (Int, Int)
polar_night_days : Int
polar_day_days : Int
}fn ecliptic_to_equatorial(lon : Double, lat : Double, jd : Double) -> (Double, Double)fn equatorial_to_horizontal(ra : Double, dec : Double, jd : Double, pos : GeoPos) -> (Double, Double)fn horizontal_to_equatorial(alt : Double, az : Double, jd : Double, pos : GeoPos) -> (Double, Double)fn julian_date(year : Int, month : Int, day : Int, hour : Int, minute : Int, second : Int) -> Doublefn to_unix_seconds(year : Int, month : Int, day : Int, hour : Int, minute : Int, second : Int) -> DoubleInstall
Download zipA pure MoonBit astronomical calculations library: Julian dates, sunrise/sunset, solar position, twilight, golden hour and moon phases.