julian.go (452B)
1 package sunrise 2 3 import ( 4 "time" 5 ) 6 7 const ( 8 secondsInADay = 86400 9 unixEpochJulianDay = 2440587.5 10 ) 11 12 // TimeToJulianDay converts a time.Time into a Julian day. 13 func TimeToJulianDay(t time.Time) float64 { 14 return float64(t.Unix())/secondsInADay + unixEpochJulianDay 15 } 16 17 // JulianDayToTime converts a Julian day into a time.Time. 18 func JulianDayToTime(d float64) time.Time { 19 return time.Unix(int64((d-unixEpochJulianDay)*secondsInADay), 0).UTC() 20 }