Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.3' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'.
- '1.4' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'.
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
- 'lts'
- 'nightly'
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.7.1"
[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
EarthOrientation = "732a3c5d-d6c0-58bc-adb1-1b51709a25e2"
ItemGraphs = "d5eda45b-7e79-5788-9687-2c6ab7b96158"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LeapSeconds = "2f5f767c-a11e-5269-a972-637d4b97c32d"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
Expand All @@ -14,13 +14,13 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
[compat]
ERFA = "0.5, 0.6, 1.0"
EarthOrientation = "0.7"
ItemGraphs = "0.4"
Graphs = "1.12.0"
LeapSeconds = "1.1"
MacroTools = "0.5"
Measurements = "2"
MuladdMacro = "0.2"
Reexport = "0.2, 1"
julia = "1.3"
julia = "1.4"

[extras]
ERFA = "17511681-8477-586a-8d98-4cfd5a1f2ec3"
Expand Down
66 changes: 49 additions & 17 deletions src/TimeScales.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module TimeScales

using ItemGraphs: ItemGraph, add_edge!, add_vertex!, items

using Graphs
import Dates

export
Expand Down Expand Up @@ -77,24 +76,51 @@ for (acronym, name) in zip(ACRONYMS, NAMES)
end
end

const SCALES = ItemGraph{TimeScale}()

function register_scale!(s)
add_vertex!(SCALES, s)
# Create a DiGraph to store the time scales
const SCALES = SimpleDiGraph{Int}()
const SCALE_VERTICES = Dict{TimeScale, Int}()
const VERTEX_SCALES = Dict{Int, TimeScale}()

function register_scale!(s::TimeScale)
if !haskey(SCALE_VERTICES, s)
add_vertex!(SCALES)
v = nv(SCALES)
SCALE_VERTICES[s] = v
VERTEX_SCALES[v] = s
end
end

function link_scales!(s1, s2; oneway=false)
add_edge!(SCALES, s1, s2)
oneway || add_edge!(SCALES, s2, s1)
function link_scales!(s1::TimeScale, s2::TimeScale; oneway=false)
# Ensure both scales are registered
register_scale!(s1)
register_scale!(s2)

# Add the edge
add_edge!(SCALES, SCALE_VERTICES[s1], SCALE_VERTICES[s2])
oneway || add_edge!(SCALES, SCALE_VERTICES[s2], SCALE_VERTICES[s1])
end

link_scales!(TAI, TT)
link_scales!(TAI, UT1)
link_scales!(TT, TCG)
link_scales!(TT, TDB)
link_scales!(TCB, TDB)

find_path(from, to) = items(SCALES, from, to)
function find_path(from::TimeScale, to::TimeScale)
# Get vertex indices
v_from = SCALE_VERTICES[from]
v_to = SCALE_VERTICES[to]

# Find shortest path
path = dijkstra_shortest_paths(SCALES, v_from)

# Extract path vertices
path_vertices = Int[]
current = v_to
while current != v_from
pushfirst!(path_vertices, current)
current = path.parents[current]
current == 0 && return TimeScale[] # No path exists
end
pushfirst!(path_vertices, v_from)

# Convert vertices back to TimeScales
return [VERTEX_SCALES[v] for v in path_vertices]
end

struct NotATimeScale <: TimeScale end

Expand All @@ -110,5 +136,11 @@ tryparse(::Any) = nothing
return val, i
end

end
# Initialize the graph with the time scale relationships
link_scales!(TAI, TT)
link_scales!(TAI, UT1)
link_scales!(TT, TCG)
link_scales!(TT, TDB)
link_scales!(TCB, TDB)

end
Loading