Skip to content

Commit

Permalink
Merge b4e0307 into d82fc87
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee authored Jul 29, 2018
2 parents d82fc87 + b4e0307 commit d83e72c
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 542 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ dist: trusty
language: julia
os:
- linux
# - osx
- osx
julia:
- 0.6
- 0.7
- nightly
matrix:
allow_failures:
Expand Down
12 changes: 7 additions & 5 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
julia 0.6
ItemGraphs 0.2.0
MuladdMacro 0.0.2
julia 0.7-beta
EarthOrientation 0.2.0
OptionalData 0.1.0
RemoteFiles 0.1.0
# ItemGraphs 0.2.0
LeapSeconds
MuladdMacro 0.0.2
# OptionalData 0.1.0
Reexport 0.1.0
# RemoteFiles 0.1.0
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
matrix:
Expand Down
72 changes: 32 additions & 40 deletions src/AstroTime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,46 @@ import RemoteFiles: path, isfile

export @timescale

include("utils.jl")

include("LeapSeconds.jl")
include("TimeScales.jl")
include("Periods.jl")
include("Epochs.jl")
#= include("Epochs.jl") =#
include("Epochs2.jl")

@reexport using .TimeScales
@reexport using .Periods
@reexport using .LeapSeconds
@reexport using .Epochs

function __init__()
isfile(LSK_FILE) && push!(LSK_DATA, path(LSK_FILE))
end

"""
@timescale scale
Define a new timescale and the corresponding `Epoch` type alias.
# Example
```jldoctest
julia> @timescale Custom
julia> Custom <: TimeScale
true
julia> CustomEpoch == Epoch{Custom, T} where T <: Number
true
```
"""
macro timescale(scale)
if !(scale isa Symbol)
error("Invalid time scale name.")
end
epoch = Symbol(scale, "Epoch")
return quote
struct $(esc(scale)) <: TimeScale end
const $(esc(epoch)) = Epoch{$(esc(scale))}
nothing
end
end
#= @reexport using .Epochs =#
@reexport using .Epochs2

#= """ =#
#= @timescale scale =#
#= =#
#= Define a new timescale and the corresponding `Epoch` type alias. =#
#= =#
#= # Example =#
#= =#
#= ```jldoctest =#
#= julia> @timescale Custom =#
#= =#
#= julia> Custom <: TimeScale =#
#= true =#
#= julia> CustomEpoch == Epoch{Custom, T} where T <: Number =#
#= true =#
#= ``` =#
#= """ =#
#= macro timescale(scale) =#
#= if !(scale isa Symbol) =#
#= error("Invalid time scale name.") =#
#= end =#
#= epoch = Symbol(scale, "Epoch") =#
#= return quote =#
#= struct $(esc(scale)) <: TimeScale end =#
#= const $(esc(epoch)) = Epoch{$(esc(scale))} =#
#= nothing =#
#= end =#
#= end =#

function update()
EarthOrientation.update()
download(LSK_FILE)
push!(LSK_DATA, path(LSK_FILE))
nothing
end

Expand Down
10 changes: 6 additions & 4 deletions src/Epochs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ using EarthOrientation
using ERFA

import Base: +, -, ==, isapprox, isless
import Dates
using Dates: DateTime, @dateformat_str

using ..TimeScales, ..Periods
import ..TimeScales: acronyms
import ..LeapSeconds: leapseconds, LSK_DATA
import LeapSeconds: offset_tai_utc

export Epoch, julian, julian1, julian2, +, -, ==, isapprox, isless,
leapseconds, jd2000, jd1950, mjd, timescale
offset_tai_utc, jd2000, jd1950, mjd, timescale

const date_fmt = dateformat"yyyy-mm-ddTHH:MM:SS.sss"

