Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TimeZones.jl relocatable #479

Merged
merged 21 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Curtis Vogt <curtis.vogt@gmail.com>"]
version = "1.19.0"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
omus marked this conversation as resolved.
Show resolved Hide resolved
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
InlineStrings = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48"
Expand All @@ -22,6 +23,7 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
TimeZonesRecipesBaseExt = "RecipesBase"

[compat]
Artifacts = "1"
Aqua = "0.8"
Dates = "1"
Downloads = "1"
Expand Down
23 changes: 22 additions & 1 deletion src/TimeZones.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module TimeZones

using Artifacts
using Dates
using Printf
using Scratch: @get_scratch!
Expand Down Expand Up @@ -33,13 +34,33 @@

_scratch_dir() = @get_scratch!("build")

const _COMPILED_DIR = Ref{String}(TZJData.ARTIFACT_DIR)
const _COMPILED_DIR = Ref{String}()

# TimeZone types used to disambiguate the context of a DateTime
# abstract type UTC <: TimeZone end # Already defined in the Dates stdlib
abstract type Local <: TimeZone end

function __init__()
# Must be set at runtime to ensure relocatability
_COMPILED_DIR[] = if isdefined(TZJData, :artifact_dir)
# Recent versions of TZJData are relocatable
TZJData.artifact_dir()

Check warning on line 47 in src/TimeZones.jl

View check run for this annotation

Codecov / codecov/patch

src/TimeZones.jl#L47

Added line #L47 was not covered by tests
else
# Backwards compatibility with TZJData v1.3.0 and below
hash = if TZJData.TZDATA_VERSION == "2024b"
Base.SHA1("7fdea2a12522469ca39925546d1fd93c10748180")
elseif TZJData.TZDATA_VERSION == "2024a"
Base.SHA1("520ce3f83be7fbb002cca87993a1b1f71fe10912")
elseif TZJData.TZDATA_VERSION == "2023d"
Base.SHA1("b071cffdb310f5d3ca640c09cfa3dc3f23d450ad")
elseif TZJData.TZDATA_VERSION == "2023c"
Base.SHA1("52e48e96c4df04eeebc6ece0d9f1c3b545f0544c")

Check warning on line 57 in src/TimeZones.jl

View check run for this annotation

Codecov / codecov/patch

src/TimeZones.jl#L52-L57

Added lines #L52 - L57 were not covered by tests
else
error("TZJData.jl with TZDATA_VERSION = $(TZJData.TZDATA_VERSION) is supposed to be relocatable!")
end
Artifacts.artifact_path(hash)
end

# Dates extension needs to happen everytime the module is loaded (issue #24)
init_dates_extension()

Expand Down
Loading