Skip to content

Commit

Permalink
ported utcut1 (#38)
Browse files Browse the repository at this point in the history
* added utcut1

* added dat

* reset
  • Loading branch information
prakharcode authored and helgee committed Jun 19, 2018
1 parent 30097e8 commit b50676e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 23 additions & 2 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,7 @@ end
Transforms DateTime field to two-part Julian Date, special provision for leapseconds is provided.
# Example
#Example
```jldoctest
julia> AstroTime.Epochs.datetime2julian(UTC, 2016, 12, 31, 23, 59, 60)
(2.4577535e6, 0.9999884260598836)
Expand Down Expand Up @@ -666,6 +665,28 @@ function datetime2julian(scale::T, year, month, date, hour, min, sec) where {T <
jd, time
end

"""
utcut1(jd1, jd2)
Transform a two-part Julian date from `UTC` to `UT1`.
# Example
```jldoctest
julia> utc = Epoch{UTC}(2.4578265e6, 0.30477440993249416)
2017-03-14T07:18:52.509 UTC
julia> AstroTime.Epochs.utcut1(utc.jd1, utc.jd2)
(2.4578265e6, 0.30477440993249416)
```
"""
@inline function utcut1(jd1, jd2, dut1, dat)
jd = +(jd1, jd2)
dta = dut1 - dat
tai1, tai2 = utctai(jd1, jd2)
date, date1 = taiut1(tai1, tai2, dta)
date, date1
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 @@ -155,7 +155,8 @@ AstroTime.update()
tdb = TDBEpoch(2000, 1, 1, 12, 0, 0.0)
tcb = TCBEpoch(2000, 1, 1, 12, 0, 0.0)
Δtr(ep) = Epochs.diff_tdb_tt(julian1(ep), julian2(ep))
dat(ep) = Epochs.dut1(ep)-Epochs.leapseconds(julian(ep))
dut1(ep) = Epochs.dut1(ep)
dat(ep) = dut1(ep) - Epochs.leapseconds(julian(ep))

@test Epochs.tttai(julian1(tt), julian2(tt)) == ERFA.tttai(julian1(tt), julian2(tt))
@test Epochs.tttai(julian2(tt), julian1(tt)) == ERFA.tttai(julian2(tt), julian1(tt))
Expand Down Expand Up @@ -224,6 +225,9 @@ AstroTime.update()
@test Epochs.jd2cal(julian1(tt), julian2(tt)) == ERFA.jd2cal(julian1(tt), julian2(tt))
@test Epochs.jd2cal(julian2(tt), julian1(tt)) == ERFA.jd2cal(julian2(tt), julian1(tt))

@test Epochs.utcut1(julian1(utc), julian2(utc), dut1(utc),leapseconds(julian(utc))) == ERFA.utcut1(julian1(utc), julian2(utc), dut1(utc))
@test Epochs.utcut1(julian2(utc), julian1(utc),dut1(utc),leapseconds(julian(utc))) == ERFA.utcut1(julian2(utc), julian1(utc), dut1(utc))

@test Epochs.datetime2julian(UTC, 2016, 12, 31, 23, 59, 60) == ERFA.dtf2d("UTC", 2016, 12, 31, 23, 59, 60)
@test Epochs.datetime2julian(TT, 2016, 12, 31, 23, 59, 59) == ERFA.dtf2d("TT", 2016, 12, 31, 23, 59, 59)
@test_throws ArgumentError Epochs.datetime2julian(TT, 2016, 12, 31, 23, 59, 60)
Expand Down

0 comments on commit b50676e

Please sign in to comment.