Values and expressions
cardinal_format handles numbers, dates and zones. cardinal_expr runs depends_on, rules and conditions.
cardinal_format
Every value crosses the wire in one canonical form, and cardinal_format converts between that form and what a user sees.
| Handles | Details |
|---|---|
| Rounding | Exact decimals, never floats |
| Number formats | The 11 formats System Settings offers, such as #,###.## and #,##,###.## |
| Dates and times | 6 date formats and 2 time formats, with strict input parsing |
| Zones | UTC to a zone and back, on a tz database bundled into the crate |
| Durations | Duration fields |
| Wire forms | Decimals as strings ("1250.00"), dates as "2026-03-08", datetimes in UTC |
| Cron | The next run of a cron expression in a zone, for Scheduled Job Types |
The crate never reads the OS zoneinfo or TZDIR. The clock, zone and locale settings arrive as arguments. Elixir calls it through the NIF, the desk through WASM, and the template and sheet crates link it.
cardinal_expr
The expression language for depends_on, row rules, workflow and notification conditions, and automation inputs. Sources look like JavaScript and are type-checked against the Record's fields when the RecType compiles.
doc.status == "Open" && doc.qty > 0
["Draft", "Open"].includes(doc.status)
if doc.grand_total > 50000 then "High" else "Normal"
date_diff(doc.due_date, today()) < 7| Rule | Behaviour |
|---|---|
| Null | Equals only null. Arithmetic on null gives null. < and > with a null side are false |
is_set(x) | False for null, "" and an empty table. True for 0 and false |
| Lists | An array literal only appears as [...].includes(x) |
| Division by zero | An evaluation error, division_by_zero |
| Depth | 50 nesting levels at most. Test one field against many values with includes, not 50 || clauses |
| Steps | Evaluation stops at 100,000 steps |
round | Ties to even, 0 to 28 places |
if c then a else b | Evaluates only the branch it takes |
Functions include min, max, abs, round, floor, ceil, date_diff, add_days, add_months, month_start, month_end, today() and has_role. Each gives null when an argument is null.
| Compile mode | Reads | Used by |
|---|---|---|
compile | doc.<field> | RecType expressions, also in the browser |
compile_rule | Also <set>().includes(x), a principal's set | Row rules and role rules, server only |
compile_with_steps | Also steps.<node>.<output> | Automation inputs |
compile_scope | Bare names, such as gross_pay | Formulas over a caller's scope, such as salary components |
cardinal_meta compiles every expression in a RecType. cardinal_perm walks the expression tree to push row rules down into SQL.