use golang timezone

master
兔子 4 years ago
parent 1c4397c9dc
commit 681dea1fb5

@ -199,8 +199,8 @@ func JDE2DateByZone(JD float64, tz *time.Location) time.Time {
}
tms := (Days - math.Floor(Days)) * 24 * 3600
Days = math.Floor(Days)
dates := time.Date(int(Years), time.Month(int(Months)), int(Days), 0, 0, 0, 0, tz)
dates = time.Unix(dates.Unix()+int64(tms), int64((tms-math.Floor(tms))*1000000000))
dates := time.Date(int(Years), time.Month(int(Months)), int(Days), 0, 0, 0, 0, time.UTC)
dates = time.Unix(dates.Unix()+int64(tms), int64((tms-math.Floor(tms))*1000000000)).In(tz)
return dates
}

@ -55,8 +55,9 @@ func ChineseLunar(date time.Time) (int, int, bool, string) {
// 例计算己亥猪年腊月三十日对应的公历即2020年1月24日
// 由于农历还未到鼠年故应当传入Solar(2019,12,30,false)
func Solar(year, month, day int, leap bool) time.Time {
jde := basic.GetSolar(year, month, day, leap)
return JDE2Date(jde)
jde := basic.GetSolar(year, month, day, leap) - 8.0/24.0
zone := time.FixedZone("CST", 8*3600)
return basic.JDE2DateByZone(jde, zone)
}
// GanZhi 返回传入年份对应的干支
@ -66,14 +67,14 @@ func GanZhi(year int) string {
// JieQi 返回传入年份、节气对应的北京时间节气时间
func JieQi(year, term int) time.Time {
calcJde := basic.GetJQTime(year, term) + 8.00/24.00
calcJde := basic.GetJQTime(year, term)
zone := time.FixedZone("CST", 8*3600)
return basic.JDE2DateByZone(calcJde, zone)
}
// WuHou 返回传入年份、物候对应的北京时间物候时间
func WuHou(year, term int) time.Time {
calcJde := basic.GetWHTime(year, term) + 8.00/24.00
calcJde := basic.GetWHTime(year, term)
zone := time.FixedZone("CST", 8*3600)
return basic.JDE2DateByZone(calcJde, zone)
}

@ -33,66 +33,66 @@ func SeeLo(date time.Time) float64 {
}
// SeeRa 月亮视赤经(站心)
// jde世界时UTC
// date, 时间
// lon, 经度
// lat, 纬度
// timezone, 时区
// 返回站心坐标
func SeeRa(date time.Time, lon, lat, timezone float64) float64 {
func SeeRa(date time.Time, lon, lat float64) float64 {
jde := basic.Date2JDE(date)
return basic.HMoonSeeRa(basic.TD2UT(jde, true), lon, lat, timezone)
_, loc := date.Zone()
return basic.HMoonSeeRa(jde, lon, lat, float64(loc)/3600.0)
}
// SeeDec 月亮视赤纬(站心)
// jde世界时UTC
// date, 时间
// lon, 经度
// lat, 纬度
// timezone, 时区
// 返回站心坐标
func SeeDec(date time.Time, lon, lat, timezone float64) float64 {
func SeeDec(date time.Time, lon, lat float64) float64 {
jde := basic.Date2JDE(date)
return basic.HMoonSeeDec(basic.TD2UT(jde, true), lon, lat, timezone)
_, loc := date.Zone()
return basic.HMoonSeeDec(jde, lon, lat, float64(loc)/3600.0)
}
// SeeRaDec 月亮视赤纬(站心)
// jde世界时UTC
// date, 本地时间
// lon, 经度
// lat, 纬度
// timezone, 时区
// 返回站心坐标
func SeeRaDec(date time.Time, lon, lat, timezone float64) (float64, float64) {
func SeeRaDec(date time.Time, lon, lat float64) (float64, float64) {
jde := basic.Date2JDE(date)
return basic.HMoonSeeRaDec(basic.TD2UT(jde, true), lon, lat, timezone)
_, loc := date.Zone()
return basic.HMoonSeeRaDec(jde, lon, lat, float64(loc)/3600.0)
}
// HourAngle 月亮时角
// date, 世界时(忽略此处时区)
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
func HourAngle(date time.Time, lon, lat, timezone float64) float64 {
func HourAngle(date time.Time, lon, lat float64) float64 {
jde := basic.Date2JDE(date)
return basic.MoonTimeAngle(jde, lon, lat, timezone)
_, loc := date.Zone()
return basic.MoonTimeAngle(jde, lon, lat, float64(loc)/3600.0)
}
// Azimuth 月亮方位角
// date, 世界时(忽略此处时区)
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
func Azimuth(date time.Time, lon, lat, timezone float64) float64 {
func Azimuth(date time.Time, lon, lat float64) float64 {
jde := basic.Date2JDE(date)
return basic.HMoonAngle(jde, lon, lat, timezone)
_, loc := date.Zone()
return basic.HMoonAngle(jde, lon, lat, float64(loc)/3600.0)
}
// Zenith 月亮高度角
// date, 世界时(忽略此处时区)
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
func Zenith(date time.Time, lon, lat, timezone float64) float64 {
jde := basic.Date2JDE(date)
return basic.HMoonHeight(jde, lon, lat, timezone)
_, loc := date.Zone()
return basic.HMoonHeight(jde, lon, lat, float64(loc)/3600.0)
}
// CulminationTime 月亮中天时间
@ -100,9 +100,10 @@ func Zenith(date time.Time, lon, lat, timezone float64) float64 {
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
func CulminationTime(date time.Time, lon, lat, timezone float64) float64 {
func CulminationTime(date time.Time, lon, lat float64) float64 {
jde := basic.Date2JDE(date)
return basic.GetMoonTZTime(jde, lon, lat, timezone)
_, loc := date.Zone()
return basic.GetMoonTZTime(jde, lon, lat, float64(loc)/3600.0)
}
// RiseTime 月亮升起时间
@ -110,9 +111,11 @@ func CulminationTime(date time.Time, lon, lat, timezone float64) float64 {
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
func RiseTime(date time.Time, lon, lat, timezone float64, aero bool) (time.Time, error) {
func RiseTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
var err error
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
aeroFloat := 0.00
if aero {
aeroFloat = 1
@ -135,9 +138,11 @@ func RiseTime(date time.Time, lon, lat, timezone float64, aero bool) (time.Time,
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
func DownTime(date time.Time, lon, lat, timezone float64, aero bool) (time.Time, error) {
func DownTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
var err error
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
aeroFloat := 0.00
if aero {
aeroFloat = 1
@ -163,23 +168,27 @@ func Phase(date time.Time) float64 {
}
// ShuoYue 朔月
func ShuoYue(year float64) float64 {
return basic.CalcMoonSH(year, 0)
func ShuoYue(year float64) time.Time {
jde := basic.TD2UT(basic.CalcMoonSH(year, 0), false)
return basic.JDE2DateByZone(jde, time.UTC)
}
// WangYue 望月
func WangYue(year float64) float64 {
return basic.CalcMoonSH(year, 1)
func WangYue(year float64) time.Time {
jde := basic.TD2UT(basic.CalcMoonSH(year, 1), false)
return basic.JDE2DateByZone(jde, time.UTC)
}
// ShangXianYue 上弦月
func ShangXianYue(year float64) float64 {
return basic.CalcMoonXH(year, 0)
func ShangXianYue(year float64) time.Time {
jde := basic.TD2UT(basic.CalcMoonXH(year, 0), false)
return basic.JDE2DateByZone(jde, time.UTC)
}
// XiaXianYue 下弦月
func XiaXianYue(year float64) float64 {
return basic.CalcMoonXH(year, 1)
func XiaXianYue(year float64) time.Time {
jde := basic.TD2UT(basic.CalcMoonXH(year, 1), false)
return basic.JDE2DateByZone(jde, time.UTC)
}
// EarthDistance 日地距离

@ -27,15 +27,16 @@ var (
// date取日期时区忽略
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
// aerotrue时进行大气修正
func RiseTime(date time.Time, lon, lat, timezone float64, aero bool) (time.Time, error) {
func RiseTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
var err error
var aeroFloat float64
if aero {
aeroFloat = 1
}
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
riseJde := basic.GetSunRiseTime(jde, lon, lat, timezone, aeroFloat)
if riseJde == -2 {
err = ERR_SUN_NEVER_RISE
@ -47,18 +48,19 @@ func RiseTime(date time.Time, lon, lat, timezone float64, aero bool) (time.Time,
}
// SunDownTime 太阳落下时间
// date取日期,时区忽略
// date当地时区日期,务必做时区修正
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
// aerotrue时进行大气修正
func DownTime(date time.Time, lon, lat, timezone float64, aero bool) (time.Time, error) {
func DownTime(date time.Time, lon, lat float64, aero bool) (time.Time, error) {
var err error
var aeroFloat float64
if aero {
aeroFloat = 1
}
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
downJde := basic.GetSunDownTime(jde, lon, lat, timezone, aeroFloat)
if downJde == -2 {
err = ERR_SUN_NEVER_RISE
@ -70,14 +72,15 @@ func DownTime(date time.Time, lon, lat, timezone float64, aero bool) (time.Time,
}
// MorningTwilight 晨朦影
// date取日期,时区忽略
// date当地时区日期
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
// angle朦影角度可选-6 -12 -18(民用、航海、天文)
func MorningTwilight(date time.Time, lon, lat, timezone, angle float64) (time.Time, error) {
func MorningTwilight(date time.Time, lon, lat, angle float64) (time.Time, error) {
var err error
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
calcJde := basic.GetAsaTime(jde, lon, lat, timezone, angle)
if calcJde == -2 {
err = ERR_TWILIGHT_NOT_EXISTS
@ -89,14 +92,15 @@ func MorningTwilight(date time.Time, lon, lat, timezone, angle float64) (time.Ti
}
// EveningTwilight 昏朦影
// date取日期,时区忽略
// date当地时区日期
// lon经度东正西负
// lat纬度北正南负
// timezone时区东正西负
// angle朦影角度可选-6 -12 -18(民用、航海、天文)
func EveningTwilight(date time.Time, lon, lat, timezone, angle float64) (time.Time, error) {
func EveningTwilight(date time.Time, lon, lat, angle float64) (time.Time, error) {
var err error
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
//不需要进行力学时转换会在GetBanTime中转换
calcJde := basic.GetBanTime(jde, lon, lat, timezone, angle)
if calcJde == -2 {
@ -209,44 +213,49 @@ func EquationTime(date time.Time) float64 {
}
// HourAngle 太阳时角
// 返回给定经纬度、对应timezone时区date时刻的太阳时角注意date本身的时区将默认舍去
func HourAngle(date time.Time, lon, lat, timezone float64) float64 {
// 返回给定经纬度、对应date时区date时刻的太阳时角
func HourAngle(date time.Time, lon, lat float64) float64 {
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
return basic.SunTimeAngle(jde, lon, lat, timezone)
}
// Azimuth 太阳方位角
// 返回给定经纬度、对应timezone时区date时刻的太阳方位角正北为0向东增加
//注意date本身的时区将默认舍去
func Azimuth(date time.Time, lon, lat, timezone float64) float64 {
// 返回给定经纬度、对应date时区date时刻的太阳方位角正北为0向东增加
func Azimuth(date time.Time, lon, lat float64) float64 {
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
return basic.SunAngle(jde, lon, lat, timezone)
}
// Zenith 太阳高度角
// 返回给定经纬度、对应timezone时区date时刻的太阳高度角
//注意date本身的时区将默认舍去
func Zenith(date time.Time, lon, lat, timezone float64) float64 {
// 返回给定经纬度、对应date时区date时刻的太阳高度角
func Zenith(date time.Time, lon, lat float64) float64 {
jde := basic.Date2JDE(date)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
return basic.SunHeight(jde, lon, lat, timezone)
}
// CulminationTime 太阳中天时间
// 返回给定经纬度、对应timezone时区date时刻的太阳中天日期
//注意date本身的时区将默认舍去返回的时间时区应当为传入的timezone
func CulminationTime(date time.Time, lon, timezone float64) time.Time {
// 返回给定经纬度、对应date时区date时刻的太阳中天日期
func CulminationTime(date time.Time, lon float64) time.Time {
jde := basic.Date2JDE(date)
if jde-math.Floor(jde) > 0.5 {
jde++
}
calcJde := basic.GetSunTZTime(jde, lon, timezone)
return basic.JDE2Date(calcJde)
_, loc := date.Zone()
timezone := float64(loc) / 3600.0
calcJde := basic.GetSunTZTime(jde, lon, timezone) - timezone/24.00
return basic.JDE2DateByZone(calcJde, date.Location())
}
// EarthDistance 日地距离
// 返回date对应UTC世界时日地距离
func EarthDistance(date time.Time) float64 {
jde := basic.Date2JDE(date)
jde := basic.Date2JDE(date.UTC())
jde = basic.TD2UT(jde, true)
return basic.EarthAway(jde)
}

Loading…
Cancel
Save