From f8b2d760025b418703c1db80e0f36bd03d2b7c03 Mon Sep 17 00:00:00 2001 From: Dennis Palmer Date: Mon, 15 Sep 2025 21:28:51 +0200 Subject: [PATCH 1/2] changes Erlang date tuples to Elixir Date structs --- README.md | 6 +- lib/holidays.ex | 4 +- lib/holidays/date_calculator/date_math.ex | 54 ++++------ lib/holidays/date_calculator/easter.ex | 19 ++-- .../date_calculator/weekend_modifier.ex | 54 +++++----- lib/holidays/define.ex | 10 +- lib/holidays/definitions/br.ex | 2 +- lib/holidays/definitions/de.ex | 10 +- lib/holidays/definitions/us.ex | 6 +- test/holidays/definitions/br_test.exs | 26 ++--- test/holidays/definitions/de_test.exs | 102 +++++++++--------- test/holidays/definitions/no_test.exs | 32 +++--- .../definitions/north_america_test.exs | 20 ++-- test/holidays/definitions/nyse_test.exs | 18 ++-- test/holidays/definitions/ups_test.exs | 20 ++-- test/holidays/definitions/us_test.exs | 32 +++--- 16 files changed, 199 insertions(+), 216 deletions(-) diff --git a/README.md b/README.md index de64643..b241a85 100644 --- a/README.md +++ b/README.md @@ -29,15 +29,15 @@ Add holidays to your list of dependencies in `mix.exs`: 3. Call the `on` function, passing in a date and a list of regions. ``` - iex> Holidays.on({2016, 1, 1}, [:us]) + iex> Holidays.on(~D[2016-01-01], [:us]) [%{name: "New Year's Day"}] ``` The `on` function gives a list of holidays for a date within specified regions. -Dates in Erlang (and therefore Elixir) are represented by the -`{year, month, day}` tuple. +Dates in Elixir are represented by the +`~D[yyyy-mm-dd]` sigil. Regions are often country codes, like `:us` or `:ca`, but may also be entities such as UPS (`:ups`) or the New York Stock Exchange diff --git a/lib/holidays.ex b/lib/holidays.ex index 3b7d3b6..dcbd880 100644 --- a/lib/holidays.ex +++ b/lib/holidays.ex @@ -25,11 +25,11 @@ defmodule Holidays do ## Examples - iex> Holidays.on({2016, 1, 1}, [:us]) + iex> Holidays.on(~D[2016-01-01], [:us]) [%{name: "New Year's Day"}] """ - @spec on(:calendar.date(), [region]) :: list + @spec on(Calendar.date(), [region]) :: list def on(date, regions) do Holidays.Define.on(date, regions) end diff --git a/lib/holidays/date_calculator/date_math.ex b/lib/holidays/date_calculator/date_math.ex index 7d4860f..3b612ac 100644 --- a/lib/holidays/date_calculator/date_math.ex +++ b/lib/holidays/date_calculator/date_math.ex @@ -1,21 +1,4 @@ defmodule Holidays.DateCalculator.DateMath do - @doc """ - Adds the given number of `days` to the given `date`. - - ## Examples - - iex> Holidays.DateCalculator.DateMath.add_days({2015, 12, 31}, 1) - {2016, 1, 1} - - iex> Holidays.DateCalculator.DateMath.add_days({2016, 1, 6}, -12) - {2015, 12, 25} - - """ - @spec add_days(:calendar.date(), integer) :: :calendar.date() - def add_days(date, days) do - :calendar.gregorian_days_to_date(:calendar.date_to_gregorian_days(date) + days) - end - @offset %{:first => 1, :second => 8, :third => 15, :fourth => 22} @doc """ @@ -23,7 +6,7 @@ defmodule Holidays.DateCalculator.DateMath do `week` may be one of :first, :second, :third, :fourth, :last - `weekday` may be a number between 1 and 7, which is the way Erlang + `weekday` may be a number between 1 and 7, which is the way Elixir represents Monday through Sunday. Or use one the atoms :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday @@ -31,15 +14,15 @@ defmodule Holidays.DateCalculator.DateMath do # The second Tuesday of June, 2013 iex> Holidays.DateCalculator.DateMath.get_weekth_day(2013, 6, :second, :tuesday) - {2013, 6, 11} + ~D[2013-06-11] # The third Friday of December, 2013 iex> Holidays.DateCalculator.DateMath.get_weekth_day(2013, 12, :third, :friday) - {2013, 12, 20} + ~D[2013-12-20] # The last Saturday of January, 2013 iex> Holidays.DateCalculator.DateMath.get_weekth_day(2013, 1, :last, :saturday) - {2013, 1, 26} + ~D[2013-01-26] """ @spec get_weekth_day( @@ -47,9 +30,9 @@ defmodule Holidays.DateCalculator.DateMath do pos_integer, Holidays.week(), Holidays.weekday() | pos_integer - ) :: :calendar.date() + ) :: Date.t() def get_weekth_day(year, month, :last, weekday) do - offset = :calendar.last_day_of_the_month(year, month) - 6 + offset = Date.days_in_month(Date.new!(year, month, 1)) - 6 do_get_weekth_day(year, month, offset, weekday) end @@ -68,22 +51,23 @@ defmodule Holidays.DateCalculator.DateMath do } @spec do_get_weekth_day(pos_integer, pos_integer, pos_integer, Holidays.weekday() | pos_integer) :: - :calendar.date() + Date.t() defp do_get_weekth_day(year, month, offset, weekday) when not is_integer(weekday) do do_get_weekth_day(year, month, offset, @daynum[weekday]) end defp do_get_weekth_day(year, month, offset, weekday) do - day = weekday - :calendar.day_of_the_week(year, month, offset) + offset + date = Date.new!(year, month, offset) + day = weekday - Date.day_of_week(date) + offset correct_offset(year, month, offset, day) end - @spec correct_offset(pos_integer, pos_integer, pos_integer, integer) :: :calendar.date() + @spec correct_offset(pos_integer, pos_integer, pos_integer, integer) :: Date.t() defp correct_offset(year, month, offset, day) when day < offset do - {year, month, day + 7} + Date.new!(year, month, day + 7) end - defp correct_offset(year, month, _offset, day), do: {year, month, day} + defp correct_offset(year, month, _offset, day), do: Date.new!(year, month, day) @dayname %{ 1 => :monday, @@ -103,22 +87,22 @@ defmodule Holidays.DateCalculator.DateMath do ## Examples - iex> Holidays.DateCalculator.DateMath.get_week_and_weekday({2016,1,29}) + iex> Holidays.DateCalculator.DateMath.get_week_and_weekday(~D[2016-01-29]) [{:last, :friday}] - iex> Holidays.DateCalculator.DateMath.get_week_and_weekday({2016,1,25}) + iex> Holidays.DateCalculator.DateMath.get_week_and_weekday(~D[2016-01-25]) [{:fourth, :monday}, {:last, :monday}] - iex> Holidays.DateCalculator.DateMath.get_week_and_weekday({2016,1,5}) + iex> Holidays.DateCalculator.DateMath.get_week_and_weekday(~D[2016-01-05]) [{:first, :tuesday}] """ - @spec get_week_and_weekday(:calendar.date()) :: [{Holidays.week(), Holidays.weekday()}] - def get_week_and_weekday({year, month, day} = date) do - day_name = @dayname[:calendar.day_of_the_week(date)] + @spec get_week_and_weekday(Date.t()) :: [{Holidays.week(), Holidays.weekday()}] + def get_week_and_weekday(%Date{day: day} = date) do + day_name = @dayname[Date.day_of_week(date)] week_name(div(day - 1, 7), day_name) ++ check_last_week( - :calendar.last_day_of_the_month(year, month) - day, + Date.days_in_month(date) - day, day_name ) end diff --git a/lib/holidays/date_calculator/easter.ex b/lib/holidays/date_calculator/easter.ex index 0b552e0..e9b93d1 100644 --- a/lib/holidays/date_calculator/easter.ex +++ b/lib/holidays/date_calculator/easter.ex @@ -1,16 +1,14 @@ defmodule Holidays.DateCalculator.Easter do - alias Holidays.DateCalculator.DateMath - @doc ~S""" Returns the date of Easter for the given `year` ## Examples iex> Holidays.DateCalculator.Easter.gregorian_easter_for(2016) - {2016, 3, 27} + ~D[2016-03-27] iex> Holidays.DateCalculator.Easter.gregorian_easter_for(2015) - {2015, 4, 5} + ~D[2015-04-05] """ def gregorian_easter_for(year) do @@ -31,23 +29,22 @@ defmodule Holidays.DateCalculator.Easter do month = (h + l - 7 * m + 114) |> div(31) day = ((h + l - 7 * m + 114) |> rem(31)) + 1 - {year, month, day} + Date.new!(year, month, day) end @doc ~S""" - Returns the date of Orthodox Easter in the given `year` ## Examples iex> Holidays.DateCalculator.Easter.gregorian_orthodox_easter_for(2016) - {2016, 5, 1} + ~D[2016-05-01] iex> Holidays.DateCalculator.Easter.gregorian_orthodox_easter_for(1815) - {1815, 4, 30} + ~D[1815-04-30] iex> Holidays.DateCalculator.Easter.gregorian_orthodox_easter_for(2101) - {2101, 4, 24} + ~D[2101-04-24] """ def gregorian_orthodox_easter_for(year) do @@ -69,7 +66,7 @@ defmodule Holidays.DateCalculator.Easter do 0 end - DateMath.add_days(j_date, offset) + Date.add(j_date, offset) end def julian_orthodox_easter_for(year) do @@ -80,6 +77,6 @@ defmodule Holidays.DateCalculator.Easter do j_month = 3 + div(i - j + 40, 44) j_day = i - j + 28 - 31 * div(j_month, 4) - {year, j_month, j_day} + Date.new!(year, j_month, j_day) end end diff --git a/lib/holidays/date_calculator/weekend_modifier.ex b/lib/holidays/date_calculator/weekend_modifier.ex index 63fa8c8..6b559b2 100644 --- a/lib/holidays/date_calculator/weekend_modifier.ex +++ b/lib/holidays/date_calculator/weekend_modifier.ex @@ -1,25 +1,23 @@ defmodule Holidays.DateCalculator.WeekendModifier do - alias Holidays.DateCalculator.DateMath - @doc """ Move `date` to Monday if it occurs on a Saturday or Sunday. ## Examples - iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_weekend({2015,12,5}) - {2015,12,7} + iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_weekend(~D[2015-12-05]) + ~D[2015-12-07] - iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_weekend({2015,12,6}) - {2015,12,7} + iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_weekend(~D[2015-12-06]) + ~D[2015-12-07] - iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_weekend({2015,12,8}) - {2015,12,8} + iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_weekend(~D[2015-12-08]) + ~D[2015-12-08] """ def to_monday_if_weekend(date) do - case :calendar.day_of_the_week(date) do - 7 -> DateMath.add_days(date, 1) - 6 -> DateMath.add_days(date, 2) + case Date.day_of_week(date) do + 6 -> Date.add(date, 2) + 7 -> Date.add(date, 1) _ -> date end end @@ -29,19 +27,19 @@ defmodule Holidays.DateCalculator.WeekendModifier do ## Examples - iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_sunday({2015,12,5}) - {2015,12,5} + iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_sunday(~D[2015-12-05]) + ~D[2015-12-05] - iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_sunday({2015,12,6}) - {2015,12,7} + iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_sunday(~D[2015-12-06]) + ~D[2015-12-07] - iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_sunday({2015,12,8}) - {2015,12,8} + iex> Holidays.DateCalculator.WeekendModifier.to_monday_if_sunday(~D[2015-12-08]) + ~D[2015-12-08] """ def to_monday_if_sunday(date) do - case :calendar.day_of_the_week(date) do - 7 -> DateMath.add_days(date, 1) + case Date.day_of_week(date) do + 7 -> Date.add(date, 1) _ -> date end end @@ -56,20 +54,20 @@ defmodule Holidays.DateCalculator.WeekendModifier do ## Examples - iex> Holidays.DateCalculator.WeekendModifier.to_weekday_if_weekend({2015,12,5}) - {2015,12,4} + iex> Holidays.DateCalculator.WeekendModifier.to_weekday_if_weekend(~D[2015-12-05]) + ~D[2015-12-04] - iex> Holidays.DateCalculator.WeekendModifier.to_weekday_if_weekend({2015,12,6}) - {2015,12,7} + iex> Holidays.DateCalculator.WeekendModifier.to_weekday_if_weekend(~D[2015-12-06]) + ~D[2015-12-07] - iex> Holidays.DateCalculator.WeekendModifier.to_weekday_if_weekend({2015,12,8}) - {2015,12,8} + iex> Holidays.DateCalculator.WeekendModifier.to_weekday_if_weekend(~D[2015-12-08]) + ~D[2015-12-08] """ def to_weekday_if_weekend(date) do - case :calendar.day_of_the_week(date) do - 7 -> DateMath.add_days(date, 1) - 6 -> DateMath.add_days(date, -1) + case Date.day_of_week(date) do + 7 -> Date.add(date, 1) + 6 -> Date.add(date, -1) _ -> date end end diff --git a/lib/holidays/define.ex b/lib/holidays/define.ex index 27209f9..6510e91 100644 --- a/lib/holidays/define.ex +++ b/lib/holidays/define.ex @@ -19,7 +19,7 @@ defmodule Holidays.Define do GenServer.cast(__MODULE__, {:add_entry, :fun, {name, function, regions}}) end - @spec on(:calendar.date(), [Holidays.region()]) :: list + @spec on(Date.t(), [Holidays.region()]) :: list def on(date, regions) do GenServer.call(__MODULE__, {:on, date, regions}) end @@ -30,7 +30,7 @@ defmodule Holidays.Define do on_fun(funs, date) end - defp on_static(holidays, {_, month, day}) do + defp on_static(holidays, %Date{month: month, day: day}) do holidays |> Enum.filter(fn {_, ^month, ^day, _} -> true @@ -44,7 +44,7 @@ defmodule Holidays.Define do |> Enum.flat_map(&on_nth(&1, holidays, date)) end - defp on_nth({week, weekday}, holidays, {_, month, _}) do + defp on_nth({week, weekday}, holidays, %Date{month: month}) do holidays |> Enum.filter(&match?({_, ^month, ^week, ^weekday, _}, &1)) |> Enum.map(fn {name, _, _, _, regions} -> %{name: name, regions: regions} end) @@ -58,10 +58,10 @@ defmodule Holidays.Define do defp apply_fun({mod, fun, args, days}, date) do apply_fun({mod, fun, args}, date) - |> DateMath.add_days(days) + |> Date.add(days) end - defp apply_fun({mod, fun, [:year]}, {year, _, _}) do + defp apply_fun({mod, fun, [:year]}, %Date{year: year}) do apply(mod, fun, [year]) end diff --git a/lib/holidays/definitions/br.ex b/lib/holidays/definitions/br.ex index 80557b9..854ac59 100644 --- a/lib/holidays/definitions/br.ex +++ b/lib/holidays/definitions/br.ex @@ -95,7 +95,7 @@ defmodule Holidays.Definitions.Br do :none iex> Holidays.Definitions.Br.election_day(2018) - {2018, 10, 7} + ~D[2018-10-07] """ def election_day(year) when rem(year, 4) == 2, do: DateMath.get_weekth_day(year, 10, :first, :sunday) diff --git a/lib/holidays/definitions/de.ex b/lib/holidays/definitions/de.ex index 7de984c..478e341 100644 --- a/lib/holidays/definitions/de.ex +++ b/lib/holidays/definitions/de.ex @@ -117,12 +117,16 @@ defmodule Holidays.Definitions.De do end def buss_und_bettag(year) do - wday = rem(:calendar.day_of_the_week(year, 11, 23), 7) + wday = + year + |> Date.new!(11, 23) + |> Date.day_of_week() + |> rem(7) if wday > 3 do - {year, 11, 23 - (wday - 3)} + Date.new!(year, 11, 23 - (wday - 3)) else - {year, 11, 23 - (wday + 4)} + Date.new!(year, 11, 23 - (wday + 4)) end end end diff --git a/lib/holidays/definitions/us.ex b/lib/holidays/definitions/us.ex index 7f86437..59ba4fc 100644 --- a/lib/holidays/definitions/us.ex +++ b/lib/holidays/definitions/us.ex @@ -101,16 +101,16 @@ defmodule Holidays.Definitions.Us do :none iex> Holidays.Definitions.Us.inauguration_day(2017) - {2017, 1, 20} + ~D[2017-01-20] iex> Holidays.Definitions.Us.inauguration_day(2018) :none """ - def inauguration_day(year) when rem(year, 4) == 1, do: {year, 1, 20} + def inauguration_day(year) when rem(year, 4) == 1, do: Date.new!(year, 1, 20) def inauguration_day(_year), do: :none def day_after_thanksgiving(year) do DateMath.get_weekth_day(year, 11, :fourth, :thursday) - |> DateMath.add_days(1) + |> Date.add(1) end end diff --git a/test/holidays/definitions/br_test.exs b/test/holidays/definitions/br_test.exs index 7f6c55d..8555e1c 100644 --- a/test/holidays/definitions/br_test.exs +++ b/test/holidays/definitions/br_test.exs @@ -9,17 +9,17 @@ defmodule Holidays.BrTest do doctest Holidays.Definitions.Br - holiday_test("Confraternização Universal", {2018, 1, 1}, :br) - holiday_test("Tiradentes", {2018, 4, 21}, :br) - holiday_test("Dia do Trabalhador", {2018, 5, 1}, :br) - holiday_test("Proclamação da Independência", {2018, 9, 7}, :br) - holiday_test("Nossa Senhora Aparecida", {2018, 10, 12}, :br) - holiday_test("Proclamação da República", {2018, 11, 15}, :br) - holiday_test("Dia da Consciência Negra", {2018, 11, 20}, :br) - holiday_test("Natal", {2018, 12, 25}, :br) - holiday_test("Carnaval", {2018, 2, 13}, :br) - holiday_test("Sexta-feira santa", {2018, 3, 30}, :br) - holiday_test("Páscoa", {2018, 4, 1}, :br) - holiday_test("Corpus Christi", {2018, 5, 31}, :br) - holiday_test("Eleições", {2018, 10, 7}, :br) + holiday_test("Confraternização Universal", ~D[2018-01-01], :br) + holiday_test("Tiradentes", ~D[2018-04-21], :br) + holiday_test("Dia do Trabalhador", ~D[2018-05-01], :br) + holiday_test("Proclamação da Independência", ~D[2018-09-07], :br) + holiday_test("Nossa Senhora Aparecida", ~D[2018-10-12], :br) + holiday_test("Proclamação da República", ~D[2018-11-15], :br) + holiday_test("Dia da Consciência Negra", ~D[2018-11-20], :br) + holiday_test("Natal", ~D[2018-12-25], :br) + holiday_test("Carnaval", ~D[2018-02-13], :br) + holiday_test("Sexta-feira santa", ~D[2018-03-30], :br) + holiday_test("Páscoa", ~D[2018-04-01], :br) + holiday_test("Corpus Christi", ~D[2018-05-31], :br) + holiday_test("Eleições", ~D[2018-10-07], :br) end diff --git a/test/holidays/definitions/de_test.exs b/test/holidays/definitions/de_test.exs index f966a74..4d43bc5 100644 --- a/test/holidays/definitions/de_test.exs +++ b/test/holidays/definitions/de_test.exs @@ -8,55 +8,55 @@ defmodule Holidays.DeTest do end # Test cases from Ruby gem: - holiday_test("Neujahrstag", {2009, 1, 1}, :de) - holiday_test("Karfreitag", {2009, 4, 10}, :de) - holiday_test("Ostermontag", {2009, 4, 13}, :de) - holiday_test("Tag der Arbeit", {2009, 5, 1}, :de) - holiday_test("Christi Himmelfahrt", {2009, 5, 21}, :de) - holiday_test("Pfingstmontag", {2009, 6, 1}, :de) - holiday_test("Tag der Deutschen Einheit", {2009, 10, 3}, :de) - holiday_test("1. Weihnachtstag", {2009, 12, 25}, :de) - holiday_test("1. Weihnachtstag", {2009, 12, 25}, :de_bw) - holiday_test("1. Weihnachtstag", {2009, 12, 25}, :de_by) - holiday_test("1. Weihnachtstag", {2009, 12, 25}, :de_by_aux) - holiday_test("2. Weihnachtstag", {2009, 12, 26}, :de) - holiday_test("1. Weihnachtstag", {2009, 12, 25}, [:de_bw, :de_by_aux]) - - holiday_test("Heilige Drei Könige", {2009, 1, 6}, :de_bw) - holiday_test("Heilige Drei Könige", {2009, 1, 6}, :de_by) - holiday_test("Heilige Drei Könige", {2009, 1, 6}, :de_st) - - holiday_test("Fronleichnam", {2009, 6, 11}, :de_bw) - holiday_test("Fronleichnam", {2009, 6, 11}, :de_by) - holiday_test("Fronleichnam", {2009, 6, 11}, :de_he) - holiday_test("Fronleichnam", {2009, 6, 11}, :de_nw) - holiday_test("Fronleichnam", {2009, 6, 11}, :de_rp) - holiday_test("Fronleichnam", {2009, 6, 11}, :de_sl) - - holiday_test("Mariä Himmelfahrt", {2009, 8, 15}, :de_by) - holiday_test("Mariä Himmelfahrt", {2009, 8, 15}, :de_by_aux) - holiday_test("Mariä Himmelfahrt", {2009, 8, 15}, :de_sl) - - holiday_test("Reformationstag", {2009, 10, 31}, :de_bb) - holiday_test("Reformationstag", {2009, 10, 31}, :de_mv) - holiday_test("Reformationstag", {2009, 10, 31}, :de_sn) - holiday_test("Reformationstag", {2009, 10, 31}, :de_st) - holiday_test("Reformationstag", {2009, 10, 31}, :de_th) - - holiday_test("Allerheiligen", {2000, 11, 1}, :de_bw) - holiday_test("Allerheiligen", {2000, 11, 1}, :de_by) - holiday_test("Allerheiligen", {2000, 11, 1}, :de_by_aux) - holiday_test("Allerheiligen", {2000, 11, 1}, :de_nw) - holiday_test("Allerheiligen", {2000, 11, 1}, :de_rp) - holiday_test("Allerheiligen", {2000, 11, 1}, :de_sl) - holiday_test("Allerheiligen", {2000, 11, 1}, [:de_bw, :de_sn]) - - holiday_test("Friedensfest", {2015, 8, 8}, :de_by_aux) - holiday_test("Friedensfest", {2015, 8, 8}, [:de_by_aux, :de_bw]) - - holiday_test("Buß- und Bettag", {2004, 11, 17}, :de_sn) - holiday_test("Buß- und Bettag", {2005, 11, 16}, :de_sn) - holiday_test("Buß- und Bettag", {2006, 11, 22}, :de_sn) - holiday_test("Buß- und Bettag", {2009, 11, 18}, :de_sn) - holiday_test("Buß- und Bettag", {2017, 11, 22}, :de_sn) + holiday_test("Neujahrstag", ~D[2009-01-01], :de) + holiday_test("Karfreitag", ~D[2009-04-10], :de) + holiday_test("Ostermontag", ~D[2009-04-13], :de) + holiday_test("Tag der Arbeit", ~D[2009-05-01], :de) + holiday_test("Christi Himmelfahrt", ~D[2009-05-21], :de) + holiday_test("Pfingstmontag", ~D[2009-06-01], :de) + holiday_test("Tag der Deutschen Einheit", ~D[2009-10-03], :de) + holiday_test("1. Weihnachtstag", ~D[2009-12-25], :de) + holiday_test("1. Weihnachtstag", ~D[2009-12-25], :de_bw) + holiday_test("1. Weihnachtstag", ~D[2009-12-25], :de_by) + holiday_test("1. Weihnachtstag", ~D[2009-12-25], :de_by_aux) + holiday_test("2. Weihnachtstag", ~D[2009-12-26], :de) + holiday_test("1. Weihnachtstag", ~D[2009-12-25], [:de_bw, :de_by_aux]) + + holiday_test("Heilige Drei Könige", ~D[2009-01-06], :de_bw) + holiday_test("Heilige Drei Könige", ~D[2009-01-06], :de_by) + holiday_test("Heilige Drei Könige", ~D[2009-01-06], :de_st) + + holiday_test("Fronleichnam", ~D[2009-06-11], :de_bw) + holiday_test("Fronleichnam", ~D[2009-06-11], :de_by) + holiday_test("Fronleichnam", ~D[2009-06-11], :de_he) + holiday_test("Fronleichnam", ~D[2009-06-11], :de_nw) + holiday_test("Fronleichnam", ~D[2009-06-11], :de_rp) + holiday_test("Fronleichnam", ~D[2009-06-11], :de_sl) + + holiday_test("Mariä Himmelfahrt", ~D[2009-08-15], :de_by) + holiday_test("Mariä Himmelfahrt", ~D[2009-08-15], :de_by_aux) + holiday_test("Mariä Himmelfahrt", ~D[2009-08-15], :de_sl) + + holiday_test("Reformationstag", ~D[2009-10-31], :de_bb) + holiday_test("Reformationstag", ~D[2009-10-31], :de_mv) + holiday_test("Reformationstag", ~D[2009-10-31], :de_sn) + holiday_test("Reformationstag", ~D[2009-10-31], :de_st) + holiday_test("Reformationstag", ~D[2009-10-31], :de_th) + + holiday_test("Allerheiligen", ~D[2000-11-01], :de_bw) + holiday_test("Allerheiligen", ~D[2000-11-01], :de_by) + holiday_test("Allerheiligen", ~D[2000-11-01], :de_by_aux) + holiday_test("Allerheiligen", ~D[2000-11-01], :de_nw) + holiday_test("Allerheiligen", ~D[2000-11-01], :de_rp) + holiday_test("Allerheiligen", ~D[2000-11-01], :de_sl) + holiday_test("Allerheiligen", ~D[2000-11-01], [:de_bw, :de_sn]) + + holiday_test("Friedensfest", ~D[2015-08-08], :de_by_aux) + holiday_test("Friedensfest", ~D[2015-08-08], [:de_by_aux, :de_bw]) + + holiday_test("Buß- und Bettag", ~D[2004-11-17], :de_sn) + holiday_test("Buß- und Bettag", ~D[2005-11-16], :de_sn) + holiday_test("Buß- und Bettag", ~D[2006-11-22], :de_sn) + holiday_test("Buß- und Bettag", ~D[2009-11-18], :de_sn) + holiday_test("Buß- und Bettag", ~D[2017-11-22], :de_sn) end diff --git a/test/holidays/definitions/no_test.exs b/test/holidays/definitions/no_test.exs index bc00569..38775b0 100644 --- a/test/holidays/definitions/no_test.exs +++ b/test/holidays/definitions/no_test.exs @@ -9,20 +9,20 @@ defmodule Holidays.NoTest do # Test cases from yaml file: - holiday_test("Nyttårsdag", {2010, 1, 1}, :no) - holiday_test("1. mai", {2010, 5, 1}, :no) - holiday_test("17. mai", {2010, 5, 17}, :no) - holiday_test("Julaften", {2010, 12, 24}, :no) - holiday_test("1. juledag", {2010, 12, 25}, :no) - holiday_test("2. juledag", {2010, 12, 26}, :no) - holiday_test("Nyttårsaften", {2010, 12, 31}, :no) - holiday_test("Fastelavn", {2010, 2, 14}, :no) - holiday_test("Palmesøndag", {2010, 3, 28}, :no) - holiday_test("Skjærtorsdag", {2010, 4, 1}, :no) - holiday_test("Langfredag", {2010, 4, 2}, :no) - holiday_test("1. påskedag", {2010, 4, 4}, :no) - holiday_test("2. påskedag", {2010, 4, 5}, :no) - holiday_test("Kristi Himmelfartsdag", {2010, 5, 13}, :no) - holiday_test("1. pinsedag", {2010, 5, 23}, :no) - holiday_test("2. pinsedag", {2010, 5, 24}, :no) + holiday_test("Nyttårsdag", ~D[2010-01-01], :no) + holiday_test("1. mai", ~D[2010-05-01], :no) + holiday_test("17. mai", ~D[2010-05-17], :no) + holiday_test("Julaften", ~D[2010-12-24], :no) + holiday_test("1. juledag", ~D[2010-12-25], :no) + holiday_test("2. juledag", ~D[2010-12-26], :no) + holiday_test("Nyttårsaften", ~D[2010-12-31], :no) + holiday_test("Fastelavn", ~D[2010-02-14], :no) + holiday_test("Palmesøndag", ~D[2010-03-28], :no) + holiday_test("Skjærtorsdag", ~D[2010-04-01], :no) + holiday_test("Langfredag", ~D[2010-04-02], :no) + holiday_test("1. påskedag", ~D[2010-04-04], :no) + holiday_test("2. påskedag", ~D[2010-04-05], :no) + holiday_test("Kristi Himmelfartsdag", ~D[2010-05-13], :no) + holiday_test("1. pinsedag", ~D[2010-05-23], :no) + holiday_test("2. pinsedag", ~D[2010-05-24], :no) end diff --git a/test/holidays/definitions/north_america_test.exs b/test/holidays/definitions/north_america_test.exs index dc5221f..742982a 100644 --- a/test/holidays/definitions/north_america_test.exs +++ b/test/holidays/definitions/north_america_test.exs @@ -7,14 +7,14 @@ defmodule Holidays.Definitions.NorthAmericaTest do :ok end - holiday_test("Groundhog Day", {2016, 2, 2}, :us) - holiday_test("Groundhog Day", {2016, 2, 2}, :ca) - holiday_test("Valentine's Day", {2013, 2, 14}, :ca) - holiday_test("St. Patrick's Day", {2013, 3, 17}, :ca) - holiday_test("April Fool's Day", {2013, 4, 1}, :ca) - holiday_test("Earth Day", {2013, 4, 22}, :ca) - holiday_test("Mother's Day", {2013, 5, 12}, :ca) - holiday_test("Armed Forces Day", {2013, 5, 18}, :us) - holiday_test("Father's Day", {2013, 6, 16}, :ca) - holiday_test("Halloween", {2013, 10, 31}, :ca) + holiday_test("Groundhog Day", ~D[2016-02-02], :us) + holiday_test("Groundhog Day", ~D[2016-02-02], :ca) + holiday_test("Valentine's Day", ~D[2013-02-14], :ca) + holiday_test("St. Patrick's Day", ~D[2013-03-17], :ca) + holiday_test("April Fool's Day", ~D[2013-04-01], :ca) + holiday_test("Earth Day", ~D[2013-04-22], :ca) + holiday_test("Mother's Day", ~D[2013-05-12], :ca) + holiday_test("Armed Forces Day", ~D[2013-05-18], :us) + holiday_test("Father's Day", ~D[2013-06-16], :ca) + holiday_test("Halloween", ~D[2013-10-31], :ca) end diff --git a/test/holidays/definitions/nyse_test.exs b/test/holidays/definitions/nyse_test.exs index 57f0354..755b506 100644 --- a/test/holidays/definitions/nyse_test.exs +++ b/test/holidays/definitions/nyse_test.exs @@ -7,13 +7,13 @@ defmodule Holidays.NyseTest do :ok end - holiday_test("New Year's Day", {2008, 1, 1}, :nyse) - holiday_test("Martin Luther King, Jr. Day", {2008, 1, 21}, :nyse) - holiday_test("Presidents' Day", {2008, 2, 18}, :nyse) - holiday_test("Good Friday", {2008, 3, 21}, :nyse) - holiday_test("Memorial Day", {2008, 5, 26}, :nyse) - holiday_test("Independence Day", {2008, 7, 4}, :nyse) - holiday_test("Labor Day", {2008, 9, 1}, :nyse) - holiday_test("Thanksgiving", {2008, 11, 27}, :nyse) - holiday_test("Christmas Day", {2008, 12, 25}, :nyse) + holiday_test("New Year's Day", ~D[2008-01-01], :nyse) + holiday_test("Martin Luther King, Jr. Day", ~D[2008-01-21], :nyse) + holiday_test("Presidents' Day", ~D[2008-02-18], :nyse) + holiday_test("Good Friday", ~D[2008-03-21], :nyse) + holiday_test("Memorial Day", ~D[2008-05-26], :nyse) + holiday_test("Independence Day", ~D[2008-07-04], :nyse) + holiday_test("Labor Day", ~D[2008-09-01], :nyse) + holiday_test("Thanksgiving", ~D[2008-11-27], :nyse) + holiday_test("Christmas Day", ~D[2008-12-25], :nyse) end diff --git a/test/holidays/definitions/ups_test.exs b/test/holidays/definitions/ups_test.exs index 60133c4..3371240 100644 --- a/test/holidays/definitions/ups_test.exs +++ b/test/holidays/definitions/ups_test.exs @@ -7,14 +7,14 @@ defmodule Holidays.UpsTest do :ok end - holiday_test("New Year's Day", {2008, 1, 1}, :ups) - holiday_test("Memorial Day", {2008, 5, 26}, :ups) - holiday_test("Independence Day", {2008, 7, 4}, :ups) - holiday_test("Labor Day", {2008, 9, 1}, :ups) - holiday_test("Thanksgiving", {2008, 11, 27}, :ups) - holiday_test("Day after Thanksgiving", {2008, 11, 28}, :ups) - holiday_test("Thanksgiving", {2013, 11, 28}, :ups) - holiday_test("Day after Thanksgiving", {2013, 11, 29}, :ups) - holiday_test("Christmas Day", {2008, 12, 25}, :ups) - holiday_test("New Year's Eve", {2015, 12, 31}, :ups) + holiday_test("New Year's Day", ~D[2008-01-01], :ups) + holiday_test("Memorial Day", ~D[2008-05-26], :ups) + holiday_test("Independence Day", ~D[2008-07-04], :ups) + holiday_test("Labor Day", ~D[2008-09-01], :ups) + holiday_test("Thanksgiving", ~D[2008-11-27], :ups) + holiday_test("Day after Thanksgiving", ~D[2008-11-28], :ups) + holiday_test("Thanksgiving", ~D[2013-11-28], :ups) + holiday_test("Day after Thanksgiving", ~D[2013-11-29], :ups) + holiday_test("Christmas Day", ~D[2008-12-25], :ups) + holiday_test("New Year's Eve", ~D[2015-12-31], :ups) end diff --git a/test/holidays/definitions/us_test.exs b/test/holidays/definitions/us_test.exs index 8da9222..f31e63b 100644 --- a/test/holidays/definitions/us_test.exs +++ b/test/holidays/definitions/us_test.exs @@ -11,20 +11,20 @@ defmodule Holidays.UsTest do doctest Holidays.Definitions.Us - holiday_test("New Year's Day", {2008, 1, 1}, :us) - holiday_test("Martin Luther King, Jr. Day", {2008, 1, 21}, :us) - holiday_test("Presidents' Day", {2008, 2, 18}, :us) - holiday_test("Memorial Day", {2008, 5, 26}, :us) - holiday_test("Independence Day", {2008, 7, 4}, :us) - holiday_test("Labor Day", {2008, 9, 1}, :us) - holiday_test("Columbus Day", {2008, 10, 13}, :us) - holiday_test("Veterans Day", {2008, 11, 11}, :us) - holiday_test("Thanksgiving", {2008, 11, 27}, :us) - holiday_test("Day after Thanksgiving", {2008, 11, 28}, :us) - holiday_test("Thanksgiving", {2013, 11, 28}, :us) - holiday_test("Day after Thanksgiving", {2013, 11, 29}, :us) - holiday_test("Christmas Day", {2008, 12, 25}, :us) - holiday_test("Easter Sunday", {2016, 3, 27}, :us) - holiday_test("Good Friday", {2016, 3, 25}, :us) - holiday_test("Inauguration Day", {2025, 1, 20}, :us_dc) + holiday_test("New Year's Day", ~D[2008-01-01], :us) + holiday_test("Martin Luther King, Jr. Day", ~D[2008-01-21], :us) + holiday_test("Presidents' Day", ~D[2008-02-18], :us) + holiday_test("Memorial Day", ~D[2008-05-26], :us) + holiday_test("Independence Day", ~D[2008-07-04], :us) + holiday_test("Labor Day", ~D[2008-09-01], :us) + holiday_test("Columbus Day", ~D[2008-10-13], :us) + holiday_test("Veterans Day", ~D[2008-11-11], :us) + holiday_test("Thanksgiving", ~D[2008-11-27], :us) + holiday_test("Day after Thanksgiving", ~D[2008-11-28], :us) + holiday_test("Thanksgiving", ~D[2013-11-28], :us) + holiday_test("Day after Thanksgiving", ~D[2013-11-29], :us) + holiday_test("Christmas Day", ~D[2008-12-25], :us) + holiday_test("Easter Sunday", ~D[2016-03-27], :us) + holiday_test("Good Friday", ~D[2016-03-25], :us) + holiday_test("Inauguration Day", ~D[2025-01-20], :us_dc) end From 5c2eae0d1305526f45ca22325725f6388e197209 Mon Sep 17 00:00:00 2001 From: Dennis Palmer Date: Mon, 15 Sep 2025 21:38:21 +0200 Subject: [PATCH 2/2] updates version number --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 06a07cb..eb81038 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Holidays.MixProject do def project do [ app: :holidays, - version: "0.3.0", + version: "0.4.0", elixir: "~> 1.15", description: "Application for finding which holidays fall on given dates.", name: "Holidays",