Chapter III. - JEXL Functions Reference Guide
This document provides a detailed overview of all JEXL functions available in the tSM platform. Each function is categorized for better usability and includes descriptions, parameters, and examples.
1. Date & Time Utilities
addTime
Adds time to a given date in specified units.
- Parameters:
date
: The starting date (string or Date object).amount
: The amount of time to add (integer).unit
: The unit of time (e.g.,'days'
,'hours'
,'minutes'
).
- Example:
addTime('2023-01-01T00:00:00Z', 1, 'days');
// Output: '2023-01-02T00:00:00Z'
compareDates
Compares two dates using a specified operator and unit of time.
- Parameters:
date1
: First date (string or Date object).date2
: Second date (string or Date object).operator
: Comparison operator ('<'
,'>'
,'=='
, etc.).unit
: The unit of time to compare ('days'
,'hours'
, etc.).
- Example:
compareDates('2023-01-01', '2023-01-10', '<', 'days');
// Output: true
dateDiff
Calculates the difference between two dates in a specified unit.
- Parameters:
startDate
: The start date (string or Date object).endDate
: The end date (string or Date object).unit
: The unit of time ('days'
,'hours'
,'minutes'
, etc.).
- Example:
dateDiff('2023-01-01', '2023-01-10', 'days');
// Output: 9
dateFormat
Formats a date into a custom pattern.
- Parameters:
date
: The date (string or Date object).pattern
: The desired output format (e.g.,'YYYY-MM-DD'
).
- Example:
dateFormat(new Date(), 'YYYY-MM-DD');
// Output: '2023-01-01'
dateFormatFrom
Converts a date from one format to another.
- Parameters:
dateString
: The date as a string.fromPattern
: The current format of the dateString.toPattern
: The desired output format.
- Example:
dateFormatFrom('2023-01-01', 'YYYY-MM-DD', 'DD-MM-YYYY');
// Output: '01-01-2023'