Date and time related functions for use in predicator expressions.
This module provides temporal functions for working with dates, times, durations, and relative date calculations.
Available Functions
Date/Time Functions
year(date)- Extracts the year from a date or datetimemonth(date)- Extracts the month from a date or datetimeday(date)- Extracts the day from a date or datetimenow()- Returns the current UTC datetime (alias for Date.now())
Examples
iex> Predicator.Functions.DateFunctions.call_year([~D[2023-05-15]], %{})
{:ok, 2023}
iex> Predicator.Functions.DateFunctions.call_date_now([], %{})
{:ok, %DateTime{}}
Summary
Functions
Returns the current UTC datetime (alias for Date.now()).
Extracts the day from a date or datetime.
Extracts the month from a date or datetime.
Extracts the year from a date or datetime.
Returns all date functions as a Predicator.FunctionProvider map.
Types
@type function_result() :: {:ok, Predicator.Types.value()} | {:error, binary()}
Functions
@spec call_date_now([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Returns the current UTC datetime (alias for Date.now()).
@spec call_day([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Extracts the day from a date or datetime.
@spec call_month([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Extracts the month from a date or datetime.
@spec call_year([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Extracts the year from a date or datetime.
@spec functions() :: %{ required(Predicator.FunctionProvider.name()) => Predicator.FunctionProvider.entry() }
Returns all date functions as a Predicator.FunctionProvider map.
Returns
A map where keys are function names and values are {arity, atom} pairs -
atom naming a public call_*/2 function on this module.
Examples
iex> functions = Predicator.Functions.DateFunctions.functions()
iex> Map.has_key?(functions, "Date.year")
true
iex> {arity, _atom} = functions["Date.year"]
iex> arity
1