Holidays.DateCalculator.DateMath (Holidays v0.4.0)

View Source

Summary

Functions

Returns a list of tuples with week and day atoms.

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

Functions

get_week_and_weekday(date)

@spec get_week_and_weekday(Date.t()) :: [{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(~D[2016-01-29])
[{:last, :friday}]

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

iex> Holidays.DateCalculator.DateMath.get_week_and_weekday(~D[2016-01-05])
[{:first, :tuesday}]

get_weekth_day(year, month, week, weekday)

@spec get_weekth_day(
  pos_integer(),
  pos_integer(),
  Holidays.week(),
  Holidays.weekday() | pos_integer()
) :: Date.t()

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 Elixir 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)
~D[2013-06-11]

# The third Friday of December, 2013
iex> Holidays.DateCalculator.DateMath.get_weekth_day(2013, 12, :third, :friday)
~D[2013-12-20]

# The last Saturday of January, 2013
iex> Holidays.DateCalculator.DateMath.get_weekth_day(2013, 1, :last, :saturday)
~D[2013-01-26]