bug fix:timezone error

master
兔子 3 years ago
parent a9135de034
commit 407a63502b

@ -169,7 +169,7 @@ func JDE2Date(JD float64) time.Time {
return dates
}
func JDE2DateByZone(JD float64, tz *time.Location) time.Time {
func JDE2DateByZone(JD float64, tz *time.Location, byZone bool) time.Time {
JD = JD + 0.5
Z := float64(int(JD))
F := JD - Z
@ -199,9 +199,12 @@ func JDE2DateByZone(JD float64, tz *time.Location) time.Time {
}
tms := (Days - math.Floor(Days)) * 24 * 3600
Days = math.Floor(Days)
dates := time.Date(int(Years), time.Month(int(Months)), int(Days), 0, 0, 0, 0, time.UTC)
dates = time.Unix(dates.Unix()+int64(tms), int64((tms-math.Floor(tms))*1000000000)).In(tz)
return dates
if !byZone {
dates := time.Date(int(Years), time.Month(int(Months)), int(Days), 0, 0, 0, 0, time.UTC)
return time.Unix(dates.Unix()+int64(tms), int64((tms-math.Floor(tms))*1000000000)).In(tz)
}
dates := time.Date(int(Years), time.Month(int(Months)), int(Days), 0, 0, 0, 0, tz)
return time.Unix(dates.Unix()+int64(tms), int64((tms-math.Floor(tms))*1000000000))
}
func GetLunar(year, month, day int) (lmonth, lday int, leap bool, result string) {

@ -1402,7 +1402,8 @@ 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 - ntz/24 + TZ/24 //求0时JDE
JDZ := math.Floor(JD) + 0.5
JD = math.Floor(JD) + 0.5 - ntz/24 + TZ/24.0 //求0时JDE
JD1 := JD
moonheight := MoonHeight(JD, Lon, Lat, TZ) //求此时月亮高度
if ZS != 0 {
@ -1453,7 +1454,7 @@ func GetMoonRiseTime(JD, Lon, Lat, TZ, ZS float64) float64 {
}
JD1 = JD1 - TZ/24 + ntz/24
if JD1 > JD+1 || JD1 < JD {
if JD1 > JDZ+1 || JD1 < JDZ {
return -3 //明日
} else {
return JD1
@ -1464,6 +1465,7 @@ func GetMoonDownTime(JD, Lon, Lat, TZ, ZS float64) float64 {
ntz := TZ
TZ = Lon / 15
var An, tms float64 = 0, 0
JDZ := math.Floor(JD) + 0.5
JD = math.Floor(JD) + 0.5 - ntz/24 + TZ/24 //求0时JDE
JD1 := JD
moonheight := MoonHeight(JD, Lon, Lat, TZ) //求此时月亮高度
@ -1511,7 +1513,7 @@ func GetMoonDownTime(JD, Lon, Lat, TZ, ZS float64) float64 {
}
}
JD1 = JD1 - TZ/24 + ntz/24
if JD1 > JD+1 || JD1 < JD {
if JD1 > JDZ+1 || JD1 < JDZ {
return -3 //明日
} else {
return JD1

@ -57,7 +57,7 @@ func ChineseLunar(date time.Time) (int, int, bool, string) {
func Solar(year, month, day int, leap bool) time.Time {
jde := basic.GetSolar(year, month, day, leap)
zone := time.FixedZone("CST", 8*3600)
return basic.JDE2DateByZone(jde, zone).Add(time.Hour * -8)
return basic.JDE2DateByZone(jde, zone, true)
}
// GanZhi 返回传入年份对应的干支
@ -69,12 +69,12 @@ func GanZhi(year int) string {
func JieQi(year, term int) time.Time {
calcJde := basic.GetJQTime(year, term)
zone := time.FixedZone("CST", 8*3600)
return basic.JDE2DateByZone(calcJde, zone)
return basic.JDE2DateByZone(calcJde, zone, false)
}
// WuHou 返回传入年份、物候对应的北京时间物候时间
func WuHou(year, term int) time.Time {
calcJde := basic.GetWHTime(year, term)
zone := time.FixedZone("CST", 8*3600)
return basic.JDE2DateByZone(calcJde, zone)
return basic.JDE2DateByZone(calcJde, zone, false)
}

@ -0,0 +1,11 @@
package calendar
import (
"fmt"
"testing"
)
func Test_Solar(t *testing.T) {
fmt.Println(Solar(2021, 1, 1, false))
fmt.Println(Solar(2020, 1, 1, false))
}

@ -111,6 +111,9 @@ func CulminationTime(date time.Time, lon, lat float64) float64 {
// lat纬度北正南负
func RiseTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
var err error
if date.Hour() > 12 {
date = date.Add(time.Hour * -12)
}
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
@ -128,7 +131,7 @@ func RiseTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
if riseJde == -1 {
err = ERR_MOON_NEVER_DOWN
}
return basic.JDE2Date(riseJde), err
return basic.JDE2DateByZone(riseJde, date.Location(), true), err
}
// DownTime 月亮降下时间
@ -137,6 +140,9 @@ func RiseTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
// lat纬度北正南负
func DownTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
var err error
if date.Hour() > 12 {
date = date.Add(time.Hour * -12)
}
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
@ -154,7 +160,7 @@ func DownTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
if downJde == -1 {
err = ERR_MOON_NEVER_DOWN
}
return basic.JDE2Date(downJde), err
return basic.JDE2DateByZone(downJde, date.Location(), true), err
}
// Phase 月相
@ -167,25 +173,25 @@ func Phase(date time.Time) float64 {
// ShuoYue 朔月
func ShuoYue(year float64) time.Time {
jde := basic.TD2UT(basic.CalcMoonSH(year, 0), false)
return basic.JDE2DateByZone(jde, time.UTC)
return basic.JDE2DateByZone(jde, time.UTC, false)
}
// WangYue 望月
func WangYue(year float64) time.Time {
jde := basic.TD2UT(basic.CalcMoonSH(year, 1), false)
return basic.JDE2DateByZone(jde, time.UTC)
return basic.JDE2DateByZone(jde, time.UTC, false)
}
// ShangXianYue 上弦月
func ShangXianYue(year float64) time.Time {
jde := basic.TD2UT(basic.CalcMoonXH(year, 0), false)
return basic.JDE2DateByZone(jde, time.UTC)
return basic.JDE2DateByZone(jde, time.UTC, false)
}
// XiaXianYue 下弦月
func XiaXianYue(year float64) time.Time {
jde := basic.TD2UT(basic.CalcMoonXH(year, 1), false)
return basic.JDE2DateByZone(jde, time.UTC)
return basic.JDE2DateByZone(jde, time.UTC, false)
}
// EarthDistance 日地距离

@ -3,12 +3,9 @@ package moon
import (
"fmt"
"testing"
"time"
)
func TestMoonI(t *testing.T) {
fmt.Println(MoonR(2465445.9755443))
}
func Test_NewCalc(t *testing.T) {
fmt.Printf("%.14f", MoonCalcNew(2, 2451546.0))
func Test_Rise(t *testing.T) {
fmt.Println(RiseTime(time.Now(), 115, 32, true))
}

@ -34,6 +34,9 @@ func RiseTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
if aero {
aeroFloat = 1
}
if date.Hour() > 12 {
date = date.Add(time.Hour * -12)
}
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
@ -44,7 +47,7 @@ func RiseTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
if riseJde == -1 {
err = ERR_SUN_NEVER_DOWN
}
return basic.JDE2Date(riseJde), err
return basic.JDE2DateByZone(riseJde, date.Location(), true), err
}
// SunDownTime 太阳落下时间
@ -58,6 +61,9 @@ func DownTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
if aero {
aeroFloat = 1
}
if date.Hour() > 12 {
date = date.Add(time.Hour * -12)
}
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
@ -68,7 +74,7 @@ func DownTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
if downJde == -1 {
err = ERR_SUN_NEVER_DOWN
}
return basic.JDE2Date(downJde), err
return basic.JDE2DateByZone(downJde, date.Location(), true), err
}
// MorningTwilight 晨朦影
@ -249,7 +255,7 @@ func CulminationTime(date time.Time, lon float64) time.Time {
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
calcJde := basic.GetSunTZTime(jde, lon, timezone) - timezone/24.00
return basic.JDE2DateByZone(calcJde, date.Location())
return basic.JDE2DateByZone(calcJde, date.Location(), false)
}
// EarthDistance 日地距离

Loading…
Cancel
Save