Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ported taiutc #39

Merged
merged 4 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,31 @@ julia> AstroTime.Epochs.taiutc(tai.jd1, tai.jd2)
```
"""
@inline function taiutc(jd1, jd2)
ls = leapseconds(jd1 + jd2)
dtat = ls/SECONDS_PER_DAY;
if jd1 > jd2
jd1 = jd1
jd2 -= dtat
big1 = jd1 >= jd2
if big1
a1 = jd1
a2 = jd2
else
jd1 -= dtat
jd2 = jd2
a1 = jd2
a2 = jd1
end
jd1, jd2

u1 = a1
u2 = a2
for i in range(1,3)
tai1, tai2 = utctai(u1, u2)
u2 += a1 - tai1
u2 += a2 - tai2
end

if big1
date = u1
date1 = u2
else
date = u2
date1 = u1
end
date, date1
end


Expand Down Expand Up @@ -616,6 +631,7 @@ function utctai(jd1, jd2)
date, date1
end


"""
datetime2julian(scale::T, year, month, date, hour, min, sec) where {T <: TimeScale}

Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ AstroTime.update()
leap = UTCEpoch(2016, 12, 31, 23, 59, 60)
tai1, tai2 = ERFA.utctai(julian1(leap), julian2(leap))
@test Epochs.utctai(julian1(leap), julian2(leap)) == ERFA.utctai(julian1(leap), julian2(leap))
@test_broken Epochs.taiutc(tai1, tai2) == ERFA.taiutc(tai1, tai2)
let (jd2, jd1) = Epochs.taiutc(tai1, tai2)
erfa_jd2, erfa_jd1 = ERFA.taiutc(tai1, tai2)
@test jd2 ≈ erfa_jd2
@test jd1 ≈ erfa_jd1
end

@test Epochs.diff_tdb_tt(julian1(tdb), julian2(tdb), 1.0, 2.0, 3.0, 4.0) == ERFA.dtdb(julian1(tdb), julian2(tdb), 1.0, 2.0, 3.0, 4.0)
@test Epochs.tdbtt(julian1(tdb), julian2(tdb), Δtr(tdb)) == ERFA.tdbtt(julian1(tdb), julian2(tdb), Δtr(tdb))
Expand Down