Skip to content

Commit

Permalink
Rename get to value
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Feb 2, 2019
1 parent 0f31fe6 commit 3954604
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/AstroTime.jl
Expand Up @@ -153,7 +153,7 @@ macro timescale(scale::Symbol, ep::Symbol, args...)
)
Dates.default_format(::Type{$epoch}) = Dates.ISODateTimeFormat
function AstroTime.Epochs.tai_offset(::$sc, $ep)
$args[end]
$(args[end])
end

nothing
Expand Down
14 changes: 7 additions & 7 deletions src/Epochs.jl
Expand Up @@ -124,9 +124,9 @@ function Epoch{S}(jd1::T, jd2::T=zero(T); origin=:j2000) where {S, T<:Number}
if origin == :j2000
# pass
elseif origin == :julian
jd1 -= get(J2000_TO_JULIAN)
jd1 -= value(J2000_TO_JULIAN)
elseif origin == :mjd
jd1 -= get(J2000_TO_MJD)
jd1 -= value(J2000_TO_MJD)
else
throw(ArgumentError("Unknown Julian epoch: $origin"))
end
Expand Down Expand Up @@ -160,7 +160,7 @@ julian(ep::Epoch, tai_offset) = j2000(ep, tai_offset) + J2000_TO_JULIAN
modified_julian(ep::Epoch, tai_offset) = j2000(ep, tai_offset) + J2000_TO_MJD

function julian_split(ep::Epoch, tai_offset)
jd = get(julian(ep, tai_offset))
jd = value(julian(ep, tai_offset))
jd1 = trunc(jd)
jd2 = jd - jd1
(jd1 * days, jd2 * days)
Expand Down Expand Up @@ -453,11 +453,11 @@ function ==(a::Epoch, b::Epoch)
a.epoch == b.epoch && a.offset == b.offset
end

<(ep1::Epoch, ep2::Epoch) = get(ep1 - ep2) < 0.0
isless(ep1::Epoch, ep2::Epoch) = isless(get(ep1 - ep2), 0.0)
<(ep1::Epoch, ep2::Epoch) = value(ep1 - ep2) < 0.0
isless(ep1::Epoch, ep2::Epoch) = isless(value(ep1 - ep2), 0.0)

+(ep::Epoch{S}, p::Period) where {S} = Epoch{S}(ep, get(seconds(p)))
-(ep::Epoch{S}, p::Period) where {S} = Epoch{S}(ep, -get(seconds(p)))
+(ep::Epoch{S}, p::Period) where {S} = Epoch{S}(ep, value(seconds(p)))
-(ep::Epoch{S}, p::Period) where {S} = Epoch{S}(ep, -value(seconds(p)))

