BitcrowdEcto.DateTime (bitcrowd_ecto v0.10.0) View Source
Functions to work with date and time values.
Link to this section Summary
Functions
Works similar to Timex.beginning_of_day/3
, but way more simple.
Converts a {<value>, <unit>}
tuple into seconds.
Works similar to Timex.shift/3
, but way more simple.
Link to this section Types
Specs
Specs
unit() :: :second | :minute | :hour | :day | :week
Link to this section Functions
Specs
beginning_of_day(DateTime.t()) :: DateTime.t()
Works similar to Timex.beginning_of_day/3
, but way more simple.
Behaviour
Nulls the time-field of the DateTime
and keeps the rest.
Examples
iex> beginning_of_day(~U[2022-04-07 07:21:22.036Z])
~U[2022-04-07 00:00:00.000000Z]
Specs
Converts a {<value>, <unit>}
tuple into seconds.
#Examples
iex> in_seconds({99, :second})
99
iex> in_seconds({1, :minute})
60
iex> in_seconds({1, :hour})
3600
iex> in_seconds({1, :day})
86400
iex> in_seconds({1, :week})
604800
Specs
shift(DateTime.t(), integer() | period()) :: DateTime.t()
Works similar to Timex.shift/3
, but way more simple.
Behaviour
Semantics are like DateTime.add/3
. TimeZone-awareness when using tzdata.
DateTime, e.g. "2020-03-29 14:00 Europe/Berlin" - 1 day = "2020-03-28 13:00" as March 29th
only had 23 hours due to DST.
Examples
iex> shift(~U[2022-04-07 07:21:22.036Z], 15)
~U[2022-04-07 07:21:37.036Z]
iex> shift(~U[2022-04-07 07:21:22.036Z], -3600)
~U[2022-04-07 06:21:22.036Z]
iex> shift(~U[2022-04-07 07:21:22.036Z], {1, :day})
~U[2022-04-08 07:21:22.036Z]
iex> ~U[2020-03-29 12:00:00.000Z]
...> |> DateTime.shift_zone!("Europe/Berlin")
...> |> shift({-1, :day})
...> |> DateTime.to_iso8601()
"2020-03-28T13:00:00.000+01:00"