Skip to content

Commit

Permalink
Implement Epoch ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Aug 28, 2018
1 parent 35a369b commit 3b8c824
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Epochs.jl
Expand Up @@ -195,6 +195,8 @@ function Epoch{S2}(ep::Epoch{S1}) where {S1, S2}
Epoch{S2}(ep.epoch, ep.offset, tai_offset(S2, ep))
end

Epoch{S, T}(ep::Epoch{S, T}) where {S, T} = ep

function isapprox(a::Epoch, b::Epoch)
a.epoch == b.epoch && a.offset b.offset
end
Expand All @@ -221,6 +223,7 @@ for scale in TimeScales.ACRONYMS
end

include("leapseconds.jl")
include("range.jl")

const JULIAN_EPOCH = TTEpoch(AstroDates.JULIAN_EPOCH, AstroDates.H12)
const J2000_EPOCH = TTEpoch(AstroDates.J2000_EPOCH, AstroDates.H12)
Expand Down
5 changes: 3 additions & 2 deletions src/Periods.jl
@@ -1,10 +1,10 @@
module Periods

import Base: *, /, get, isapprox, show
import Base: -, *, /, get, isapprox, show

export TimeUnit, Second, Minute, Hour, Day, Year, Century,
seconds, minutes, hours, days, years, centuries,
Period, *, /, get,
Period, -, *, /, get,
SECONDS_PER_MINUTE,
SECONDS_PER_HOUR,
SECONDS_PER_DAY,
Expand Down Expand Up @@ -85,6 +85,7 @@ show(io::IO, p::Period{Century}) = print(io, "$(get(p)) centuries")

(*)(Δt::T, ::U) where {T<:Number, U<:TimeUnit} = Period{U}(Δt)

(-)(p::Period) = Period{p.unit}(-p.Δt)
(*)(x::T, p::Period) where {T<:Number} = Period{p.unit}(p.Δt * x)
(*)(p::Period, x::T) where {T<:Number} = Period{p.unit}(p.Δt * x)
(/)(x::T, p::Period) where {T<:Number} = Period{p.unit}(x / p.Δ)
Expand Down
12 changes: 12 additions & 0 deletions src/range.jl
@@ -0,0 +1,12 @@
import Base: (:)

(:)(start::Epoch{S}, stop::Epoch{S}) where {S} = (:)(start, 1.0days, stop)

function (:)(start::Epoch{S}, step::Period, stop::Epoch{S}) where S
step = seconds(step)
step = start < stop ? step : -step
StepRangeLen(start, step, floor(Int, get(stop-start)/get(step))+1)
end

Base.step(r::StepRangeLen{T}) where {T<:Epoch} = r.step

0 comments on commit 3b8c824

Please sign in to comment.