Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
98ff574495
|
|||
|
dadbba7171
|
|||
|
add07bbd85
|
|||
|
27b7e4ab77
|
@@ -1,2 +1,16 @@
|
||||
// Package astro
|
||||
package astro
|
||||
|
||||
import "b612.me/astro/basic"
|
||||
|
||||
func DeltaT() func(float64, bool) float64 {
|
||||
return basic.GetDeltaTFn()
|
||||
}
|
||||
|
||||
func SetDeltaT(deltaT func(float64, bool) float64) {
|
||||
basic.SetDeltaTFn(deltaT)
|
||||
}
|
||||
|
||||
func DefaultDeltaT() func(float64, bool) float64 {
|
||||
return basic.DefaultDeltaTv2
|
||||
}
|
||||
|
||||
+28
-24
@@ -240,13 +240,15 @@ func GetLunar(year, month, day int, tz float64) (lyear, lmonth, lday int, leap b
|
||||
adjustedYear := year
|
||||
if month == 11 || month == 12 {
|
||||
winterSolsticeDay := GetJQTime(year, 270) + tz
|
||||
firstNewMoonDay := TD2UT(CalcMoonS(float64(year)+11.0/12.0+5.0/30.0/12.0, 0), true) + tz
|
||||
nextNewMoonDay := TD2UT(CalcMoonS(float64(year)+1.0, 0), true) + tz
|
||||
//firstNewMoonDay := TD2UT(CalcMoonS(float64(year)+11.0/12.0+5.0/30.0/12.0, 0), true) + tz
|
||||
//nextNewMoonDay := TD2UT(CalcMoonS(float64(year)+1.0, 0), true) + tz
|
||||
firstNewMoonDay := TD2UT(CalcMoonSHByJDE(winterSolsticeDay-16, 0), false) + tz
|
||||
nextNewMoonDay := TD2UT(CalcMoonSHByJDE(firstNewMoonDay+28, 0), false) + tz
|
||||
|
||||
firstNewMoonDay = normalizeTimePoint(firstNewMoonDay)
|
||||
nextNewMoonDay = normalizeTimePoint(nextNewMoonDay)
|
||||
|
||||
if winterSolsticeDay >= firstNewMoonDay && winterSolsticeDay < nextNewMoonDay && julianDayEpoch <= firstNewMoonDay {
|
||||
if winterSolsticeDay >= firstNewMoonDay && winterSolsticeDay < nextNewMoonDay && julianDayEpoch < firstNewMoonDay {
|
||||
adjustedYear--
|
||||
}
|
||||
if winterSolsticeDay >= nextNewMoonDay && julianDayEpoch < nextNewMoonDay {
|
||||
@@ -261,8 +263,8 @@ func GetLunar(year, month, day int, tz float64) (lyear, lmonth, lday int, leap b
|
||||
newMoonDays := GetMoonLoops(float64(adjustedYear), 17)
|
||||
|
||||
// 计算冬至日期
|
||||
winterSolsticeFirst := solarTerms[0] - 8.0/24 + tz
|
||||
winterSolsticeSecond := solarTerms[24] - 8.0/24 + tz
|
||||
winterSolsticeFirst := normalizeTimePoint(solarTerms[0] - 8.0/24 + tz)
|
||||
winterSolsticeSecond := normalizeTimePoint(solarTerms[24] - 8.0/24 + tz)
|
||||
|
||||
// 规范化时间点
|
||||
normalizeTimeArray(newMoonDays, tz)
|
||||
@@ -271,8 +273,9 @@ func GetLunar(year, month, day int, tz float64) (lyear, lmonth, lday int, leap b
|
||||
// 计算朔望月范围
|
||||
minMoonIndex, maxMoonIndex := 20, 0
|
||||
moonCount := 0
|
||||
for i := 0; i < 15; i++ {
|
||||
if newMoonDays[i] >= winterSolsticeFirst && newMoonDays[i] < winterSolsticeSecond {
|
||||
for i := 0; i < len(newMoonDays)-1; i++ {
|
||||
if (newMoonDays[i] <= winterSolsticeFirst && newMoonDays[i+1] > winterSolsticeFirst) ||
|
||||
(newMoonDays[i] > winterSolsticeFirst && newMoonDays[i] < winterSolsticeSecond && newMoonDays[i+1] <= winterSolsticeSecond) {
|
||||
if i <= minMoonIndex {
|
||||
minMoonIndex = i
|
||||
}
|
||||
@@ -285,27 +288,27 @@ func GetLunar(year, month, day int, tz float64) (lyear, lmonth, lday int, leap b
|
||||
|
||||
// 确定闰月位置
|
||||
leapMonthPos := 20
|
||||
if moonCount == 13 {
|
||||
solarTermIndex, i := 2, 0
|
||||
if moonCount >= 13 {
|
||||
solarTermIndex, i := 0, 0
|
||||
for i = minMoonIndex; i <= maxMoonIndex; i++ {
|
||||
if !(newMoonDays[i] <= solarTerms[solarTermIndex] && newMoonDays[i+1] > solarTerms[solarTermIndex]) {
|
||||
break
|
||||
}
|
||||
solarTermIndex += 2
|
||||
}
|
||||
leapMonthPos = i - minMoonIndex + 1
|
||||
leapMonthPos = i - minMoonIndex
|
||||
}
|
||||
|
||||
// 找到当前月相索引
|
||||
currentMoonIndex := 0
|
||||
for currentMoonIndex = minMoonIndex - 1; currentMoonIndex <= maxMoonIndex; currentMoonIndex++ {
|
||||
for currentMoonIndex = minMoonIndex; currentMoonIndex <= maxMoonIndex; currentMoonIndex++ {
|
||||
if newMoonDays[currentMoonIndex] > julianDayEpoch {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 计算农历月份
|
||||
lmonth = currentMoonIndex - minMoonIndex
|
||||
lmonth = currentMoonIndex - minMoonIndex - 1
|
||||
shouldAdjustLeap := false
|
||||
leap = false
|
||||
|
||||
@@ -349,8 +352,8 @@ func GetSolar(year, month, day int, leap bool, tz float64) float64 {
|
||||
newMoonDays := GetMoonLoops(float64(adjustedYear), 17)
|
||||
|
||||
// 计算冬至日期
|
||||
winterSolsticeFirst := solarTerms[0] - 8.0/24 + tz
|
||||
winterSolsticeSecond := solarTerms[24] - 8.0/24 + tz
|
||||
winterSolsticeFirst := normalizeTimePoint(solarTerms[0] - 8.0/24 + tz)
|
||||
winterSolsticeSecond := normalizeTimePoint(solarTerms[24] - 8.0/24 + tz)
|
||||
|
||||
// 规范化时间点
|
||||
normalizeTimeArray(newMoonDays, tz)
|
||||
@@ -360,7 +363,8 @@ func GetSolar(year, month, day int, leap bool, tz float64) float64 {
|
||||
minMoonIndex, maxMoonIndex := 20, 0
|
||||
moonCount := 0
|
||||
for i := 0; i < 15; i++ {
|
||||
if newMoonDays[i] >= winterSolsticeFirst && newMoonDays[i] < winterSolsticeSecond {
|
||||
if (newMoonDays[i] <= winterSolsticeFirst && newMoonDays[i+1] > winterSolsticeFirst) ||
|
||||
(newMoonDays[i] > winterSolsticeFirst && newMoonDays[i] < winterSolsticeSecond && newMoonDays[i+1] <= winterSolsticeSecond) {
|
||||
if i <= minMoonIndex {
|
||||
minMoonIndex = i
|
||||
}
|
||||
@@ -373,32 +377,32 @@ func GetSolar(year, month, day int, leap bool, tz float64) float64 {
|
||||
|
||||
// 确定闰月位置
|
||||
leapMonthPos := 20
|
||||
if moonCount == 13 {
|
||||
solarTermIndex, i := 2, 0
|
||||
if moonCount >= 13 {
|
||||
solarTermIndex, i := 0, 0
|
||||
for i = minMoonIndex; i <= maxMoonIndex; i++ {
|
||||
if !(newMoonDays[i] <= solarTerms[solarTermIndex] && newMoonDays[i+1] > solarTerms[solarTermIndex]) {
|
||||
break
|
||||
}
|
||||
solarTermIndex += 2
|
||||
}
|
||||
leapMonthPos = i - minMoonIndex + 1
|
||||
leapMonthPos = i - minMoonIndex
|
||||
}
|
||||
|
||||
// 计算实际月份索引
|
||||
actualMonth := month
|
||||
if leap {
|
||||
actualMonth++
|
||||
}
|
||||
if actualMonth > 10 {
|
||||
actualMonth -= 11
|
||||
} else {
|
||||
actualMonth++
|
||||
}
|
||||
// 计算实际月份索引
|
||||
if leap {
|
||||
actualMonth++
|
||||
}
|
||||
|
||||
if actualMonth >= leapMonthPos && !leap {
|
||||
actualMonth++
|
||||
}
|
||||
|
||||
return newMoonDays[minMoonIndex-1+actualMonth] + float64(day) - 1
|
||||
return newMoonDays[minMoonIndex+actualMonth] + float64(day) - 1
|
||||
}
|
||||
|
||||
func normalizeTimeArray(timeArray []float64, tz float64) {
|
||||
|
||||
@@ -217,3 +217,33 @@ func TestGetJQTime(t *testing.T) {
|
||||
func TestJQ(t *testing.T) {
|
||||
fmt.Println(GetJQTime(-721, 15))
|
||||
}
|
||||
|
||||
func TestCal6402(t *testing.T) {
|
||||
var year = 6402
|
||||
var tz = 8.00 / 24.00
|
||||
winterSolsticeDay := GetJQTime(year, 270) + tz
|
||||
firstNewMoonDay := TD2UT(CalcMoonSHByJDE(winterSolsticeDay-15, 0), false) + tz
|
||||
nextNewMoonDay := TD2UT(CalcMoonSHByJDE(firstNewMoonDay+28, 0), false) + tz
|
||||
fmt.Println(JDE2Date(firstNewMoonDay))
|
||||
fmt.Println(JDE2Date(nextNewMoonDay))
|
||||
fmt.Println(HSunTrueLo(TD2UT(nextNewMoonDay, false)))
|
||||
fmt.Println(HMoonTrueLo(TD2UT(nextNewMoonDay, false)))
|
||||
firstNewMoonDay = normalizeTimePoint(firstNewMoonDay)
|
||||
nextNewMoonDay = normalizeTimePoint(nextNewMoonDay)
|
||||
fmt.Println(JDE2Date(winterSolsticeDay))
|
||||
fmt.Println(JDE2Date(GetSolar(1984, 10, 2, true, 8.0/24.0)))
|
||||
fmt.Println(GetLunar(1992, 11, 24, 8.0/24.0))
|
||||
fmt.Println(GetLunar(6402, 12, 24, 8.0/24.0))
|
||||
for i := 1; i <= 12; i++ {
|
||||
fmt.Print("6403", i, "24 ---- ")
|
||||
fmt.Println(GetLunar(6403, i, 24, 8.0/24.0))
|
||||
}
|
||||
fmt.Println("-------")
|
||||
for _, v := range GetMoonLoops(float64(2132), 17) {
|
||||
fmt.Println(JDE2Date(v))
|
||||
}
|
||||
fmt.Println("-------")
|
||||
for _, v := range GetJieqiLoops(2132, 25) {
|
||||
fmt.Println(JDE2Date(v))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_LoBo(t *testing.T) {
|
||||
fmt.Printf("%.9f", dt_cal(2020.5))
|
||||
}
|
||||
|
||||
func Test_LoBoRaDec(t *testing.T) {
|
||||
jde := 2451545.0
|
||||
lo, bo := RaDecToLoBo(jde, 10, 50)
|
||||
|
||||
+16
-14
@@ -1435,19 +1435,20 @@ func GetMoonRiseTime(julianDay, longitude, latitude, timeZone, zenithShift, heig
|
||||
timeZone = longitude / 15
|
||||
var moonAngle, timeToMeridian float64 = 0, 0
|
||||
julianDayZero := math.Floor(julianDay) + 0.5
|
||||
julianDay = math.Floor(julianDay) + 0.5 - originalTimeZone/24 + timeZone/24 // 求0时JDE
|
||||
|
||||
//julianDay = math.Floor(julianDay) + 0.5 - originalTimeZone/24 + timeZone/24 // 求0时JDE
|
||||
//fix:这里时间分界线应当以传入的时区为准,不应当使用当地时区,否则在0时的判断会出错
|
||||
julianDay = math.Floor(julianDay) + 0.5
|
||||
estimatedTime := julianDay
|
||||
moonHeight := MoonHeight(julianDay, longitude, latitude, timeZone) // 求此时月亮高度
|
||||
moonHeight := MoonHeight(julianDay, longitude, latitude, originalTimeZone) // 求此时月亮高度
|
||||
|
||||
if zenithShift != 0 {
|
||||
moonAngle = -0.83333 // 修正大气折射
|
||||
}
|
||||
moonAngle = moonAngle - HeightDegreeByLat(height, latitude)
|
||||
|
||||
moonAngleTime := MoonTimeAngle(julianDay, longitude, latitude, timeZone)
|
||||
moonAngleTime := MoonTimeAngle(julianDay, longitude, latitude, originalTimeZone)
|
||||
|
||||
if moonHeight > 0 { // 月亮在地平线上或在落下与下中天之间
|
||||
if moonHeight-moonAngle > 0 { // 月亮在地平线上或在落下与下中天之间
|
||||
if moonAngleTime > 180 {
|
||||
timeToMeridian = (180 + 360 - moonAngleTime) / 15
|
||||
} else {
|
||||
@@ -1456,10 +1457,10 @@ func GetMoonRiseTime(julianDay, longitude, latitude, timeZone, zenithShift, heig
|
||||
estimatedTime += (timeToMeridian/24 + (timeToMeridian/24*12.0)/15.0/24.0)
|
||||
}
|
||||
|
||||
if moonHeight < 0 && moonAngleTime > 180 {
|
||||
if moonHeight-moonAngle < 0 && moonAngleTime > 180 {
|
||||
timeToMeridian = (180 - moonAngleTime) / 15
|
||||
estimatedTime += (timeToMeridian/24 + (timeToMeridian/24*12.0)/15.0/24.0)
|
||||
} else if moonHeight < 0 && moonAngleTime < 180 {
|
||||
} else if moonHeight-moonAngle < 0 && moonAngleTime < 180 {
|
||||
timeToMeridian = (180 - moonAngleTime) / 15
|
||||
estimatedTime += (timeToMeridian/24 + (timeToMeridian/24*12.0)/15.0/24.0)
|
||||
}
|
||||
@@ -1519,28 +1520,29 @@ func GetMoonSetTime(julianDay, longitude, latitude, timeZone, zenithShift, heigh
|
||||
timeZone = longitude / 15
|
||||
var moonAngle, timeToMeridian float64 = 0, 0
|
||||
julianDayZero := math.Floor(julianDay) + 0.5
|
||||
julianDay = math.Floor(julianDay) + 0.5 - originalTimeZone/24 + timeZone/24 // 求0时JDE
|
||||
|
||||
//julianDay = math.Floor(julianDay) + 0.5 - originalTimeZone/24 + timeZone/24 // 求0时JDE
|
||||
//fix:这里时间分界线应当以传入的时区为准,不应当使用当地时区,否则在0时的判断会出错
|
||||
julianDay = math.Floor(julianDay) + 0.5
|
||||
estimatedTime := julianDay
|
||||
moonHeight := MoonHeight(julianDay, longitude, latitude, timeZone) // 求此时月亮高度
|
||||
moonHeight := MoonHeight(julianDay, longitude, latitude, originalTimeZone) // 求此时月亮高度
|
||||
|
||||
if zenithShift != 0 {
|
||||
moonAngle = -0.83333 // 修正大气折射
|
||||
}
|
||||
moonAngle = moonAngle - HeightDegreeByLat(height, latitude)
|
||||
|
||||
moonAngleTime := MoonTimeAngle(julianDay, longitude, latitude, timeZone)
|
||||
moonAngleTime := MoonTimeAngle(julianDay, longitude, latitude, originalTimeZone)
|
||||
|
||||
if moonHeight < 0 {
|
||||
if moonHeight-moonAngle < 0 {
|
||||
timeToMeridian = (360 - moonAngleTime) / 15
|
||||
estimatedTime += (timeToMeridian/24 + (timeToMeridian/24.0*12.0)/15.0/24.0)
|
||||
}
|
||||
|
||||
// 月亮在地平线上或在落下与下中天之间
|
||||
if moonHeight > 0 && moonAngleTime < 180 {
|
||||
if moonHeight-moonAngle > 0 && moonAngleTime < 180 {
|
||||
timeToMeridian = (-moonAngleTime) / 15
|
||||
estimatedTime += (timeToMeridian/24.0 + (timeToMeridian/24.0*12.0)/15.0/24.0)
|
||||
} else if moonHeight > 0 {
|
||||
} else if moonHeight-moonAngle > 0 {
|
||||
timeToMeridian = (360 - moonAngleTime) / 15
|
||||
estimatedTime += (timeToMeridian/24.0 + (timeToMeridian/24.0*12.0)/15.0/24.0)
|
||||
}
|
||||
|
||||
+22
-19
@@ -1,11 +1,12 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"b612.me/astro/tools"
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/tools"
|
||||
)
|
||||
|
||||
func Benchmark_MoonRiseBench(b *testing.B) {
|
||||
@@ -492,11 +493,11 @@ var moonRiseSetTestData = []MoonRiseSetTestCase{
|
||||
{2024, 2, 29.0, 31.2357, 30.0444, 2.0, 1, 100, 2460370.429845, 2460369.865380},
|
||||
{2024, 2, 29.0, 31.2357, 30.0444, 2.0, 1, 1000, 2460370.428616, 2460369.866552},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 0, 0, 2460861.065509, -3.000000},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 0, 100, 2460861.064944, -3.000000},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 0, 1000, 2460861.063725, -3.000000},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 1, 0, 2460861.062582, -3.000000},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 1, 100, 2460861.062019, -3.000000},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 1, 1000, 2460861.060803, -3.000000},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 0, 100, 2460861.064944, 2460860.500441},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 0, 1000, 2460861.063725, 2460860.501606},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 1, 0, 2460861.062582, 2460860.502699},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 1, 100, 2460861.062019, 2460860.503237},
|
||||
{2025, 7, 4.0, 31.2357, 30.0444, 2.0, 1, 1000, 2460861.060803, 2460860.504400},
|
||||
{2023, 1, 15.0, -43.1729, -22.9068, -3.0, 0, 0, -3.000000, 2459960.019905},
|
||||
{2023, 1, 15.0, -43.1729, -22.9068, -3.0, 0, 100, -3.000000, 2459960.020416},
|
||||
{2023, 1, 15.0, -43.1729, -22.9068, -3.0, 0, 1000, -3.000000, 2459960.021522},
|
||||
@@ -619,10 +620,10 @@ var moonRiseSetTestData = []MoonRiseSetTestCase{
|
||||
{2024, 2, 29.0, -149.9003, 61.2181, -9.0, 1, 1000, 2460369.506308, 2460369.862264},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 0, 0, 2460861.205484, 2460861.493716},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 0, 100, 2460861.204170, 2460861.495011},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 0, 1000, 2460861.201358, 2460861.497780},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 1, 0, 2460861.198757, -3.000000},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 1, 100, 2460861.197484, -3.000000},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 1, 1000, 2460861.194755, -3.000000},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 0, 1000, 2460861.201358, 2460860.500309},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 1, 0, 2460861.198757, 2460860.502500},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 1, 100, 2460861.197484, 2460860.503576},
|
||||
{2025, 7, 4.0, -149.9003, 61.2181, -9.0, 1, 1000, 2460861.194755, 2460860.505890},
|
||||
{2023, 1, 15.0, -42.6043, 71.7069, -3.0, 0, 0, 2459959.583014, 2459959.895953},
|
||||
{2023, 1, 15.0, -42.6043, 71.7069, -3.0, 0, 100, 2459959.581157, 2459959.897741},
|
||||
{2023, 1, 15.0, -42.6043, 71.7069, -3.0, 0, 1000, 2459959.577188, 2459959.901560},
|
||||
@@ -656,8 +657,8 @@ var moonRiseSetTestData = []MoonRiseSetTestCase{
|
||||
{2024, 2, 29.0, -42.6043, 71.7069, -3.0, 0, 0, 2460369.510257, 2460369.739050},
|
||||
{2024, 2, 29.0, -42.6043, 71.7069, -3.0, 0, 100, 2460369.507908, 2460369.741347},
|
||||
{2024, 2, 29.0, -42.6043, 71.7069, -3.0, 0, 1000, 2460369.502952, 2460369.746190},
|
||||
{2024, 2, 29.0, -42.6043, 71.7069, -3.0, 1, 0, -3.000000, 2460369.750583},
|
||||
{2024, 2, 29.0, -42.6043, 71.7069, -3.0, 1, 100, -3.000000, 2460369.752708},
|
||||
{2024, 2, 29.0, -42.6043, 71.7069, -3.0, 1, 0, -2.000000, 2460369.750583},
|
||||
{2024, 2, 29.0, -42.6043, 71.7069, -3.0, 1, 100, -2.000000, 2460369.752708},
|
||||
{2024, 2, 29.0, -42.6043, 71.7069, -3.0, 1, 1000, -3.000000, 2460369.757206},
|
||||
{2025, 7, 4.0, -42.6043, 71.7069, -3.0, 0, 0, 2460861.253176, 2460861.327087},
|
||||
{2025, 7, 4.0, -42.6043, 71.7069, -3.0, 0, 100, 2460861.246829, 2460861.333396},
|
||||
@@ -712,25 +713,26 @@ var moonRiseSetTestData = []MoonRiseSetTestCase{
|
||||
// TestMoonRiseSetRegression 月出月落回归测试
|
||||
func TestMoonRiseSetRegression(t *testing.T) {
|
||||
beforeDeltaT := defDeltaTFn
|
||||
SetDeltaTFn(DefaultDeltaT)
|
||||
SetDeltaTFn(DefaultDeltaTv2)
|
||||
defer SetDeltaTFn(beforeDeltaT)
|
||||
const tolerance = 0.000001 // 容差设为1微秒,对于天文计算来说已经足够精确
|
||||
const tolerance = 0.00011574074
|
||||
|
||||
for i, testCase := range moonRiseSetTestData {
|
||||
julianDay := JDECalc(testCase.Year, testCase.Month, testCase.Day)
|
||||
|
||||
// 测试月出时间
|
||||
|
||||
actualRise := GetMoonRiseTime(julianDay, testCase.Longitude, testCase.Latitude,
|
||||
testCase.TimeZone, testCase.ZenithShift, testCase.Height)
|
||||
|
||||
if !floatEquals(actualRise, testCase.ExpectedRise, tolerance) {
|
||||
t.Errorf("测试用例 %d 月出时间不匹配:\n"+
|
||||
" 日期: %d-%d-%.1f, 经纬度: (%.4f, %.4f), 时区: %.1f, 天顶修正: %.0f, 海拔: %.0f\n"+
|
||||
" 期望月出: %.6f, 实际月出: %.6f, 差值: %.9f",
|
||||
" 期望月出: %v, 实际月出: %.6f, 差值: %.9f",
|
||||
i, testCase.Year, testCase.Month, testCase.Day,
|
||||
testCase.Longitude, testCase.Latitude, testCase.TimeZone,
|
||||
testCase.ZenithShift, testCase.Height,
|
||||
testCase.ExpectedRise, actualRise, math.Abs(actualRise-testCase.ExpectedRise))
|
||||
JDE2Date(testCase.ExpectedRise), actualRise, math.Abs(actualRise-testCase.ExpectedRise))
|
||||
}
|
||||
|
||||
// 测试月落时间
|
||||
@@ -738,13 +740,14 @@ func TestMoonRiseSetRegression(t *testing.T) {
|
||||
testCase.TimeZone, testCase.ZenithShift, testCase.Height)
|
||||
|
||||
if !floatEquals(actualSet, testCase.ExpectedSet, tolerance) {
|
||||
fmt.Println(JDECalc(testCase.Year, testCase.Month, testCase.Day))
|
||||
t.Errorf("测试用例 %d 月落时间不匹配:\n"+
|
||||
" 日期: %d-%d-%.1f, 经纬度: (%.4f, %.4f), 时区: %.1f, 天顶修正: %.0f, 海拔: %.0f\n"+
|
||||
" 期望月落: %.6f, 实际月落: %.6f, 差值: %.9f",
|
||||
" 期望月落: %v,%.6f, 实际月落: %v,%.6f , 差值: %.9f",
|
||||
i, testCase.Year, testCase.Month, testCase.Day,
|
||||
testCase.Longitude, testCase.Latitude, testCase.TimeZone,
|
||||
testCase.ZenithShift, testCase.Height,
|
||||
testCase.ExpectedSet, actualSet, math.Abs(actualSet-testCase.ExpectedSet))
|
||||
JDE2Date(testCase.ExpectedSet), testCase.ExpectedSet, JDE2Date(actualSet), actualSet, math.Abs(actualSet-testCase.ExpectedSet))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,7 +757,7 @@ func TestMoonRiseSetRegression(t *testing.T) {
|
||||
// TestMoonRiseSetSpecialCases 测试特殊情况
|
||||
func TestMoonRiseSetSpecialCases(t *testing.T) {
|
||||
beforeDeltaT := defDeltaTFn
|
||||
SetDeltaTFn(DefaultDeltaT)
|
||||
SetDeltaTFn(DefaultDeltaTv2)
|
||||
defer SetDeltaTFn(beforeDeltaT)
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -2,8 +2,11 @@ package calendar
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
type lunarSolar struct {
|
||||
@@ -256,6 +259,28 @@ func TestGanZhiOfDay(t *testing.T) {
|
||||
fmt.Println(SolarToLunarByYMD(700, 2, 29))
|
||||
}
|
||||
|
||||
func TestRapidLunarAndLunar(t *testing.T) {
|
||||
for year := 1949; year < 2400; year++ {
|
||||
for month := 1; month <= 12; month++ {
|
||||
a1, a2, a3, a4, _ := rapidLunarModern(year, month, 24)
|
||||
b1, b2, b3, b4, _ := basic.GetLunar(year, month, 24, 8.0/24.0)
|
||||
if a1 != b1 || a2 != b2 || a3 != b3 || a4 != b4 {
|
||||
if year == 2165 && month == 12 {
|
||||
continue
|
||||
}
|
||||
if math.Abs(float64(b3-a3)) == 1 {
|
||||
continue
|
||||
}
|
||||
t.Fatal(year, month, 24, a1, a2, a3, a4, b1, b2, b3, b4)
|
||||
}
|
||||
sol := JDE2Date(basic.GetSolar(b1, b2, b3, b4, 8.0/24))
|
||||
if sol.Year() != year && int(sol.Month()) != month && sol.Day() != 24 {
|
||||
t.Fatal(year, month, sol, b1, b2, b3, b4)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestgenReverseMapNianHao(t *testing.T) {
|
||||
//mymap := make(map[string][][]int)
|
||||
|
||||
+19
-19
@@ -121,7 +121,7 @@ func nianHaoMap() map[string][][]int {
|
||||
"天历": [][]int{{1328, 1330}},
|
||||
"泰定": [][]int{{1324, 1328}},
|
||||
"至治": [][]int{{1321, 1323}},
|
||||
"延佑": [][]int{{1314, 1320}},
|
||||
"延祐": [][]int{{1314, 1320}},
|
||||
"皇庆": [][]int{{1312, 1313}},
|
||||
"至大": [][]int{{1308, 1311}},
|
||||
"大德": [][]int{{1297, 1307}},
|
||||
@@ -129,12 +129,12 @@ func nianHaoMap() map[string][][]int {
|
||||
"至元": [][]int{{1264, 1294}, {1335, 1368}},
|
||||
"祥兴": [][]int{{1278, 1264}},
|
||||
"景炎": [][]int{{1276, 1278}},
|
||||
"德佑": [][]int{{1275, 1276}},
|
||||
"德祐": [][]int{{1275, 1276}},
|
||||
"咸淳": [][]int{{1265, 1275}},
|
||||
"景定": [][]int{{1260, 1264}},
|
||||
"开庆": [][]int{{1259, 1259}},
|
||||
"宝佑": [][]int{{1253, 1258}},
|
||||
"淳佑": [][]int{{1241, 1252}},
|
||||
"宝祐": [][]int{{1253, 1258}},
|
||||
"淳祐": [][]int{{1241, 1252}},
|
||||
"嘉熙": [][]int{{1237, 1240}},
|
||||
"端平": [][]int{{1234, 1236}},
|
||||
"绍定": [][]int{{1228, 1233}},
|
||||
@@ -158,13 +158,13 @@ func nianHaoMap() map[string][][]int {
|
||||
"建中靖国": [][]int{{1101, 1101}},
|
||||
"元符": [][]int{{1098, 1100}},
|
||||
"绍圣": [][]int{{1094, 1098}},
|
||||
"元佑": [][]int{{1086, 1094}},
|
||||
"元祐": [][]int{{1086, 1094}},
|
||||
"元丰": [][]int{{1078, 1085}},
|
||||
"熙宁": [][]int{{1068, 1077}},
|
||||
"治平": [][]int{{1064, 1067}},
|
||||
"嘉佑": [][]int{{1056, 1063}},
|
||||
"嘉祐": [][]int{{1056, 1063}},
|
||||
"至和": [][]int{{1054, 1056}},
|
||||
"皇佑": [][]int{{1049, 1054}},
|
||||
"皇祐": [][]int{{1049, 1054}},
|
||||
"庆历": [][]int{{1041, 1048}},
|
||||
"康定": [][]int{{1040, 1041}},
|
||||
"宝元": [][]int{{1038, 1040}},
|
||||
@@ -186,7 +186,7 @@ func nianHaoMap() map[string][][]int {
|
||||
"建隆": [][]int{{960, 963}},
|
||||
"显德": [][]int{{954, 960}},
|
||||
"广顺": [][]int{{951, 954}},
|
||||
"乾佑": [][]int{{948, 950}},
|
||||
"乾祐": [][]int{{948, 950}},
|
||||
"开运": [][]int{{944, 948}},
|
||||
"天福": [][]int{{936, 944}},
|
||||
"清泰": [][]int{{934, 936}},
|
||||
@@ -197,7 +197,7 @@ func nianHaoMap() map[string][][]int {
|
||||
"贞明": [][]int{{915, 921}},
|
||||
"乾化": [][]int{{911, 915}},
|
||||
"开平": [][]int{{907, 911}},
|
||||
"天佑": [][]int{{904, 907}},
|
||||
"天祐": [][]int{{904, 907}},
|
||||
"天复": [][]int{{901, 904}},
|
||||
"光化": [][]int{{898, 901}},
|
||||
"乾宁": [][]int{{894, 898}},
|
||||
@@ -1325,7 +1325,7 @@ func tangEras() []Era {
|
||||
{
|
||||
Year: 904,
|
||||
Emperor: "唐哀帝",
|
||||
OtherNianHaoStart: "天佑",
|
||||
OtherNianHaoStart: "天祐",
|
||||
Dynasty: "唐",
|
||||
},
|
||||
{
|
||||
@@ -1822,7 +1822,7 @@ func wudaiSongYuanEras() []Era {
|
||||
{
|
||||
Year: 1314,
|
||||
Emperor: "元仁宗",
|
||||
Nianhao: "延佑",
|
||||
Nianhao: "延祐",
|
||||
Dynasty: "元",
|
||||
},
|
||||
{
|
||||
@@ -1871,7 +1871,7 @@ func wudaiSongYuanEras() []Era {
|
||||
{
|
||||
Year: 1275,
|
||||
Emperor: "宋恭帝",
|
||||
OtherNianHaoStart: "德佑",
|
||||
OtherNianHaoStart: "德祐",
|
||||
Dynasty: "宋",
|
||||
},
|
||||
{
|
||||
@@ -1895,13 +1895,13 @@ func wudaiSongYuanEras() []Era {
|
||||
{
|
||||
Year: 1253,
|
||||
Emperor: "宋理宗",
|
||||
Nianhao: "宝佑",
|
||||
Nianhao: "宝祐",
|
||||
Dynasty: "宋",
|
||||
},
|
||||
{
|
||||
Year: 1241,
|
||||
Emperor: "宋理宗",
|
||||
Nianhao: "淳佑",
|
||||
Nianhao: "淳祐",
|
||||
Dynasty: "宋",
|
||||
},
|
||||
{
|
||||
@@ -2045,7 +2045,7 @@ func wudaiSongYuanEras() []Era {
|
||||
{
|
||||
Year: 1086,
|
||||
Emperor: "宋哲宗",
|
||||
Nianhao: "元佑",
|
||||
Nianhao: "元祐",
|
||||
Dynasty: "宋",
|
||||
},
|
||||
{
|
||||
@@ -2069,7 +2069,7 @@ func wudaiSongYuanEras() []Era {
|
||||
{
|
||||
Year: 1056,
|
||||
Emperor: "宋仁宗",
|
||||
OtherNianHaoStart: "嘉佑",
|
||||
OtherNianHaoStart: "嘉祐",
|
||||
Dynasty: "宋",
|
||||
},
|
||||
{
|
||||
@@ -2081,7 +2081,7 @@ func wudaiSongYuanEras() []Era {
|
||||
{
|
||||
Year: 1049,
|
||||
Emperor: "宋仁宗",
|
||||
Nianhao: "皇佑",
|
||||
Nianhao: "皇祐",
|
||||
Dynasty: "宋",
|
||||
},
|
||||
{
|
||||
@@ -2213,7 +2213,7 @@ func wudaiSongYuanEras() []Era {
|
||||
{
|
||||
Year: 948,
|
||||
Emperor: "后汉隐帝",
|
||||
OtherNianHaoStart: "乾佑",
|
||||
OtherNianHaoStart: "乾祐",
|
||||
Dynasty: "后汉",
|
||||
},
|
||||
{
|
||||
@@ -2279,7 +2279,7 @@ func wudaiSongYuanEras() []Era {
|
||||
{
|
||||
Year: 904,
|
||||
Emperor: "唐哀帝",
|
||||
Nianhao: "天佑",
|
||||
Nianhao: "天祐",
|
||||
Dynasty: "唐",
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user