Skip to content

Commit

Permalink
Remove unnecessary type casts
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Apr 12, 2021
1 parent c500f86 commit bc4ee73
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/AstroDates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Epochs/accessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 5 additions & 7 deletions src/Epochs/dates.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/epochs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc4ee73

Please sign in to comment.