-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accessors and conversions to other time types
- Loading branch information
Showing
4 changed files
with
160 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Dates | ||
|
||
import ..AstroDates: DateTime, year, month, day, hour, minute, second | ||
|
||
export julian, j2000, timescale | ||
|
||
timescale(ep::Epoch{S}) where {S} = S | ||
|
||
julian(ep::Epoch) = get(days(ep - JULIAN_EPOCH)) | ||
j2000(ep::Epoch) = get(days(ep - J2000_EPOCH)) | ||
|
||
function DateTime(ep::Epoch) | ||
if !isfinite(ep.offset) | ||
if ep.offset < 0 | ||
DateTime(AstroDates.MIN_EPOCH, AstroDates.H00) | ||
else | ||
DateTime(AstroDates.MAX_EPOCH, Time(23, 59, 59.999)) | ||
end | ||
end | ||
|
||
ts_offset = tai_offset(ep) | ||
sum = ep.offset + ts_offset | ||
o′ = sum - ts_offset | ||
d′ = sum - o′ | ||
Δo = ep.offset - o′ | ||
Δd = ts_offset - d′ | ||
residual = Δo + Δd | ||
|
||
carry = floor(Int64, sum) | ||
offset2000B = (sum - carry) + residual | ||
offset2000A = ep.epoch + carry + Int64(43200) | ||
if offset2000B < 0 | ||
offset2000A -= 1 | ||
offset2000B += 1 | ||
end | ||
time = offset2000A % Int64(86400) | ||
if time < Int64(0) | ||
time += Int64(86400) | ||
end | ||
date = Int((offset2000A - time) ÷ Int64(86400)) | ||
|
||
date_comp = Date(AstroDates.J2000_EPOCH, date) | ||
time_comp = Time(time, offset2000B) | ||
|
||
#= if (timeScale.insideLeap(this)) { =# | ||
#= // fix the seconds number to take the leap into account =# | ||
#= timeComponents = new TimeComponents(timeComponents.getHour(), timeComponents.getMinute(), =# | ||
#= timeComponents.getSecond() + timeScale.getLeap(this)) =# | ||
#= } =# | ||
|
||
DateTime(date_comp, time_comp) | ||
end | ||
|
||
year(ep::Epoch) = year(DateTime(ep)) | ||
month(ep::Epoch) = month(DateTime(ep)) | ||
day(ep::Epoch) = day(DateTime(ep)) | ||
hour(ep::Epoch) = hour(DateTime(ep)) | ||
minute(ep::Epoch) = minute(DateTime(ep)) | ||
second(ep::Epoch) = second(DateTime(ep)) | ||
|
||
Dates.DateTime(ep::Epoch) = Dates.DateTime(DateTime(ep)) | ||
Epoch{S}(dt::Dates.DateTime) where {S} = Epoch{S}(DateTime(dt)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
tai_offset(::InternationalAtomicTime, ep) = 0.0 | ||
tai_offset(::TerrestrialTime, ep) = OFFSET_TAI_TT | ||
tai_offset(::CoordinatedUniversalTime, ep) = offset_tai_utc(julian(ep)) | ||
tai_offset(::UniversalTime, ep) = tai_offset(UTC, ep) + getΔUT1(julian(ep)) | ||
tai_offset(::GeocentricCoordinateTime, ep) = tai_offset(TT, ep) + LG_RATE * get(ep - EPOCH_77) | ||
tai_offset(::BarycentricCoordinateTime, ep) = tai_offset(TT, ep) + LB_RATE * get(ep - EPOCH_77) | ||
function tai_offset(::BarycentricDynamicalTime, ep) | ||
dt = get(days(ep - J2000_EPOCH)) | ||
g = 357.53 + 0.9856003dt | ||
tai_offset(TT, ep) + 0.001658sind(g) + 0.000014sind(2g) | ||
end | ||
|
||
tai_offset(ep::Epoch{S}) where {S} = tai_offset(S, ep) | ||
|
||
tai_offset(::InternationalAtomicTime, date, time) = 0.0 | ||
|
||
function tai_offset(scale, date, time) | ||
ref = Epoch{TAI}(date, time) | ||
offset = 0.0 | ||
for _ in 1:8 | ||
offset = -tai_offset(scale, Epoch{TAI}(ref, offset)) | ||
end | ||
offset | ||
end |