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

chore(Elixir): Fix warnings emitted by elixir 1.16 #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

config :logger, utc_log: true
config :tzdata, :autoupdate, :enabled
Expand Down
26 changes: 13 additions & 13 deletions lib/tzdata.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ defmodule Tzdata do
DateTime. This includes aliases.
"""
@spec zone_list() :: [Calendar.time_zone]
def zone_list, do: Tzdata.ReleaseReader.zone_and_link_list
def zone_list, do: Tzdata.ReleaseReader.zone_and_link_list()

@doc """
Like zone_list, but excludes aliases for zones.
"""
@spec canonical_zone_list() :: [Calendar.time_zone]
def canonical_zone_list, do: Tzdata.ReleaseReader.zone_list
def canonical_zone_list, do: Tzdata.ReleaseReader.zone_list()

@doc """
A list of aliases for zone names. For instance Europe/Jersey
is an alias for Europe/London. Aliases are also known as linked zones.
"""
@spec zone_alias_list() :: [Calendar.time_zone]
def zone_alias_list, do: Tzdata.ReleaseReader.link_list
def zone_alias_list, do: Tzdata.ReleaseReader.link_list()

@doc """
Takes the name of a zone. Returns true if zone exists. Otherwise false.
Expand Down Expand Up @@ -87,19 +87,19 @@ defmodule Tzdata do
@doc """
Returns a map of links. Also known as aliases.

iex> Tzdata.links["Europe/Jersey"]
iex> Tzdata.links()["Europe/Jersey"]
"Europe/London"
"""
@spec links() :: %{Calendar.time_zone => Calendar.time_zone}
def links, do: Tzdata.ReleaseReader.links
def links, do: Tzdata.ReleaseReader.links()

@doc """
Returns a map with keys being group names and the values lists of
time zone names. The group names mirror the file names used by the tzinfo
database.
"""
@spec zone_lists_grouped() :: %{atom() => [Calendar.time_zone]}
def zone_lists_grouped, do: Tzdata.ReleaseReader.by_group
def zone_lists_grouped, do: Tzdata.ReleaseReader.by_group()

@doc """
Returns tzdata release version as a string.
Expand All @@ -110,7 +110,7 @@ defmodule Tzdata do
"2014i"
"""
@spec tzdata_version() :: String.t
def tzdata_version, do: Tzdata.ReleaseReader.release_version
def tzdata_version, do: Tzdata.ReleaseReader.release_version()

@doc """
Returns a list of periods for the `zone_name` provided as an argument.
Expand Down Expand Up @@ -225,12 +225,12 @@ defmodule Tzdata do

# Use dynamic periods for points in time that are about 40 years into the future
@years_in_the_future_where_precompiled_periods_are_used 40
@point_from_which_to_use_dynamic_periods :calendar.datetime_to_gregorian_seconds {{(:calendar.universal_time|>elem(0)|>elem(0)) + @years_in_the_future_where_precompiled_periods_are_used, 1, 1}, {0, 0, 0}}
@point_from_which_to_use_dynamic_periods :calendar.datetime_to_gregorian_seconds {{(:calendar.universal_time()|>elem(0)|>elem(0)) + @years_in_the_future_where_precompiled_periods_are_used, 1, 1}, {0, 0, 0}}
defp possible_periods_for_zone_and_time(zone_name, time_point, time_type) when time_point >= @point_from_which_to_use_dynamic_periods do
if Tzdata.FarFutureDynamicPeriods.zone_in_30_years_in_eternal_period?(zone_name) do
periods(zone_name)
else
link_status = Tzdata.ReleaseReader.links |> Map.get(zone_name)
link_status = Tzdata.ReleaseReader.links() |> Map.get(zone_name)
if link_status == nil do
Tzdata.FarFutureDynamicPeriods.periods_for_point_in_time(time_point, zone_name)
else
Expand Down Expand Up @@ -264,13 +264,13 @@ defmodule Tzdata do

## Example

iex> Tzdata.leap_seconds_with_tai_diff |> Enum.take(2)
iex> Tzdata.leap_seconds_with_tai_diff() |> Enum.take(2)
[%{date_time: {{1972, 6, 30}, {23, 59, 60}}, tai_diff: 11},
%{date_time: {{1972, 12, 31}, {23, 59, 60}}, tai_diff: 12}]
"""
@spec leap_seconds_with_tai_diff() :: [%{date_time: :calendar.datetime(), tai_diff: integer}]
def leap_seconds_with_tai_diff do
leap_seconds_data = Tzdata.ReleaseReader.leap_sec_data
leap_seconds_data = Tzdata.ReleaseReader.leap_sec_data()
leap_seconds_data.leap_seconds
end

Expand All @@ -283,7 +283,7 @@ defmodule Tzdata do

## Example

