Skip to content

Commit

Permalink
Merge 9e5bce8 into 30097e8
Browse files Browse the repository at this point in the history
  • Loading branch information
prakharcode committed Jun 19, 2018
2 parents 30097e8 + 9e5bce8 commit 3068d8a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
33 changes: 25 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 Expand Up @@ -666,6 +682,7 @@ function datetime2julian(scale::T, year, month, date, hour, min, sec) where {T <
jd, time
end


# TAI <-> UTC
@transform UTC TAI ep begin
jd1, jd2 = julian1(ep), julian2(ep)
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,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

0 comments on commit 3068d8a

Please sign in to comment.