From b0920d327c73b7f5e8a29a79aa5cee317c759642 Mon Sep 17 00:00:00 2001 From: starainrt Date: Tue, 31 Dec 2024 13:52:59 +0800 Subject: [PATCH] =?UTF-8?q?bug=20fix:=E8=85=8A=E6=9C=88=E5=8D=81=E4=BA=8C?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=BA=E6=AD=A3=E6=9C=88=E5=88=9D=E4=B8=80?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calendar/chinese.go | 2 +- calendar/chinese_test.go | 41 +++++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/calendar/chinese.go b/calendar/chinese.go index d7fdb32..7e96913 100644 --- a/calendar/chinese.go +++ b/calendar/chinese.go @@ -143,7 +143,7 @@ recalc: magic := int32(upper[idx])<<8 + int32(lower[idx]) springMonth := (magic&0x800000)>>23 + 1 springDay := (magic & 0x7FFFFF) >> 18 - if springMonth == int32(month) && springDay == int32(day) { + if !useGoto && springMonth == int32(month) && springDay == int32(day) { return 1, 1, false, "正月初一" } if !useGoto && (springMonth > int32(month) || (springMonth == int32(month) && springDay > int32(day))) { diff --git a/calendar/chinese_test.go b/calendar/chinese_test.go index 18f9ae4..f89ff90 100644 --- a/calendar/chinese_test.go +++ b/calendar/chinese_test.go @@ -18,6 +18,7 @@ type lunarSolar struct { func Test_ChineseCalendar(t *testing.T) { var testData = []lunarSolar{ + {Lyear: 1995, Lmonth: 12, Lday: 12, Leap: false, Year: 1996, Month: 1, Day: 31}, {Lyear: 2034, Lmonth: 1, Lday: 1, Leap: false, Year: 2034, Month: 2, Day: 19}, {Lyear: 2033, Lmonth: 12, Lday: 30, Leap: false, Year: 2034, Month: 2, Day: 18}, {Lyear: 2033, Lmonth: 11, Lday: 27, Leap: true, Year: 2034, Month: 1, Day: 17}, @@ -37,19 +38,37 @@ func Test_ChineseCalendar(t *testing.T) { {Lyear: 2021, Lmonth: 12, Lday: 29, Leap: false, Year: 2022, Month: 1, Day: 31}, } for _, v := range testData { - var lyear int = v.Year - lmonth, lday, leap, desp := SolarToLunar(time.Date(v.Year, time.Month(v.Month), v.Day, 0, 0, 0, 0, time.Local)) - if lmonth > v.Month { - lyear-- - } - fmt.Println(lyear, desp, v.Year, v.Month, v.Day) - if lyear != v.Lyear || lmonth != v.Lmonth || lday != v.Lday || leap != v.Leap { - t.Fatal(v, lyear, lmonth, lday, leap, desp) + { + var lyear int = v.Year + lmonth, lday, leap, desp := SolarToLunar(time.Date(v.Year, time.Month(v.Month), v.Day, 0, 0, 0, 0, time.Local)) + if lmonth > v.Month { + lyear-- + } + fmt.Println(lyear, desp, v.Year, v.Month, v.Day) + if lyear != v.Lyear || lmonth != v.Lmonth || lday != v.Lday || leap != v.Leap { + t.Fatal(v, lyear, lmonth, lday, leap, desp) + } + + date := LunarToSolar(v.Lyear, v.Lmonth, v.Lday, v.Leap) + if date.Year() != v.Year || int(date.Month()) != v.Month || date.Day() != v.Day { + t.Fatal(v, date) + } } + { + var lyear int = v.Year + lmonth, lday, leap, desp := RapidSolarToLunar(time.Date(v.Year, time.Month(v.Month), v.Day, 0, 0, 0, 0, time.Local)) + if lmonth > v.Month { + lyear-- + } + fmt.Println(lyear, desp, v.Year, v.Month, v.Day) + if lyear != v.Lyear || lmonth != v.Lmonth || lday != v.Lday || leap != v.Leap { + t.Fatal(v, lyear, lmonth, lday, leap, desp) + } - date := LunarToSolar(v.Lyear, v.Lmonth, v.Lday, v.Leap) - if date.Year() != v.Year || int(date.Month()) != v.Month || date.Day() != v.Day { - t.Fatal(v, date) + date := RapidLunarToSolar(v.Lyear, v.Lmonth, v.Lday, v.Leap) + if date.Year() != v.Year || int(date.Month()) != v.Month || date.Day() != v.Day { + t.Fatal(v, date) + } } } }