View Source Tarearbol.Calendar (tarearbol v1.11.2)

Handy functions to work with dates.

Summary

Functions

Returns a DateTime instance of the beginning of the period given as third parameters, related to the DateTime instance given as the first parameter (defaulted to DateTime.utc_now/0).

Functions

Link to this function

beginning_of(dt \\ nil, count \\ 0, what)

View Source
@spec beginning_of(dt :: DateTime.t() | nil, count :: integer(), atom()) ::
  DateTime.t()

Returns a DateTime instance of the beginning of the period given as third parameters, related to the DateTime instance given as the first parameter (defaulted to DateTime.utc_now/0).

The number of periods to shift might be given as the second parameter (defaults to 0.)

Examples:

iex> dt = DateTime.from_unix!(1567091960)
~U[2019-08-29 15:19:20Z]
iex> Tarearbol.Calendar.beginning_of(dt, :year)
~U[2019-01-01 00:00:00Z]
iex> Tarearbol.Calendar.beginning_of(dt, -2, :year)
~U[2017-01-01 00:00:00Z]
iex> Tarearbol.Calendar.beginning_of(dt, :month)
~U[2019-08-01 00:00:00Z]
iex> Tarearbol.Calendar.beginning_of(dt, 6, :month)
~U[2020-02-01 00:00:00Z]
iex> Tarearbol.Calendar.beginning_of(dt, 4, :day)
~U[2019-09-02 00:00:00Z]
iex> Tarearbol.Calendar.beginning_of(dt, :week)
~U[2019-08-26 00:00:00Z]
iex> Tarearbol.Calendar.beginning_of(dt, -34, :week)
~U[2018-12-31 00:00:00Z]
iex> Tarearbol.Calendar.beginning_of(dt, :hour)
~U[2019-08-29 15:00:00Z]
iex> Tarearbol.Calendar.beginning_of(dt, -28*24-16, :hour)
~U[2019-07-31 23:00:00Z]
iex> Tarearbol.Calendar.end_of(dt, :hour)
~U[2019-08-29 15:59:59Z]
iex> Tarearbol.Calendar.end_of(dt, 5, :month)
~U[2020-01-31 23:59:59Z]
iex> Tarearbol.Calendar.end_of(dt, -1, :year)
~U[2018-12-31 23:59:59Z]
Link to this function

end_of(dt \\ nil, n \\ 0, period)

View Source
@spec end_of(dt :: DateTime.t() | nil, count :: integer(), atom()) :: DateTime.t()