From 6ff76468b49d4c4e1dc3669082a72c29aa3fcffe Mon Sep 17 00:00:00 2001 From: starainrt Date: Sun, 23 Jul 2023 11:56:05 +0800 Subject: [PATCH] =?UTF-8?q?feature=20add:=E5=85=81=E8=AE=B8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89deltaT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basic/calendar.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/basic/calendar.go b/basic/calendar.go index 57297fd..96f3306 100644 --- a/basic/calendar.go +++ b/basic/calendar.go @@ -7,6 +7,8 @@ import ( "time" ) +var defDeltaTFn = DefaultDeltaT + /* @name: 儒略日计算 @dec: 计算给定时间的儒略日,1582年改力后为格里高利历,之前为儒略历 @@ -91,7 +93,36 @@ func dt_cal(y float64) float64 { //传入年, 返回世界时UT与原子时( res := d[i+1] + d[i+2]*t1 + d[i+3]*t2 + d[i+4]*t3 return (res) } -func DeltaT(Date float64, IsJDE bool) (Result float64) { //传入年或儒略日,传出为秒 + +func DeltaT(date float64, isJDE bool) float64 { + return defDeltaTFn(date, isJDE) +} + +func SetDeltaTFn(fn func(float64, bool) float64) { + if fn != nil { + defDeltaTFn = fn + } +} + +func GetDeltaTFn() func(float64, bool) float64 { + return defDeltaTFn +} + +func OldDefaultDeltaT(Date float64, IsJDE bool) (Result float64) { //传入年或儒略日,传出为秒 + var Year float64 + if IsJDE { + dates := JDE2Date(Date) + Year = float64(dates.Year()) + float64(dates.YearDay())/365.0 + } else { + Year = Date + } + if Year < 2100 && Year >= 2010 { + return dt_cal(Year) + } + return DefaultDeltaT(Date, IsJDE) +} + +func DefaultDeltaT(Date float64, IsJDE bool) (Result float64) { //传入年或儒略日,传出为秒 var Year float64 if IsJDE { dates := JDE2Date(Date) @@ -120,6 +151,7 @@ func DeltaT(Date float64, IsJDE bool) (Result float64) { //传入年或儒略日 } return } + func TD2UT(JDE float64, UT2TD bool) float64 { // true 世界时转力学时CC,false 力学时转世界时VV Deltat := DeltaT(JDE, true)