holidays v0.1.1 Holidays
Provides the on
function that gives a list of holidays for a date within
specified regions.
Dates in Erlang (and therefore Elixir) are represented by the tuple
{year, month, day}
.
This module uses pattern matching as much as possible. So, when a holiday occurs on a fixed month and day every year, it will match on a clause that looks something like this:
defp do_on({_year, 1, 1}, :us), do: [%{name: "New Year's Day"}]
A holiday that occurs on a certain week and week day will match like this:
defp do_on(5, :last, :monday, :us), do: [%{name: "Memorial Day"}]
Regions are often country codes, like :us
or :ca
, but
may also be entities such as UPS (:ups
) or the New York Stock Exchange
(:nyse
).
They can sometimes also be states/provinces, like :us_ca
or :us_dc
.
Holidays are defined within modules in the lib/holidays/definitions
directory which use the holiday
macro from Holidays.Define
.
It’s fairly easy to take yaml files from the original Ruby implementation
and translate them into the Elixir definition modules. The yaml files are
included in the root definitions
folder. They just haven’t all been
translated yet.
Summary
Functions
Wrapper for Holidays.DateCalculator.Easter.gregorian_easter_for(year)
so Definition modules don’t all need their own copy
For debug purposes, returns contents of @holidays attribute
Returns a list of holidays on the given date
for the specified regions
Types
Functions
Wrapper for Holidays.DateCalculator.Easter.gregorian_easter_for(year)
so Definition modules don’t all need their own copy.
For eample, in Holidays.Definitions.Us
, Easter Sunday is defined like this:
holiday "Easter Sunday",
%{regions: [:us],
function: {:easter, [:year]},
type: :informal}
Specs
on(:calendar.date, [region]) :: list
Returns a list of holidays on the given date
for the specified regions
.
Examples
iex> Holidays.on({2016, 1, 1}, [:us])
[%{name: "New Year's Day"}]