From bc4ee73762192234e2bc121746edaf33e819d6ee Mon Sep 17 00:00:00 2001 From: Helge Eichhorn Date: Mon, 12 Apr 2021 22:11:33 +0200 Subject: [PATCH] Remove unnecessary type casts --- src/AstroDates.jl | 2 +- src/Epochs/accessors.jl | 8 ++++---- src/Epochs/dates.jl | 12 +++++------- test/epochs.jl | 4 ++-- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/AstroDates.jl b/src/AstroDates.jl index d2775ce..ef7b820 100644 --- a/src/AstroDates.jl +++ b/src/AstroDates.jl @@ -10,7 +10,7 @@ using Dates: dayofyear const J2000 = 2.4515445e6 function findyear(calendar, j2000day) - j2kday = Int64(j2000day) + j2kday = ifelse(j2000day isa Int32, widen(j2000day), j2000day) if calendar == :proleptic_julian return -((-4 * j2kday - 2920488) ÷ 1461) elseif calendar == :julian diff --git a/src/Epochs/accessors.jl b/src/Epochs/accessors.jl index 9b999e2..a6e45f8 100644 --- a/src/Epochs/accessors.jl +++ b/src/Epochs/accessors.jl @@ -29,12 +29,12 @@ function DateTime(ep::Epoch) end end - sec = ep.second + Int64(43200) - time = sec % Int64(86400) + sec = ep.second + 43200 + time = sec % 86400 if time < 0 - time += Int64(86400) + time += 86400 end - date = Int((sec - time) ÷ Int64(86400)) + date = (sec - time) ÷ 86400 date_comp = Date(AstroDates.J2000_EPOCH, date) time_comp = Time(time, ep.fraction) diff --git a/src/Epochs/dates.jl b/src/Epochs/dates.jl index db9bcbb..45567df 100644 --- a/src/Epochs/dates.jl +++ b/src/Epochs/dates.jl @@ -1,11 +1,9 @@ function Epoch{S}(date::Date, time::Time{T}, args...) where {S,T} - hr = hour(time) - mn = minute(time) - s = second(Int, time) - daysec = Int64((j2000(date) - 0.5) * SECONDS_PER_DAY) - hoursec = Int64(hour(time) * SECONDS_PER_HOUR) - minutesec = Int64(minute(time) * SECONDS_PER_MINUTE) - sec = Int64(s) + minutesec + hoursec + daysec + daysec = round(Int64, (j2000(date) - 0.5) * SECONDS_PER_DAY) + horsec = round(Int64, hour(time) * SECONDS_PER_HOUR) + minsec = round(Int64, minute(time) * SECONDS_PER_MINUTE) + sec = daysec + horsec + minsec + second(time) + return Epoch{S}(sec, time.fraction) end diff --git a/test/epochs.jl b/test/epochs.jl index ad2c84e..bb04624 100644 --- a/test/epochs.jl +++ b/test/epochs.jl @@ -79,11 +79,11 @@ end @testset "Precision" begin ep = TAIEpoch(TAIEpoch(2000, 1, 1, 12), 2eps()) @test ep.second == 0 - @test ep.fraction ≈ 2eps() + @test ep.fraction == 2eps() ep += 10000centuries @test ep.second == value(seconds(10000centuries)) - @test ep.fraction ≈ 2eps() + @test ep.fraction == 2eps() # Issue 44 elong1 = 0.0