Predicator.Functions.DateFunctions (predicator v6.0.0)

Copy Markdown View Source

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 datetime
  • month(date) - Extracts the month from a date or datetime
  • day(date) - Extracts the day from a date or datetime
  • now() - 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

function_result()

@type function_result() :: {:ok, Predicator.Types.value()} | {:error, binary()}

Functions

call_date_now(arg1, context)

Returns the current UTC datetime (alias for Date.now()).

call_day(arg1, context)

Extracts the day from a date or datetime.

call_month(arg1, context)

Extracts the month from a date or datetime.

call_year(arg1, context)

Extracts the year from a date or datetime.

functions()

@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