A neat library to do business days intervals given a set of calendars.
Initalize the server with a map of holiday calendars:
BusinessDays.start_link(%{
"USD" => [{2018, 4, 7}, "2018-12-25", ~D[2018-01-01]],
"other" => ~W[2018-04-07 2018-10-01]
})
The dates in the calendars can be plain strings, Date objects or erlang date-like tuples. Any non-conformant element of a calendar will be logged and skipped.
Now you can calculate forwards and backwards intervals:
iex> BusinessDays.since(~D[2018-07-03], 1, ~W[USD])
~D[2018-07-03]
iex> BusinessDays.ago(~D[2018-07-05], 1, ~W[USD])
~D[2018-07-03]
Negative skips are supported, behaving as the "opposite" method was called:
iex> BusinessDays.ago(~D[2018-07-03], -1, ~W[USD])
~D[2018-07-03]
iex> BusinessDays.since(~D[2018-07-05], -1, ~W[USD])
~D[2018-07-03]
Week-ends are skipped too:
iex> BusinessDays.since(~D[2018-07-28], 0)
~D[2018-07-30]
iex> BusinessDays.ago(~D[2018-07-28], 0)
~D[2018-07-27]
If available in Hex, the package can be installed
by adding business_days
to your list of dependencies in mix.exs
:
def deps do
[
{:business_days, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/business_days.