Skip to content

Commit

Permalink
Add warning when TZ database version is changed
Browse files Browse the repository at this point in the history
Changing the TZ database is useful for unit and compatability tests, but
production should rely on the current tested version in this lib. This adds
a warning message when a new version is supplied in the config to make that
point known
  • Loading branch information
jjcarstens authored and fhunleth committed May 19, 2022
1 parent a3c6483 commit 44caf16
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,7 @@ defmodule NervesTimeZones.MixProject do
package: package(),
source_url: @source_url,
compilers: [:elixir_make | Mix.compilers()],
make_env: fn ->
tzdata_version = Application.get_env(@app, :version, @tzdata_version)
tzdata_earliest_date = Application.get_env(@app, :earliest_date, @tzdata_earliest_date)
tzdata_latest_date = Application.get_env(@app, :latest_date, @tzdata_latest_date)

%{
"TZDATA_VERSION" => tzdata_version,
"TZDATA_EARLIEST_DATE" => to_string(tzdata_earliest_date),
"TZDATA_LATEST_DATE" => to_string(tzdata_latest_date)
}
end,
make_env: &make_env/0,
make_error_message: "",
make_targets: ["all"],
make_clean: ["clean"],
Expand Down Expand Up @@ -96,4 +86,26 @@ defmodule NervesTimeZones.MixProject do
source_url: @source_url
]
end

defp make_env() do
tzdata_version = Application.get_env(@app, :version, @tzdata_version)
tzdata_earliest_date = Application.get_env(@app, :earliest_date, @tzdata_earliest_date)
tzdata_latest_date = Application.get_env(@app, :latest_date, @tzdata_latest_date)

if tzdata_version != @tzdata_version do
msg = """
TZ database version #{tzdata_version} differs from the offically supported version #{@tzdata_version}
This is useful for unit and compatability tests, but should be avoided in production.
"""

IO.warn(msg, [])
end

%{
"TZDATA_VERSION" => tzdata_version,
"TZDATA_EARLIEST_DATE" => to_string(tzdata_earliest_date),
"TZDATA_LATEST_DATE" => to_string(tzdata_latest_date)
}
end
end

0 comments on commit 44caf16

Please sign in to comment.