recurring_events v0.2.0 RecurringEvents.Date View Source

Helper module responsible for common date manipulations.

Link to this section Summary

Functions

Compares two dates, time if provided will be ignored

Returns year day of provided date

Returns last daty of the month for provided date

Returns next day of the week

Returns numbered week day of provided date

Returns previous day of the week

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

Shifts week days

Returns week day of provided date

Returns week number of provided date Minimum 4 days of week are required in the first week, :week_start can be provided

Link to this section Functions

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

Returns year day of provided date

Example

iex> RecurringEvents.Date.day_of_the_year(~D[2017-02-04]) 35

Link to this function last_day_of_the_month(arg1) View Source

Returns last daty of the month for provided date.

Example

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

Returns next day of the week

Example

iex> RecurringEvents.Date.next_week_day(:friday)
:saturday
Link to this function numbered_week_day(date, period \\ :month, order \\ :foreward) View Source

Returns numbered week day of provided date

Example

iex> RecurringEvents.Date.numbered_week_day(~D[2017-02-04], :month) {1, :saturday}

iex> RecurringEvents.Date.numbered_week_day(~D[2017-02-04], :year, :backward) {-48, :saturday}

Returns previous day of the week

Example

iex> RecurringEvents.Date.prev_week_day(:wednesday)
:tuesday
Link to this function shift_date(date, count, period) View Source

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]
Link to this function shift_week_day(day, shift) View Source

Shifts week days

Example

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

Returns week day of provided date

Example

iex> RecurringEvents.Date.week_day(~D[2017-02-04])
:saturday
Link to this function week_number(date, options \\ []) View Source

Returns week number of provided date Minimum 4 days of week are required in the first week, :week_start can be provided

Example

iex> RecurringEvents.Date.week_number(~D[2017-01-05]) 1 iex> RecurringEvents.Date.week_number(~D[2017-01-05], reversed: true) -52