"""
-(a::Epoch, b::Epoch)
Expand Down
20 changes: 10 additions & 10 deletions src/Periods.jl
Expand Up @@ -4,7 +4,7 @@ import Base: -, *, /, +, get, isapprox, show

export TimeUnit, Second, Minute, Hour, Day, Year, Century,
seconds, minutes, hours, days, years, centuries,
Period, -, *, /, +, get,
Period, -, *, /, +, value,
SECONDS_PER_MINUTE,
SECONDS_PER_HOUR,
SECONDS_PER_DAY,
Expand Down Expand Up @@ -104,37 +104,37 @@ struct Period{U<:TimeUnit,T<:Number}
Period{U}(Δt::T) where {U<:TimeUnit,T<:Number} = new{U,T}(U, Δt)
end

get(p::Period) = p.Δt
value(p::Period) = p.Δt

plural(p::Period{U, T}) where {U, T} = get(p) == one(T) ? "" : "s"
plural(p::Period{U, T}) where {U, T} = value(p) == one(T) ? "" : "s"

function show(io::IO, p::Period{Second})
v = get(p)
v = value(p)
print(io, v, v isa Integer && v == 1 ? " second" : " seconds")
end

function show(io::IO, p::Period{Minute})
v = get(p)
v = value(p)
print(io, v, v isa Integer && v == 1 ? " minute" : " minutes")
end

function show(io::IO, p::Period{Hour})
v = get(p)
v = value(p)
print(io, v, v isa Integer && v == 1 ? " hour" : " hours")
end

function show(io::IO, p::Period{Day})
v = get(p)
v = value(p)
print(io, v, v isa Integer && v == 1 ? " day" : " days")
end

function show(io::IO, p::Period{Year})
v = get(p)
v = value(p)
print(io, v, v isa Integer && v == 1 ? " year" : " years")
end

function show(io::IO, p::Period{Century})
v = get(p)
v = value(p)
print(io, v, v isa Integer && v == 1 ? " century" : " centuries")
end

Expand All @@ -148,7 +148,7 @@ end
(/)(x::T, p::Period) where {T<:Number} = Period{p.unit}(x / p.Δ)
(/)(p::Period, x::T) where {T<:Number} = Period{p.unit}(p.Δt / x)

isapprox(p1::Period{U}, p2::Period{U}) where {U<:TimeUnit} = get(p1) get(p2)
isapprox(p1::Period{U}, p2::Period{U}) where {U<:TimeUnit} = value(p1) value(p2)

(::Second)(p::Period{Second}) = p
(::Second)(p::Period{Minute}) = Period{Second}(p.Δt * SECONDS_PER_MINUTE)
Expand Down
4 changes: 2 additions & 2 deletions src/leapseconds.jl
Expand Up @@ -19,7 +19,7 @@ end
@inline function getoffset(t::TAIOffset, ep::Epoch)
t.slope_tai == 0.0 && return t.offset

t.offset + get(ep - t.reference) * t.slope_tai
t.offset + value(ep - t.reference) * t.slope_tai
end

@inline function getoffset(to::TAIOffset, d::Date, t::Time)
Expand Down Expand Up @@ -58,7 +58,7 @@ for (ep, offset, dep, rate) in zip(EPOCHS, OFFSETS, DRIFT_EPOCHS, DRIFT_RATES)
start_offset = offset + (ep - dep) * rate
stop = TAIEpoch(tai, start_offset)
slope = rate / SECONDS_PER_DAY
leap = get(stop - start) / (1 + slope)
leap = value(stop - start) / (1 + slope)
o = TAIOffset(start, ep + LeapSeconds.MJD_EPOCH,
TAIEpoch(start, leap),
ref,
Expand Down
10 changes: 5 additions & 5 deletions src/offsets.jl
Expand Up @@ -12,8 +12,8 @@ tai_offset(ep::Epoch) = ep.ts_offset

tai_offset(::InternationalAtomicTime, ep) = 0.0
tai_offset(::TerrestrialTime, ep) = OFFSET_TAI_TT
tai_offset(::GeocentricCoordinateTime, ep) = tai_offset(TT, ep) + LG_RATE * get(ep - EPOCH_77)
tai_offset(::BarycentricCoordinateTime, ep) = tai_offset(TDB, ep) + LB_RATE * get(ep - EPOCH_77)
tai_offset(::GeocentricCoordinateTime, ep) = tai_offset(TT, ep) + LG_RATE * value(ep - EPOCH_77)
tai_offset(::BarycentricCoordinateTime, ep) = tai_offset(TDB, ep) + LB_RATE * value(ep - EPOCH_77)

@inline function tai_offset(::CoordinatedUniversalTime, ep)
offset = findoffset(ep)
Expand All @@ -23,7 +23,7 @@ tai_offset(::BarycentricCoordinateTime, ep) = tai_offset(TDB, ep) + LB_RATE * ge
end

@inline function tai_offset(::UniversalTime, ep)
jd = get(julian(UTC, ep))
jd = value(julian(UTC, ep))
tai_offset(UTC, ep) + getΔUT1(jd)
end

Expand All @@ -46,7 +46,7 @@ the quantity TDB-TT can differ by as much as ~4 microseconds. See
"""
@inline function tai_offset(::BarycentricDynamicalTime, ep)
dt = get(j2000(TT, ep))
dt = value(j2000(TT, ep))
g = deg2rad(357.53 + 0.9856003dt)
tai_offset(TT, ep) + 0.001658sin(g) + 0.000014sin(2g)
end
Expand All @@ -58,7 +58,7 @@ Test
"""
function tai_offset(::BarycentricDynamicalTime, ep, elong, u, v)
ut = fractionofday(UT1Epoch(ep))
t = get(centuries(j2000(TT, ep))) / 10.0
t = value(centuries(j2000(TT, ep))) / 10.0
# Convert UT to local solar time in radians.
tsol = mod(ut, 1.0) * 2π + elong

Expand Down
2 changes: 1 addition & 1 deletion src/range.jl
Expand Up @@ -5,7 +5,7 @@ import Base: (:)
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)
StepRangeLen(start, step, floor(Int, value(stop-start)/value(step))+1)
end

Base.step(r::StepRangeLen{T}) where {T<:Epoch} = r.step
Expand Down
2 changes: 1 addition & 1 deletion test/epochs.jl
Expand Up @@ -5,7 +5,7 @@
@test ep.offset 2eps()

ep += 10000centuries
@test ep.epoch == get(seconds(10000centuries))
@test ep.epoch == value(seconds(10000centuries))
@test ep.offset 2eps()
end
@testset "Parsing" begin
Expand Down

0 comments on commit 3954604

Please sign in to comment.