Expand Down Expand Up @@ -90,7 +92,7 @@ julia> DateTime(Epoch{TT}(2017, 3, 14, 7, 18, 20, 325))
2017-03-14T07:18:20.325
```
"""
function Base.DateTime(ep::Epoch{T}) where {T}
function DateTime(ep::Epoch{T}) where {T}
dt = ERFA.d2dtf(string(T), 3, julian1(ep), julian2(ep))
DateTime(dt...)
end
Expand Down Expand Up @@ -135,7 +137,7 @@ jd1950(ep) = julian(ep) - J1950
(::Century)(ep::Epoch, base=0.0) = centuries((julian1(ep) - base + julian2(ep)) * days)

dut1(ep::Epoch) = getΔUT1(julian(ep))
leapseconds(ep::Epoch) = leapseconds(julian(ep))
offset_tai_utc(ep::Epoch) = offset_tai_utc(julian(ep))

function isapprox(a::Epoch{T}, b::Epoch{T}) where {T}
return julian(a) julian(b)
Expand Down
65 changes: 65 additions & 0 deletions src/Epochs2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module Epochs2

using LeapSeconds: offset_tai_utc
using EarthOrientation: getΔUT1
using Dates: DateTime, datetime2julian

using ..TimeScales

export Epoch2

const OFFSET_TAI_TT = 32.184
const SECONDS_PER_DAY = 86400.0
const J2000_EPOCH = datetime2julian(DateTime(2000, 1, 1, 12, 0, 0)) * SECONDS_PER_DAY
const REF_EPOCH = datetime2julian(DateTime(1977, 1, 1)) * SECONDS_PER_DAY
const LG_RATE = 6.969290134e-10
const LB_RATE = 1.550519768e-8

struct Epoch2{S, T}
epoch::Int64
offset::T
Epoch2{S}(epoch, offset::T) where {S, T} = new{S::TimeScale, T}(epoch, offset)
end

function Epoch2{S}(epoch, offset, Δt) where S
sum = offset + Δt

if !isfinite(sum)
offset′ = sum
epoch′ = sum < 0 ? typemin(Int64) : typemax(Int64)
else
o′ = sum - Δt
d′ = sum - o′
Δ0 = offset - o′
Δd = Δt - d′
residual = Δ0 + Δd
dl = floor(Int64, sum)
offset′ = (sum - dl) + residual
epoch′ = epoch + dl
end

Epoch2{S}(epoch′, offset′)
end

Epoch2{S}(ep::Epoch2{S}, Δt) where {S} = Epoch2{S}(ep.epoch, ep.offset, Δt)

function Epoch2{S2}(ep::Epoch2{S1}) where {S1, S2}
Δt = offset(S2, ep) - offset(S1, ep)
Epoch2{S2}(ep.epoch, ep.offset, Δt)
end

julian(ep::Epoch2) = (ep.epoch + ep.offset) / SECONDS_PER_DAY

offset(::InternationalAtomicTime, ep) = 0.0
offset(::TerrestrialTime, ep) = OFFSET_TAI_TT
offset(::CoordinatedUniversalTime, ep) = offset_tai_utc(julian(ep))
offset(::UniversalTime, ep) = offset(UTC, ep) + getΔUT1(julian(ep))
offset(::GeocentricCoordinateTime, ep) = offset(TT, ep) + LG_RATE * (ep.epoch - REF_EPOCH + ep.offset)
offset(::BarycentricCoordinateTime, ep) = offset(TT, ep) + LB_RATE * (ep.epoch - REF_EPOCH + ep.offset)
function offset(::BarycentricDynamicalTime, ep)
dt = (ep.epoch - J2000 + ep.offset) / SECONDS_PER_DAY
g = 357.53 + 0.9856003dt
offset(TT, ep) + 0.001658sind(g) + 0.000014sind(2g)
end

end
116 changes: 0 additions & 116 deletions src/LeapSeconds.jl

This file was deleted.

3 changes: 3 additions & 0 deletions src/constants.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Dates
using Dates: DateTime

export MJD, J2000, J1950,
SECONDS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_YEAR, SECONDS_PER_CENTURY,
MINUTES_PER_HOUR, MINUTES_PER_DAY, MINUTES_PER_YEAR, MINUTES_PER_CENTURY,
Expand Down
Loading

0 comments on commit d83e72c

Please sign in to comment.