Resuelve AuthPlug v1.4.3 ResuelveAuth.Utils.Calendar View Source
Encapsulates the functions related to the date.
If using a time library is required,
it should be added here the desired functionality.
In the project you should only find calls to
the Calendar
module to facilitate code maintenance.
Link to this section Summary
Functions
Returns the difference between two dates in unix format.
Converts the given Unix time to DateTime.
Identifies if the date sent as Unix time is passed.
In case of sending a value that is not an integer, it returns true
by default.
Returns the current date in unix time
.
Link to this section Functions
Specs
Returns the difference between two dates in unix format.
Example
iex> {ayer, ahora} = {1577646287000, 1577733231563}
iex> {:ok, first} = DateTime.from_unix(ayer, :millisecond)
iex> {:ok, second} = DateTime.from_unix(ahora, :millisecond)
iex> ResuelveAuth.Utils.Calendar.diff(first, second)
-24
iex> {ayer, ahora} = {1577646287000, 1577733231563}
iex> {:ok, first} = DateTime.from_unix(ayer, :millisecond)
iex> {:ok, second} = DateTime.from_unix(ahora, :millisecond)
iex> ResuelveAuth.Utils.Calendar.diff(second, first)
24
Specs
from_unix(integer()) :: {:ok, %DateTime{ calendar: term(), day: term(), hour: term(), microsecond: term(), minute: term(), month: term(), second: term(), std_offset: term(), time_zone: term(), utc_offset: term(), year: term(), zone_abbr: term() }} | {:error, any()}
Converts the given Unix time to DateTime.
iex> alias ResuelveAuth.Utils.Calendar
iex> {:ok, %DateTime{} = date} = Calendar.from_unix(1572617244)
iex> DateTime.to_unix(date)
1572617
iex> alias ResuelveAuth.Utils.Calendar
iex> Calendar.from_unix(1724.0)
{:error, :invalid_unix_time}
iex> alias ResuelveAuth.Utils.Calendar
iex> Calendar.from_unix("algo")
{:error, :invalid_unix_time}
Specs
Identifies if the date sent as Unix time is passed.
In case of sending a value that is not an integer, it returns true
by default.
Examples
iex> alias ResuelveAuth.Utils.Calendar
iex> unix_time = 1572617244
iex> Calendar.is_past?(unix_time)
true
iex> alias ResuelveAuth.Utils.Calendar
iex> unix_time = 4128685709000
iex> Calendar.is_past?(unix_time)
false
iex> alias ResuelveAuth.Utils.Calendar
iex> Calendar.is_past?("2100-02-29T12:30:30+00:00")
true
Specs
unix_now() :: integer()
Returns the current date in unix time
.
Example
> ResuelveAuth.Utils.Calendar.unix_now()
1577733231563