Holidays v0.2.1 Holidays.DateCalculator.DateMath

Summary

Functions

Adds the given number of days to the given date

Returns a list of tuples with week and day atoms

Returns the date for the weekth weekday for the given year and month

Functions

add_days(date, days)

Specs

add_days(:calendar.date, integer) :: :calendar.date

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}
get_week_and_weekday(date)

Specs

get_week_and_weekday(:calendar.date) :: [{Holidays.week, Holidays.weekday}]

Returns a list of tuples with week and day atoms.

The list will contain a single item except when the day is both the :fourth and the :last week.

Examples

iex> Holidays.DateCalculator.DateMath.get_week_and_weekday({2016,1,29})
[{:last, :friday}]

iex> Holidays.DateCalculator.DateMath.get_week_and_weekday({2016,1,25})
[{:fourth, :monday}, {:last, :monday}]

iex> Holidays.DateCalculator.DateMath.get_week_and_weekday({2016,1,5})
[{:first, :tuesday}]
get_weekth_day(year, month, week, weekday)

Specs

get_weekth_day(pos_integer, pos_integer, Holidays.week, Holidays.weekday | pos_integer) :: :calendar.date

Returns the date for the weekth weekday for the given year and month.

week may be one of :first, :second, :third, :fourth, :last

weekday may be a number between 1 and 7, which is the way Erlang represents Monday through Sunday. Or use one the atoms :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday

Examples

# The second Tuesday of June, 2013
iex> Holidays.DateCalculator.DateMath.get_weekth_day(2013, 6, :second, :tuesday)
{2013, 6, 11}

# The third Friday of December, 2013
iex> Holidays.DateCalculator.DateMath.get_weekth_day(2013, 12, :third, :friday)
{2013, 12, 20}

# The last Saturday of January, 2013
iex> Holidays.DateCalculator.DateMath.get_weekth_day(2013, 1, :last, :saturday)
{2013, 1, 26}