1.修正:农历年返回不正确的问题
This commit is contained in:
parent
b865e64fa9
commit
9f688024e8
@ -336,10 +336,11 @@ func Date2JDE(date time.Time) float64 {
|
|||||||
return JDECalc(date.Year(), int(date.Month()), day)
|
return JDECalc(date.Year(), int(date.Month()), day)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLunar(year, month, day int, tz float64) (adjustedYear, lmonth, lday int, leap bool, result string) {
|
func GetLunar(year, month, day int, tz float64) (lyear, lmonth, lday int, leap bool, result string) {
|
||||||
julianDayEpoch := JDECalc(year, month, float64(day))
|
julianDayEpoch := JDECalc(year, month, float64(day))
|
||||||
// 确定农历年份
|
// 确定农历年份
|
||||||
adjustedYear = year
|
lyear = year
|
||||||
|
adjustedYear := year
|
||||||
if month == 11 || month == 12 {
|
if month == 11 || month == 12 {
|
||||||
winterSolsticeDay := GetJQTime(year, 270) + tz
|
winterSolsticeDay := GetJQTime(year, 270) + tz
|
||||||
firstNewMoonDay := TD2UT(CalcMoonS(float64(year)+11.0/12.0+5.0/30.0/12.0, 0), true) + tz
|
firstNewMoonDay := TD2UT(CalcMoonS(float64(year)+11.0/12.0+5.0/30.0/12.0, 0), true) + tz
|
||||||
@ -434,7 +435,9 @@ func GetLunar(year, month, day int, tz float64) (adjustedYear, lmonth, lday int,
|
|||||||
|
|
||||||
// 生成农历日期字符串
|
// 生成农历日期字符串
|
||||||
result = formatLunarDateString(lmonth, lday, leap)
|
result = formatLunarDateString(lmonth, lday, leap)
|
||||||
|
if lmonth >= 10 && month < 3 {
|
||||||
|
lyear--
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,8 @@ func Test_ChineseCalendarModern(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, v := range testData {
|
for _, v := range testData {
|
||||||
{
|
{
|
||||||
var lyear int = v.Year
|
lyear, lmonth, lday, leap, desp := Lunar(v.Year, v.Month, v.Day, 8.0)
|
||||||
_, lmonth, lday, leap, desp := Lunar(v.Year, v.Month, v.Day, 8.0)
|
|
||||||
if lmonth > v.Month {
|
|
||||||
lyear--
|
|
||||||
}
|
|
||||||
fmt.Println(lyear, desp, v.Year, v.Month, v.Day)
|
fmt.Println(lyear, desp, v.Year, v.Month, v.Day)
|
||||||
if lyear != v.Lyear || lmonth != v.Lmonth || lday != v.Lday || leap != v.Leap {
|
if lyear != v.Lyear || lmonth != v.Lmonth || lday != v.Lday || leap != v.Leap {
|
||||||
t.Fatal(v, lyear, lmonth, lday, leap, desp)
|
t.Fatal(v, lyear, lmonth, lday, leap, desp)
|
||||||
@ -241,12 +238,12 @@ func Test_ChineseCalendarAncient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGanZhiOfDay(t *testing.T) {
|
func TestGanZhiOfDay(t *testing.T) {
|
||||||
dates := time.Date(1083, 11, 24, 0, 0, 0, 0, getCst())
|
dates := time.Date(2025, 1, 24, 0, 0, 0, 0, getCst())
|
||||||
fmt.Println(dates.Weekday())
|
fmt.Println(dates.Weekday())
|
||||||
jde := Date2JDE(dates)
|
jde := Date2JDE(dates)
|
||||||
fmt.Println(int(jde+1.5) % 7)
|
fmt.Println(int(jde+1.5) % 7)
|
||||||
d, _ := SolarToLunar(dates)
|
y, _, _, _, desc := Lunar(dates.Year(), int(dates.Month()), dates.Day(), 8.0)
|
||||||
fmt.Println(d.LunarInfo())
|
fmt.Println(y, desc)
|
||||||
//date, err := LunarToSolar("久视元年腊月辛亥")
|
//date, err := LunarToSolar("久视元年腊月辛亥")
|
||||||
date, err := LunarToSolar("2025年闰6月1日")
|
date, err := LunarToSolar("2025年闰6月1日")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user