From 08fcbf9f89758608d2f69c8f452cd52a8964db6f Mon Sep 17 00:00:00 2001 From: 兔子 Date: Mon, 4 Nov 2019 19:18:45 +0800 Subject: [PATCH] moon buf fix --- astro.go | 6 ++++++ basic/moon.go | 26 +++++++++++++------------- moon/moon.go | 6 ++++++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/astro.go b/astro.go index 2de4aed..5bfc3f6 100644 --- a/astro.go +++ b/astro.go @@ -148,6 +148,9 @@ func MoonRiseTime(jde, lon, lat, timezone float64, aero bool) (time.Time, error) tz = 1 } tm := basic.GetMoonRiseTime(jde, lon, lat, timezone, tz) + if tm == -3 { + err = errors.New("非今日") + } if tm == -2 { err = errors.New("极夜") } @@ -172,6 +175,9 @@ func MoonDownTime(jde, lon, lat, timezone float64, aero bool) (time.Time, error) tz = 1 } tm := basic.GetMoonDownTime(jde, lon, lat, timezone, tz) + if tm == -3 { + err = errors.New("非今日") + } if tm == -2 { err = errors.New("极夜") } diff --git a/basic/moon.go b/basic/moon.go index e739f75..39b78a7 100644 --- a/basic/moon.go +++ b/basic/moon.go @@ -1402,7 +1402,7 @@ func GetMoonRiseTime(JD, Lon, Lat, TZ, ZS float64) float64 { ntz := TZ TZ = Lon / 15 var An, tms float64 = 0, 0 - JD = math.Floor(JD) + 0.5 //求0时JDE + JD = math.Floor(JD) + 0.5 - ntz/24 + TZ/24 //求0时JDE JD1 := JD moonheight := MoonHeight(JD, Lon, Lat, TZ) //求此时月亮高度 if ZS != 0 { @@ -1415,19 +1415,19 @@ func GetMoonRiseTime(JD, Lon, Lat, TZ, ZS float64) float64 { } else { tms = (180 - moonang) / 15 } - JD1 += (tms/24 + (tms/24*12.0)/15/24) + JD1 += (tms/24 + (tms/24*12.0)/15.0/24.0) } if moonheight < 0 && moonang > 180 { tms = (180 - moonang) / 15 - JD1 += (tms/24 + (tms/24*12.0)/15/24) + JD1 += (tms/24 + (tms/24*12.0)/15.0/24.0) } else if moonheight < 0 && moonang < 180 { tms = (-180 + moonang) / 15 - JD1 += (tms/24 + (tms/24*12.0)/15/24) + JD1 += (tms/24 + (tms/24*12.0)/15.0/24.0) } now := MoonTimeAngle(JD1, Lon, Lat, TZ) if math.Abs(now-180) > 0.5 { - JD1 += (180 - now) * 4 / 60 / 24 + JD1 += (180 - now) * 4.0 / 60.0 / 24.0 } hei := MoonHeight(JD1, Lon, Lat, TZ) if !(hei < -10 && math.Abs(Lat) < 60) { @@ -1464,7 +1464,7 @@ func GetMoonDownTime(JD, Lon, Lat, TZ, ZS float64) float64 { ntz := TZ TZ = Lon / 15 var An, tms float64 = 0, 0 - JD = math.Floor(JD) + 0.5 //求0时JDE + JD = math.Floor(JD) + 0.5 - ntz/24 + TZ/24 //求0时JDE JD1 := JD moonheight := MoonHeight(JD, Lon, Lat, TZ) //求此时月亮高度 if ZS != 0 { @@ -1473,34 +1473,34 @@ func GetMoonDownTime(JD, Lon, Lat, TZ, ZS float64) float64 { moonang := MoonTimeAngle(JD, Lon, Lat, TZ) if moonheight < 0 { //月亮在地平线上或在落下与下中天之间 tms = (360 - moonang) / 15 - JD1 += (tms/24 + (tms/24*12.0)/15/24) + JD1 += (tms/24 + (tms/24.0*12.0)/15.0/24.0) } if moonheight > 0 && moonang < 180 { tms = (-moonang) / 15 - JD1 += (tms/24 + (tms/24*12.0)/15/24) + JD1 += (tms/24.0 + (tms/24.0*12.0)/15.0/24.0) } else if moonheight > 0 { tms = (360 - moonang) / 15 - JD1 += (tms/24 + (tms/24*12.0)/15/24) + JD1 += (tms/24.0 + (tms/24.0*12.0)/15.0/24.0) } now := MoonTimeAngle(JD1, Lon, Lat, TZ) if now < 180 { now += 360 } if math.Abs(now-360) > 0.5 { - JD1 += (360 - now) * 4 / 60 / 24 + JD1 += (360 - now) * 4.0 / 60.0 / 24.0 } hei := MoonHeight(JD1, Lon, Lat, TZ) if !(hei > 10 && math.Abs(Lat) < 60) { if hei < An { return -2 //沉 } - if MoonHeight(JD1+12/24+6/15/24, Lon, Lat, TZ) > An { + if MoonHeight(JD1+12.0/24.0+6.0/15.0/24.0, Lon, Lat, TZ) > An { return -1 //拱 } } dec := MoonSeeDec(JD1, Lon, Lat, TZ) - SJ := (ArcCos(-Tan(Lat) * Tan(dec))) / 15 - JD1 += SJ/24 + SJ/33/15 + SJ := (ArcCos(-Tan(Lat) * Tan(dec))) / 15.0 + JD1 += SJ/24 + SJ/33.0/15.0 for { JD0 := JD1 stDegree := HMoonHeight(JD0, Lon, Lat, TZ) - An diff --git a/moon/moon.go b/moon/moon.go index 8047320..b879760 100644 --- a/moon/moon.go +++ b/moon/moon.go @@ -133,6 +133,9 @@ func RiseTime(jde, lon, lat, timezone float64, aero bool) (float64, error) { tz = 1 } tm := basic.GetMoonRiseTime(jde, lon, lat, timezone, tz) + if tm == -3 { + err = errors.New("非今日") + } if tm == -2 { err = errors.New("极夜") } @@ -157,6 +160,9 @@ func DownTime(jde, lon, lat, timezone float64, aero bool) (float64, error) { tz = 1 } tm := basic.GetMoonDownTime(jde, lon, lat, timezone, tz) + if tm == -3 { + err = errors.New("非今日") + } if tm == -2 { err = errors.New("极夜") }