6tail / lunar-go

日历、公历(阳历)、农历(阴历、老黄历)、道历、佛历,支持节假日、星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道黑道日及吉凶等。lunar is a calendar library for Solar and Chinese Lunar.
https://6tail.cn/calendar/api.html
MIT License
215 stars 57 forks source link

身宫计算问题 #17

Open orzmoe opened 5 months ago

orzmoe commented 5 months ago
func (eightChar *EightChar) GetShenGong() string {
    monthZhiIndex := 0
    timeZhiIndex := 0
    size := len(MONTH_ZHI)
    for i := 0; i < size; i++ {
        zhi := MONTH_ZHI[i]
        if strings.Compare(eightChar.GetMonthZhi(), zhi) == 0 {
            monthZhiIndex = i
        }
        if strings.Compare(eightChar.GetTimeZhi(), zhi) == 0 {
            timeZhiIndex = i
        }
    }
    zhiIndex := 2 + monthZhiIndex + timeZhiIndex
    if zhiIndex > 12 {
        zhiIndex -= 12
    }
    jiaZiIndex := LunarUtil.GetJiaZiIndex(eightChar.lunar.GetMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex)
    if jiaZiIndex >= 60 {
        jiaZiIndex -= 60
    }
    if jiaZiIndex < 0 {
        jiaZiIndex += 60
    }
    return LunarUtil.JIA_ZI[jiaZiIndex]
}

其中zhiIndex 可能在减去12后还是会大于12的情况比如 1990-01-27 ,会导致身宫计算错误 正确的是 丙寅 目前计算出来的是 戊寅

6tail commented 5 months ago

1990-01-27几点钟?

orzmoe commented 5 months ago

1990-01-27几点钟?

1990-01-27 00:00:00

6tail commented 5 months ago

我验证了,确实应该为丙寅,将在下个版本修复。