Skip to content

Commit

Permalink
Attach docs also to Epoch aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Aug 27, 2018
1 parent d6e476f commit ea54468
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/Epochs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ struct Epoch{S, T} <: Dates.AbstractDateTime
Epoch{S}(epoch::Int64, offset::T) where {S, T} = new{S::TimeScale, T}(epoch, offset)
end

for scale in TimeScales.ACRONYMS
epoch = Symbol(scale, "Epoch")
@eval begin
const $epoch = Epoch{$scale}
export $epoch
end
end

function Epoch{S}(epoch::Int64, offset, Δt) where S
sum = offset + Δt

Expand All @@ -56,6 +48,22 @@ function Epoch{S}(epoch::Int64, offset, Δt) where S
Epoch{S}(epoch′, offset′)
end

"""
Epoch{S}(ep::Epoch, Δt) where S
Construct a new `Epoch` with time scale `S` which is `ep` shifted by `Δt`
seconds.
### Example ###
```jldoctest
julia> t = UTCEpoch(2018, 2, 6, 20, 45, 0.0)
2018-02-06T20:45:00.000 UTC
julia> UTCEpoch(ep, 20.0)
2018-02-06T20:45:20.000 UTC
```
"""
Epoch{S}(ep::Epoch, Δt) where {S} = Epoch{S}(ep.epoch, ep.offset, Δt)

function j2000(scale, ep::Epoch)
Expand Down Expand Up @@ -145,6 +153,16 @@ isless(ep1::Epoch, ep2::Epoch) = isless(get(ep1 - ep2), 0.0)
-(ep::Epoch{S}, p::Period) where {S} = Epoch{S}(ep, -get(seconds(p)))
-(a::Epoch, b::Epoch) = ((a.epoch - b.epoch) + (a.offset - b.offset)) * seconds

for scale in TimeScales.ACRONYMS
epoch = Symbol(scale, "Epoch")
@eval begin
const $epoch = Epoch{$scale}
export $epoch

@doc @doc(Epoch{$scale}) $epoch
end
end

include("leapseconds.jl")

const JULIAN_EPOCH = TTEpoch(AstroDates.JULIAN_EPOCH, AstroDates.H12)
Expand Down

0 comments on commit ea54468

Please sign in to comment.