Handlebars Helpers
Sugartime
Save a date using sugartime syntax
Overview
This helper outputs a date in a specified format according to the human time explanation.
It uses the Sugar.js Date library to parse the human date text.
You can use the interactive tool the this page to test the human date text.
The format uses the moment.js format.
When concatenating more than one human time phrase, ensure each phrase is separated by a coma.
Concatenating
Concatenating, stringing more that one phrase together, allows you to do quite complex sugartime calculations.
It calculates working from left to right, starting with the left most phrase. The result of the first phrase calculation is used as the starting point for the 2 second phrase calculation. It will continue until there is nothing left to calculate.
Sugartime human syntax is not an LLM, you cannot ask it to do complex calculations like "the first Monday of next month", it will not understand that. You can however use the concatenation to build up a date from smaller parts, like "next month, the first Monday".
You should split up complex calculations into smaller parts and concatenate them together.
Timezones
It is possible to set the timezone of a sugartime to use relative date and times in the specified timezone. For example, using in 5 minutes with a specified timezone will return the time in 5 minutes in the specified timezone. Absolute dates such as today at 17:00 will return with today's date at 17:00. Timezones are specified in the IANA timezone format
If no timezone is set for the sugartime helper, it will default to the timezone set in _org_settings.locale.timezone.name in the template's data. If there is no timezone specified in either the sugartime helper or at _org_settings.locale.timezone.name, then the sugartime helper will use UTC time.
Syntax
Examples
Basic Example
Basic example will output the date in default format "YYYY-MM-DD HH:mm:SS" according to the human time explanation.
Usage
Substitution
Concat Example
Concat example will output the date in default format "YYYY-MM-DD HH:mm:SS" according to the human time explanation that is given in parts
Usage
Substitution
Format Example
Format example will output the date in a specified format "YYYY-MM-DD".
Usage
Substitution
Concat nudging example
Concat example will output the date in default format by nudging in parts
Usage
Substitution
Timezone Example
Timezone example will output the date in the specified timezone
Usage
Substitution