From d479d39352c6fb44902b75ccef3a9230577c3d72 Mon Sep 17 00:00:00 2001 From: Starainrt Date: Tue, 16 Jan 2024 11:30:53 +0800 Subject: [PATCH] update --- basic/sun.go | 1 - basic/sun_test.go | 67 +++++++++++++++++++++++++++++++++++++++++++++ calendar/chinese.go | 7 ++--- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/basic/sun.go b/basic/sun.go index 876bc03..abcdde4 100644 --- a/basic/sun.go +++ b/basic/sun.go @@ -101,7 +101,6 @@ func SunMidFun(JD float64) float64 { //'太阳中间方程 return SunMidFun } func SunTrueLo(JD float64) float64 { // '太阳真黄经 - SunTrueLo := SunLo(JD) + SunMidFun(JD) return SunTrueLo } diff --git a/basic/sun_test.go b/basic/sun_test.go index 90c62bb..8d2353a 100644 --- a/basic/sun_test.go +++ b/basic/sun_test.go @@ -153,3 +153,70 @@ func Test_SunAz(t *testing.T) { fmt.Println(SunAngle(Date2JDE(time.Date(2022, 5, 30, 11, 55, 0, 0, cst)), 120, 30, 8.0)) } + +func TestJQDate(t *testing.T) { + trimDay := func(d float64) float64 { + if d-math.Floor(d) < 0.5 { + return math.Floor(d) - 0.5 + } + return math.Floor(d) + 0.5 + } + c := 0 + for year := 1900; year <= 2600; year++ { + for pos := 0; pos < 360; pos += 15 { + n := newGetJQTime(year, pos) + o := GetJQTime(year, pos) + if trimDay(n) != trimDay(o) { + c++ + fmt.Printf("\"%d%03d\":%.0f,", year, pos, trimDay(o)-trimDay(n)) + } + } + } + fmt.Println(c) +} + +func newGetJQTime(Year, Angle int) float64 { //节气时间 + var j int = 1 + var Day int + var tp float64 + if Angle%2 == 0 { + Day = 18 + } else { + Day = 3 + } + if Angle%10 != 0 { + tp = float64(Angle+15.0) / 30.0 + } else { + tp = float64(Angle) / 30.0 + } + Month := 3 + tp + if Month > 12 { + Month -= 12 + } + JD1 := JDECalc(int(Year), int(Month), float64(Day)) + if Angle == 0 { + Angle = 360 + } + for i := 0; i < j; i++ { + for { + JD0 := JD1 + stDegree := newJQLospec(JD0) - float64(Angle) + stDegreep := (newJQLospec(JD0+0.000005) - newJQLospec(JD0-0.000005)) / 0.00001 + JD1 = JD0 - stDegree/stDegreep + if math.Abs(JD1-JD0) <= 0.00001 { + break + } + } + JD1 -= 0.001 + } + JD1 += 0.001 + return JD1 - 0.0046296296296296 +} + +func newJQLospec(JD float64) float64 { + t := tools.FloatRound(SunApparentLo(JD), 9) + if t <= 12 { + t += 360 + } + return t +} diff --git a/calendar/chinese.go b/calendar/chinese.go index d9f2356..d7fdb32 100644 --- a/calendar/chinese.go +++ b/calendar/chinese.go @@ -166,8 +166,7 @@ recalc: strday := []string{"初", "十", "廿", "三"} for i := 0; i < 13; i++ { var dayofLunar = 29 - tmp := uint8(magic&0x3FFE>>(13-i)) & 1 - if tmp == 1 { + if uint8(magic&0x3FFE>>(13-i))&1 == 1 { dayofLunar++ } if totalDay+dayofLunar > diffDay { @@ -222,10 +221,8 @@ func rapidSolar(year, month, day int, isLeap bool) time.Time { target := spring.AddDate(0, 0, totalDay+day-1) return target } - var dayofLunar = 29 - tmp := uint8(magic&0x3FFE>>(13-i)) & 1 - if tmp == 1 { + if uint8(magic&0x3FFE>>(13-i))&1 == 1 { dayofLunar++ } totalDay += dayofLunar