Our new Appfire Documentation Space is now live!
Take a look here! If you have any questions please email support@appfire.com
Working time calculations
The date filters in JMWE Nunjucks template allow you to perform working time calculations using various working time methods. You can run these date and time calculations based on working days and working times that are defined using the workingTime
and holidays
variables.
This document provides the usage details of these working time methods.
On this page
Before using any working time method, you must define the working times and holidays. If not, the following default values are used:
Working times - Monday to Friday, 9:00 am to 6:00 pm
No holiday
Working times settings
Consider an example work schedule:
Monday, 9:00 am to 1:00 pm and 2:00 pm to 6:00 pm
Tuesday to Thursday, 9:00 am to 6:00 pm
Friday, 9:00 am to 1:00 pm
Saturday and Sunday, non-working days
Use the following syntax to define it:
{%set workingTime = {
monday:['09:00:00','13:00:00','14:00:00','18:00:00'],
tuesday:['09:00:00','18:00:00'],
wednesday:['09:00:00','18:00:00'],
thursday:['09:00:00','18:00:00'],
friday:['09:00:00','13:00:00']
} %}
Holidays settings
Consider an example where every Jan 1st and Dec 25th are holidays including Feb 29th, 2024. Use the following syntax to define them:
{%set holidays = ['*-01-01','*-12-25','2024-02-29']%}
The date format used is yyyy-mm-dd (4 digits for the year, 2 digits for the month, from 1 to 12, 2 digits for the day of the month). You can use '*' instead of an actual year, month, or day to denote that the definition applies to every year, month or day, respectively.
Supported methods
This section lists all the supported working time methods in detail. Consider the following work times and holiday settings for the example syntax and output listed in the following table:
{%set workingTime = {
monday:['09:00:00', '13:00:00','13:30:00','17:30:00'],
tuesday:['09:00:00', '13:00:00','13:30:00','17:30:00'],
wednesday:['09:00:00', '13:00:00','13:30:00','17:30:00'],
thursday:['09:00:00', '13:00:00','13:30:00','17:30:00'],
friday:['09:00:00', '13:00:00','13:30:00','17:30:00']
} %}
{%set holidays = ["*-01-14","*-01-15","*-01-26","*-08-15"]%}
Method name | Description | Parameters | Example syntax | Output |
---|---|---|---|---|
| Determines if the day of the current instance is a working day. | N/A |
|
|
| Determines if the day and time fall inside working days and hours. | N/A |
|
|
| Returns a new moment representing the next day considered to be a working day. | N/A |
|
|
| Returns either the same moment if the day and time fall inside working days and hours, or a new moment representing the start of the next day considered to be a working day. | N/A |
|
|
| Adds an amount of working time to the input date and time. |
| Add 30 min to issue creation time, in the logged-in user’s current time zone:
|
|
| Subtracts an amount of working time from the input date and time. |
| Subtract 30 min from issue creation time, in the logged-in user’s current time zone:
|
|
| Calculates the difference between two moments, counting only working time. |
| Difference between now and Issue creation date (both in the logged-in user’s current time zone)
|
|
Ensure to use the current logged-in user’s timezone (date("tz")
while calling the working time methods, wherever applicable. If not, you might not see the results as expected.
Additional examples
Example | Syntax | Returns |
---|---|---|
Subtract 4 working hours from the specified time with the following definitions:
|
| |
Add 2 working days to now, in the logged-in user’s current time zone with the following definitions:
|
| |
Difference between the issue creation time and now with the following definitions:
| returns the number of working hours since the issue's creation, in the current user's time zone. |
|
Additional links