recurring_events v0.1.0 RecurringEvents.Date

Helper module responsible for common date manipulations.

Summary

Functions

Compares two dates, time if provided will be ignored

Returns last daty of the month for provided date

Returns next day of the week

Returns previous day of the week

Shifts date by :days, :weeks, :months and :years

Shifts week days

Returns week day of provided date

Functions

compare(arg1, arg2)

Compares two dates, time if provided will be ignored.

Example

iex> RecurringEvents.Date.compare(~D[2017-02-05], ~D[2017-02-01])
:gt

iex> RecurringEvents.Date.compare(~D[2017-02-01], ~D[2017-02-05])
:lt

iex> RecurringEvents.Date.compare(~N[2017-02-05 12:00:00],
...>                              ~N[2017-02-05 18:21:11])
:eq
last_day_of_the_month(arg1)

Returns last daty of the month for provided date.

Example

iex> RecurringEvents.Date.last_day_of_the_month(~D[2017-02-04])
28
next_week_day(day)

Returns next day of the week

Example

iex> RecurringEvents.Date.next_week_day(:friday)
:saturday
prev_week_day(day)

Returns previous day of the week

Example

iex> RecurringEvents.Date.prev_week_day(:wednesday)
:tuesday
shift_date(date, count, period)

Shifts date by :days, :weeks, :months and :years

Example

iex> RecurringEvents.Date.shift_date(~D[2011-02-04], 4, :days)
~D[2011-02-08]

iex> RecurringEvents.Date.shift_date(~D[2011-02-04], 2, :years)
~D[2013-02-04]
shift_week_day(day, shift)

Shifts week days

Example

iex> RecurringEvents.Date.shift_week_day(:monday, -3)
:friday
week_day(date)

Returns week day of provided date

Example

iex> RecurringEvents.Date.week_day(~D[2017-02-04])
:saturday