Skip to content

Commit

Permalink
Merge e92386c into f1246c0
Browse files Browse the repository at this point in the history
  • Loading branch information
prakharcode committed Jun 6, 2018
2 parents f1246c0 + e92386c commit fa1d056
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,37 @@ julia> AstroTime.Epochs.tcbtdb(tcb.jd1, tcb.jd2)
end


function cal2jd(iy, im, id)
EYEAR_ALLOWED = -4799
MON_LENGTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

if iy < EYEAR_ALLOWED
throw(ArugumentError("Year is outside of the representable range (< $EYEAR_ALLOWED)"))
end

if im < 1 || im > 12
throw(ArugumentError("Month is outside of the range (1,12)"))
end

ly = ((im == 2 ) && !Bool(iy % 4!=0) && (Bool(iy % 100!=0) || !Bool(iy % 400!=0)))? 1:0 #check if leap year

if ((id < 1) || (id > (MON_LENGTH[im] + ly)))
println("Day is outside of permissible range (1, $(MON_LENGTH[im]))")
end

my = (im - 14) ÷ 12
iypmy = trunc(Int,(iy + my))
jd = MJD
jd1 = float((((1461 * (iypmy + 4800)) ÷ 4)
+ (367 * trunc(Int,(im - 2 - 12 * my))) ÷ 12
- (3 * ((iypmy + 4900) ÷ 100)) ÷ 4
+ trunc(Int,id) - 2432076))

jd, jd1
end



# TAI <-> UTC
@transform UTC TAI ep begin
jd1, jd2 = julian1(ep), julian2(ep)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ AstroTime.update()
for jd in 2414105.0:10.0:2488985.0
@test Epochs.diff_tdb_tt(jd, 0.5) Epochs.diff_tdb_tt(jd,0.5,0.0,0.0,0.0,0.0) atol=40e-6
end

@test Epochs.cal2jd(2000, 1, 1) == ERFA.cal2jd(2000, 1, 1)
@test Epochs.cal2jd(2016, 2, 29) == ERFA.cal2jd(2016, 2, 29)
end
@testset "Leap Seconds" begin
@test leapseconds(TTEpoch(1959,1,1)) == 0
Expand Down

0 comments on commit fa1d056

Please sign in to comment.