I have a requirement to calculate business hours between two date/time stamps in custom jira fields or a custom field and 'now' which considers normal business hours and holiday calendar. Has anyone found and implemented a good solution ? For one of serveral examples, I want to know the exact business hours between issue creation and the current date/time.
Hello @Mark W_ McColgan
Take a look at this answer provided by the inimitable @Bill Sheboy , one of the community's well-recognized SMEs when it comes to Automation Rules.
Hi @Mark W_ McColgan and @Trudy Claspill
Mark, as you want the business hours diff with holiday handling, I recommend looking for an external REST API endpoint which could be called from an automation rule with the Send Web Request action. Or, if you need this for display-only purposes, check if you have (or could acquire) marketplace dashboard gadgets / reports to help.
Trudy, thanks for finding that old post of mine as it includes many of the relevant assumptions and steps for this scenario!
After you recently answered a similar question, I did a bit of experimentation and created a generic, automation expression to calculate business hours diff between two date / time values. I am still pondering if it would be worth posting as an article; it is a bit tricky / complicated, although it has some helpful dependent features for other rule scenarios...but, it cannot easily handle embedded holidays. (That was another article, I recall :^)
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy
If you're willing to do the work it might be worth it to write that article, even if the solution is complicated. I'd give it a Like!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark W_ McColgan, @Trudy Claspill already pointed you to @Bill Sheboy's classic answer, which is the right reference for an Automation only solution. Let me add the trade offs by approach so you can pick the one that matches your use case.
1. Native Automation, rough estimate. The closest built in primitive is {{issue.created.diff(now).businessDays}}, which counts Monday to Friday and treats 9am to 6pm as the working window (9 hours). For a "good enough" hours figure you can do:
{{#=}}{{issue.created.diff(now).businessDays.abs}} * 9{{/}}
This does not respect holidays and does not handle partial days on the boundaries (so an issue created at 5:30pm is counted as a full business day). It is fine for SLA dashboards where directional accuracy is enough, not for billing.
2. Native Automation, accurate. Bill's approach (calculate the partial hours on the start day, the partial hours on the end day, and the full business days in between) gives you correct business hours but you have to model holidays yourself, typically as a JSON list of dates that you check with a condition. It scales poorly past one rule.
3. JSM SLA, the cleanest native option for holidays. If the work item lives in a Jira Service Management project, SLA Goals natively support a Calendar with working hours and a holiday set defined in Project settings > Calendars. You then expose Time to resolution or a custom SLA, and read the elapsed business time directly. This is the only fully native path I know of that handles holidays properly. If your issues are in Jira Software only, this is not available.
4. Marketplace apps. For Jira Software, several apps compute time in status / lead time against a configurable working calendar with holidays (Time in Status, Timepiece, Status Time Reports, among others). I would not lead with this unless you have already tried 1 to 3 and the constraints do not fit.
References:
Quick sanity check before you build any of this: are the two timestamps you are comparing both in JSM, both in Jira Software, or mixed? That determines whether option 3 is on the table at all.
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.