@@ -19,6 +19,7 @@ Predicator allows you to safely evaluate user-defined expressions without the se
1919- 🔄 ** Reversible** : Convert AST back to string expressions with formatting options
2020- 🧮 ** Arithmetic** : Full arithmetic operations (` + ` , ` - ` , ` * ` , ` / ` , ` % ` ) with proper precedence
2121- 📅 ** Date Support** : Native date and datetime literals with ISO 8601 format
22+ - ⏳ ** Durations & Relative Dates** : Natural-language durations and relative time expressions with date arithmetic
2223- 📋 ** Lists** : List literals with membership operations (` in ` , ` contains ` )
2324- 🧠 ** Smart Logic** : Logical operators with proper precedence (` AND ` , ` OR ` , ` NOT ` )
2425- 🔧 ** Functions** : Built-in functions for string, numeric, and date operations
@@ -32,7 +33,7 @@ Add `predicator` to your list of dependencies in `mix.exs`:
3233``` elixir
3334def deps do
3435 [
35- {:predicator , " ~> 3.3 " }
36+ {:predicator , " ~> 3.4 " }
3637 ]
3738end
3839```
5859iex> Predicator .evaluate! (" created_at < #2024-01-15T10:30:00Z#" , %{" created_at" => ~U[ 2024-01-10 09:00:00Z] })
5960true
6061
62+ # Durations, relative dates, and date arithmetic
63+ iex> Predicator .evaluate! (" created_at > 3d ago" , %{" created_at" => ~U[ 2024-01-20 00:00:00Z] })
64+ true
65+
66+ iex> Predicator .evaluate! (" due_at < 2w from now" , %{" due_at" => Date .add (Date .utc_today (), 10 )})
67+ true
68+
69+ iex> Predicator .evaluate! (" #2024-01-10# + 5d = #2024-01-15#" , %{})
70+ true
71+
72+ iex> Predicator .evaluate! (" #2024-01-15T10:30:00Z# - 2h < #2024-01-15T10:30:00Z#" , %{})
73+ true
74+
6175# List literals and membership
6276iex> Predicator .evaluate! (" role in ['admin', 'manager']" , %{" role" => " admin" })
6377true
@@ -334,6 +348,9 @@ iex> Predicator.evaluate("'coding' in user.hobbies", list_context)
334348- ** Booleans** : ` true ` , ` false ` (or plain identifiers like ` active ` , ` expired ` )
335349- ** Dates** : ` #2024-01-15# ` (ISO 8601 date format)
336350- ** DateTimes** : ` #2024-01-15T10:30:00Z# ` (ISO 8601 datetime format with timezone)
351+ - ** Durations** : Natural units for time spans (e.g., ` 3d ` , ` 2h ` , ` 15m ` )
352+ - In relative expressions: ` 3d ago ` , ` 2w from now ` , ` next 1mo ` , ` last 1y `
353+ - In arithmetic: ` #2024-01-10# + 5d ` , ` #2024-01-15T10:30:00Z# - 2h `
337354- ** Lists** : ` [1, 2, 3] ` , ` ['admin', 'manager'] ` (homogeneous collections)
338355- ** Objects** : ` {} ` , ` {name: "John", age: 30} ` , ` {user: {role: "admin"}} ` (JavaScript-style object literals)
339356- ** Identifiers** : ` score ` , ` user_name ` , ` is_active ` , ` user.profile.name ` , ` user['key'] ` , ` items[0] ` (variable references with dot notation and bracket notation for nested data)
@@ -554,4 +571,3 @@ mix dialyzer # Type checking
554571## Documentation
555572
556573Full documentation is available at [ HexDocs] ( https://hexdocs.pm/predicator ) .
557-
0 commit comments