View Source Tempus.Sigils (Tempus v0.16.0)
Handy sigils to instantiate Tempus.Slot and Tempus.Slots
Summary
Functions
Parses the sigil-like binary representation of a Tempus.Slot.
Handles the sigil ~I for Tempus.Slot.
It returns a slot without interpolations and without escape
characters, except for the escaping of the closing sigil character
itself.
Functions
@spec parse(input :: binary()) :: {:ok, Tempus.Slot.t()} | {:error, any()}
Parses the sigil-like binary representation of a Tempus.Slot.
Examples
iex> Tempus.Sigils.parse("2021-03-30T06:35:40Z|2021-03-30T06:36:00Z")
{:ok, %Tempus.Slot{from: ~U[2021-03-30 06:35:40Z], to: ~U[2021-03-30 06:36:00Z]}}
iex> Tempus.Sigils.parse("foo|bar")
{:error, :invalid_format}
Handles the sigil ~I for Tempus.Slot.
It returns a slot without interpolations and without escape
characters, except for the escaping of the closing sigil character
itself.
Allowed separators: |, →, ->, .. (might be surrounded by spaces)
Allowed modifiers:
- none — expects two instances of
DateTime - single letter, one of
d,t,u— both values are expected to be of that type - any combination of two letters
d,t,u— the values are treated respectively g— the value types are to be guessed
Examples
iex> import Tempus.Sigils
iex> ~I(2021-03-30T06:35:40Z|2021-03-30T06:36:00Z)
%Tempus.Slot{from: ~U[2021-03-30 06:35:40Z], to: ~U[2021-03-30 06:36:00Z]}
iex> ~I(2021-03-30 → 2021-03-31)d
%Tempus.Slot{from: ~U[2021-03-30 00:00:00.000000Z], to: ~U[2021-03-31 23:59:59.999999Z]}
iex> ~I(2021-03-30)d
%Tempus.Slot{from: ~U[2021-03-30 00:00:00.000000Z], to: ~U[2021-03-30 23:59:59.999999Z]}
iex> ~I(2021-03-30 06:35:40Z .. 2021-03-30 06:36:00Z)g
%Tempus.Slot{from: ~U[2021-03-30 06:35:40Z], to: ~U[2021-03-30 06:36:00Z]}
iex> ~I(|2021-03-30 06:36:00Z)g
%Tempus.Slot{from: ~U[2021-03-30 06:36:00Z], to: ~U[2021-03-30 06:36:00Z]}
iex> ~I(2021-03-30 06:36:00Z|)g
%Tempus.Slot{from: ~U[2021-03-30 06:36:00Z], to: ~U[2021-03-30 06:36:00Z]}
iex> Code.compile_quoted(quote do: ~I(foo|bar)g)
** (CompileError) nofile: `~I` sigil input is malformed, error: :invalid_format