◷ Reading Time: 3 minutes
This article has some examples of how to use FEEL Functions and Types.
The list of DMN functions with examples is on the DMN Function page..
Date and Time Usage
Defining date and time
Different ways exist to define a new Time, Date, and Duration using the Feel function and Type.
date("2024-03-22")
time ("4:30:00")
time("4:30:00+02:00")
date and time("2022-10-11T23:59:00")
date and time("2022-10-11T08:00:00+02:00")
date and time("2022-10-11T08:00:00@Europe/Madrid")
duration ("PT6H2M10S")
duration("P5D")Time and Date properties
After a date or time expression, the user can extract the properties by writing a specific property after the expression.
date("2024-03-22").month
Result: 3
-------------------------------------------------------------------------
date("2024-03-22").weekday
Result: Friday
-------------------------------------------------------------------------
date and time("2022-10-11T08:00:00@Europe/Madrid").timezone
Result: Europe/Madrid
-------------------------------------------------------------------------
time ("4:30:00").hour
Result: 4
-------------------------------------------------------------------------
duration ("PT6H2M10S").minute
Result: 2
-------------------------------------------------------------------------
duration("P5D").day
Result: 5
-------------------------------------------------------------------------Time and Date Adding and subtracting
Adding and subtracting value to the date and time is another feature of FEEL. The type must be the same, and if the types are different, the result is null.
date("2024-03-22") + duration ("P5D")
Result: 2024-03-27
-------------------------------------------------------------------------
time ("4:30:00") + duration ("PT2H5M30S")
Result: 06:35:30
-------------------------------------------------------------------------
date and time("2022-10-11T08:00:00") - duration ("P5D")
Result: 2022-10-06T08:00:00
-------------------------------------------------------------------------
duration("P5D") - duration("P2D")
Result: PT72H
-------------------------------------------------------------------------Using Lists with FEEL
flatten([[1 ,2],[[3],[["Cat", "Dog"],[1]]], 4])
Result: [1,2,3,4]
-------------------------------------------------------------------------
sublist([1,"Car","Jeep","Boat","Ship"], 2, 3)
Result: ["Car","Jeep","Boat"]
-------------------------------------------------------------------------
claims := [
{id: "A", amount: 900},
{id: "B", amount: 1200},
{id: "C", amount: 1500}
]
highClaims := claims[amount > 1000]
Result: [ {id: "B", amount: 1200},
{id: "C", amount: 1500}]
Using Numeric Functions with FEEL
Here are some examples using DMN numeric built-in functions, each paired with a business scenario and the corresponding FEEL expression:
Scenario: A penalty is calculated based on the logarithm of days overdue, but always as a positive value.
daysLate = 10, penaltyRate = 5
penalty := abs(log(daysLate) * penaltyRate)
Result: 11.513
-------------------------------------------------------------------------
Scenario: Assign applications to batches using modulo.
applicationId = 17
batchNumber = modulo(applicationId, 5)
Result: 2
The User can test all the Feel Functions on the Shell window in the FlexRule authoring platform.
