# Table of Contents * [`Introduction`](#introduction) * [`Filters`](#filters) * [`ifEmpty`](#ifempty) * [`length`](#length) * [`T`](#t) * [`toDate`](#todate) * [`toDateTime`](#todatetime) * [`toTime`](#totime) * [`addMin`](#addmin) * [`addHour`](#addhour) * [`addDay`](#addday) * [`addMonth`](#addmonth) * [`addYear`](#addyear) * [`subMin`](#submin) * [`subHour`](#subhour) * [`subDay`](#subday) * [`subMonth`](#submonth) * [`subYear`](#subyear) * [`setMin`](#setmin) * [`setHour`](#sethour) * [`setDay`](#setday) * [`setMonth`](#setmonth) * [`setYear`](#setyear) * [`setMonth`](#setmonth) * [`setYear`](#setyear) * [`toMinuteInMs`](#tominuteinms) * [`toHourInMs`](#tohourinms) * [`toDayInMs`](#todayinms) * [`toWeekInMs`](#toweekinms) * [`toMonthInMs`](#tomonthinms) * [`toYearInMs`](#toyearinms) # Introduction The filters listed below work on one main principle: take a value from a macro -> return the changed value.\ Some filters may support an argument, such as `ifEmpty`, and some may not, such as `length`. Here are some examples of their application: * `%login|length%` - Getting the length of a value from the `login` field; * `%login|ifEmpty(empty)%` - Getting the value from the login field. If it is empty, then we get the value "empty"; * `%date_field|addDay(5)|addHour(3)|toDate%` - Getting the value from the date field -> adding 5 days -> adding 3 hours -> formatting the timestamp to the value for the Date Field; # Filters ## ifEmpty If the macro returns an empty value, the filter will return the value passed in the argument ### Arguments Any argument, except for the parentheses `(` and `)` ### Example Macro string: ``` Value from field is: %field_name|isEmpty(empty)% ``` Result if `field_name` is empty: ``` Value from field is: empty ``` Result if `field_name` is filled with value "123" ``` Value from field is: 123 ``` ## length Returns the length of the string or array ### Example Macro string: ``` Number of charatcers from field is: %field_name|length% ``` Result if `field_name` is filled with value "123" ``` Number of charatcers from field is: 3 ``` ## T Returns the time stamp. Usually used in conjunction with Date & Datetime and Time Field. ### Example For Date Field ``` %date_field|T% ``` Result if `date_field` is filled with value "2022-10-22" ``` 1666386000000 ``` For Datetime Field ``` %datetime_field|T% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666450140000 ``` For Time Field ``` %time_field|T% ``` Result if `time_field` is filled with value "17:49" and today is 2022-10-22. (Today's date is taken as a basis.) ``` 1666018173371 ``` ## toDate Formats the timestamp according to the Date Field format. ### Arguments Optionally accepts `false` to use the user's local timezone instead of UTC (default: `true`). Using default UTC timezone: ``` %datetime_field|toDate% ``` Using local timezone: ``` %datetime_field|toDate(false)% ``` ### Example https://github.com/Crocoblock/jetformbuilder/wiki/Frontend-Macros---External-Macros#ctcurrentdate ## toDateTime Formats the timestamp according to the Datetime Field format. ### Arguments Optionally accepts `true` to use UTC timezone instead of the user's local timezone (default: `false` - local timezone). Using default local timezone: ``` %timestamp_field|toDateTime% ``` Using UTC timezone: ``` %timestamp_field|toDateTime(true)% ``` ### Example https://github.com/Crocoblock/jetformbuilder/wiki/Frontend-Macros---External-Macros#ctcurrentdate ## toTime Formats the timestamp according to the Time Field format. ### Arguments Optionally accepts `false` to use the user's local timezone instead of UTC (default: `true`). Using default UTC timezone: ``` %timestamp_field|toTime% ``` Using local timezone: ``` %timestamp_field|toTime(false)% ``` ### Example https://github.com/Crocoblock/jetformbuilder/wiki/Frontend-Macros---External-Macros#ctcurrentdate ## addMin Adds minutes via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will add **1 minute** ### Example Macro string: ``` %datetime_field|addMin(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666450440000 ``` ## addHour Adds hours via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will add **1 hour** ### Example Macro string: ``` %datetime_field|addHour(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666468140000 ``` ## addDay Adds days via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will add 1 day ### Example Macro string: ``` %datetime_field|addDay(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666882140000 ``` ## addMonth Adds months via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will add **1 month** ### Example Macro string: ``` %datetime_field|addMonth(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1647964140000 ``` ## addYear Adds years via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will add **1 year** ### Example Macro string: ``` %datetime_field|addYear(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1824216540000 ``` ## subMin Subtracts minutes via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will subtract **1 minute** ### Example Macro string: ``` %datetime_field|subMin(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666449840000 ``` ## subHour Subtracts hours via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will subtract **1 hour** ### Example Macro string: ``` %datetime_field|subHour(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666432140000 ``` ## subDay Subtracts days via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will subtract **1 day** ### Example Macro string: ``` %datetime_field|subDay(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666018140000 ``` ## subMonth Subtracts montha via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will subtract **1 month** ### Example Macro string: ``` %datetime_field|subMonth(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1653230940000 ``` ## subYear Subtracts years via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will subtract **1 year** ### Example Macro string: ``` %datetime_field|subYear(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1508683740000 ``` ## setMin Sets a minute via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will set 0 minute ### Example Macro string: ``` %datetime_field|setMin(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666447500000 ``` ## setHour Sets a hour via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will set 0 hour ### Example Macro string: ``` %datetime_field|setHour(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1666406940000 ``` ## setDay Sets a day via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will set 1 day ### Example Macro string: ``` %datetime_field|setDay(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1664981340000 ``` ## setMonth Sets a month via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will set 1 month ### Example Macro string: ``` %datetime_field|setMonth(5)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1664981340000 ``` ## setYear Sets a year via an argument to a macro that returns a date or timestamp ### Arguments Integer only. If no argument is passed, the filter will return the value without changes ### Example Macro string: ``` %datetime_field|setYear(2017)% ``` Result if `datetime_field` is filled with value "2022-10-22T17:49" ``` 1508683740000 ``` ## toMinuteInMs Converts a number of minutes into milliseconds. ### Example Macro string: ``` %minutes|toMinuteInMs% ``` ## toHourInMs Converts a number of hours into milliseconds. ### Example Macro string: ``` %hours|toHourInMs% ``` ## toDayInMs Converts a number of days into milliseconds. ### Example Macro string: ``` %days|toDayInMs% ``` ## toWeekInMs Converts a number of weeks into milliseconds. ### Example Macro string: ``` %weeks|toWeekInMs% ``` ## toMonthInMs Converts a number of months into milliseconds. ### Example Macro string: ``` %months|toMonthInMs% ``` ## toYearInMs Converts a number of years into milliseconds. ### Example Macro string: ``` %years|toYearInMs% ``` # Useful links [:small_orange_diamond: View source of current page](https://raw.githubusercontent.com/wiki/Crocoblock/jetformbuilder/Frontend-Macros---Filters.md)