-
Notifications
You must be signed in to change notification settings - Fork 6
/
holidays.ex
53 lines (37 loc) · 1.25 KB
/
holidays.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
defmodule Holidays do
use Application
@moduledoc """
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}`.
"""
@type weekday :: :monday | :tuesday | :wednesday | :thursday | :friday | :saturday | :sunday
@type week :: :first | :second | :third | :fourth | :last
@type region :: atom
def start(_type, _args) do
Holidays.Supervisor.start_link
end
@doc """
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"}]
"""
@spec on(:calendar.date, [region]) :: list
def on(date, regions) do
Holidays.Define.on(date, regions)
end
@doc """
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: {Holidays, :easter, [:year]},
type: :informal}
"""
def easter(year) do
Holidays.DateCalculator.Easter.gregorian_easter_for(year)
end
end