iex> Tzdata.leap_seconds |> Enum.take(2)
iex> Tzdata.leap_seconds() |> Enum.take(2)
[{{1972, 6, 30}, {23, 59, 60}},
{{1972, 12, 31}, {23, 59, 60}}]
"""
Expand All @@ -305,7 +305,7 @@ defmodule Tzdata do
"""
@spec leap_second_data_valid_until() :: :calendar.datetime()
def leap_second_data_valid_until do
leap_seconds_data = Tzdata.ReleaseReader.leap_sec_data
leap_seconds_data = Tzdata.ReleaseReader.leap_sec_data()
leap_seconds_data.valid_until
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tzdata/basic_data_map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Tzdata.BasicDataMap do

by_group = all_files_read
|> Enum.map(fn {name, file_read} -> {name, Organizer.zone_and_link_list(file_read)} end)
|> Enum.into(Map.new)
|> Enum.into(Map.new())
{:ok,
%{rules: rules,
zones: zones,
Expand Down
2 changes: 1 addition & 1 deletion lib/tzdata/data_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ defmodule Tzdata.DataBuilder do
defp leap_sec_data(tzdata_dir), do: LeapSecParser.read_file(tzdata_dir)

def ets_file_name_for_release_version(release_version) do
"#{release_dir()}/#{release_version}.v#{Tzdata.EtsHolder.file_version}.ets"
"#{release_dir()}/#{release_version}.v#{Tzdata.EtsHolder.file_version()}.ets"
end

def ets_table_name_for_release_version(release_version) do
Expand Down
4 changes: 2 additions & 2 deletions lib/tzdata/ets_holder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ defmodule Tzdata.EtsHolder do
make_sure_a_release_dir_exists()

cond do
release_files() == [] and Util.custom_data_dir_configured? ->
release_files() == [] and Util.custom_data_dir_configured?() ->
Logger.info("No tzdata release files found in custom data dir. Copying release file from tzdata priv dir.")
copy_release_dir_from_priv()
release_files() == [] and not Util.custom_data_dir_configured? ->
release_files() == [] and not Util.custom_data_dir_configured?() ->
Logger.error("No tzdata release files found!")
true ->
nil
Expand Down
2 changes: 1 addition & 1 deletion lib/tzdata/far_future_dynamic_periods.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Tzdata.FarFutureDynamicPeriods do
alias Tzdata.Util

# February 1st 30 years from compile time
@greg_sec_30_years_from_now :calendar.datetime_to_gregorian_seconds {{(:calendar.universal_time|>elem(0)|>elem(0)) + 30, 2, 1}, {0, 0, 0}}
@greg_sec_30_years_from_now :calendar.datetime_to_gregorian_seconds {{(:calendar.universal_time()|>elem(0)|>elem(0)) + 30, 2, 1}, {0, 0, 0}}

# 30 years from compile time, is the zone in a period
# that runs until :max ? Ie. it is not using DST
Expand Down
2 changes: 1 addition & 1 deletion lib/tzdata/tzdata_app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Tzdata.App do
{:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)

# Make zone atoms exist so that when to_existing_atom is called, all of the zones exist
Tzdata.zone_list |> Enum.map(&(&1 |> String.to_atom))
Tzdata.zone_list() |> Enum.map(&(&1 |> String.to_atom))

{:ok, pid}
end
Expand Down
8 changes: 4 additions & 4 deletions test/tzdata_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ defmodule TzdataTest do
|> Kernel.+(3600 * 24 * 365 * 150)

# This should not raise any exceptions
Tzdata.zone_list
Tzdata.zone_list()
|> Enum.reject(&(Enum.member?(@moroccan_time_zones, &1)))
|> Enum.map(fn(zone) -> Tzdata.periods_for_time(zone, point_in_time, :wall) end)
end

@tag :skip
test "Get periods for point in time far away in the future. For all timezones except Moroccan ones." do
# roughly 150 years from now
point_in_time = :calendar.universal_time |> :calendar.datetime_to_gregorian_seconds |> Kernel.+(3600*24*365*150)
point_in_time = :calendar.universal_time() |> :calendar.datetime_to_gregorian_seconds |> Kernel.+(3600*24*365*150)
# This should not raise any exceptions
Tzdata.zone_list
Tzdata.zone_list()
|> Enum.filter(&(Enum.member?(@moroccan_time_zones, &1)))
|> Enum.map(fn(zone) -> Tzdata.periods_for_time(zone, point_in_time, :wall) end)
Tzdata.zone_list() |> Enum.map(&Tzdata.periods_for_time(&1, point_in_time, :wall))
Expand Down Expand Up @@ -115,7 +115,7 @@ defmodule TzdataTest do
# create random strings that will be used for zone names and could be turned into atoms
time_zone_names =
0..1000
|> Enum.map(&"Fake/#{&1}-#{:crypto.rand_uniform(1, 9_999_999)}")
|> Enum.map(&"Fake/#{&1}-#{:rand.uniform(9_999_999)}")

time_zone_names
|> Enum.map(&Tzdata.periods_for_time(&1, gregorian_seconds, :utc))
Expand Down