Using plusBusinessHours does not work as expecte
Asked by Brian Pelton:

Trying to add hours to a custom date/time field and it doesn't update as expected. I suspect it is some kind of timezone issue? I'm using Jira Cloud.

Example 1 - worked as expected

Formula: {{now.plusBusinessHours(1)}}

I triggered automation on Aug 4 at 8:16 am PDT and after the automation runs the custom date/time was set to "Aug 04, 2021, 9:16 AM"

Example 2 - not working

Formula: {{now.plusBusinessHours(4)}}

I triggered automation on Aug 4 at 8:18 am PDT and after the automation runs the custom date/time was set to "Aug 05, 2021, 3:18 AM"

I'm using info from this article: <https://community.atlassian.com/t5/Automation-articles/New-automation-smart-values-in-Jira-Cloud/ba-p/1402775>


Answers:
author: Bill Sheboy
body: Hi [@Brian Pelton](/t5/user/viewprofilepage/user-id/2116608)

That is curious, and I suspect you are correct about time zone and the **hours/day and days/week setting impacting this**. You could try to force to your time zone first and see what happens, such as this using the reporter as the "anchor" time zone. Perhaps log both with and without the increment to see what you get.

{{now.convertToTimeZone(issue.reporter.timeZone)...

Of note, I cannot tell if you are using Cloud or Server/Data Center, and when I checked the current documentation for both, neither one shows that plusBusinessHours() function. But they might be out of date.

* <https://confluence.atlassian.com/automation/date-and-time-functions-993924864.html>
* <https://support.atlassian.com/jira-software-cloud/docs/smart-values-date-and-time-functions/>

What problem are you trying to solve by doing this?

Best regards,  
Bill

comments: author: Brian Pelton
body: Thanks for the reply,

I'm on Jira Cloud.

I found the \`plusBusinessHours\` function mentioned on the blog post I linked to at the bottom of my question.

I experimented a little to force a timezone, but not the way you mention so I will try that approach to see if helps.

If I can't get it working, I suppose I will open a ticket with Atlassian Support.

----

My goal is to calculate a 'follow up' or reminder date time for the ticket. Something like 'add 4 hours' each time a ticket gets a new comment. It would be nice to advance the reminder to the next business day if say the last comment is at 4pm.


author: Bill Sheboy
body: After a re-read of that article (emphasis is mine below), please note this function targets Jira Service Desk:
> You can now play around with timestamp fields by adjusting fields at hour level. For that, you have two new functions in your pocket: plusBusinessHours and minusBusinessHours. We wanted to take business hours window dynamically from **Jira Service Desk** , but for now, we **assume business hours are 9 AM to 6 PM**, Monday to Friday.

And with some experimentation... try to log this smart value, from 0 to 10 hours of incrementing:

```
now+0 hours: {{now.plusBusinessHours(0).fullDateTime}} 
and diff of 0 business hour(s): {{now.diff(now.plusBusinessHours(0)).minutes}}
```

What I see in the log seems to indicate this starts at the next business day's start of hours (9 am) for a 0-hour increment, and continues, wrapping to the subsequent days.

![audit log.png](https://community.atlassian.com/t5/image/serverpage/image-id/154581i375BC1313902DAF8/image-size/large?v=v2&px=999 "audit log.png")

I am unclear of the purpose of this function as it is also not listed on the Jira Service Desk (Management) smart value help.

<https://support.atlassian.com/jira-service-management-cloud/docs/smart-values-date-and-time-functions/>

Definitely time for customer service to chime in on this one.


author: Brian Pelton
body: After working with support and a bit of trial and error, I ended up with:

```
{{now.convertToTimeZone(reporter.timeZone).plusBusinessHours(2)}}
```

Its too bad you can't pass variables as parameters, I wanted to store the number of business hours (2 in this case) as a variable and pass it to "plusBusinessHours" to simplify the automation.


author: Bill Sheboy
body: Thanks, and I agree. I submitted a defect for not being able to pass variables as function parameters last year. Here are the public backlog items if you want to watch them:

* <https://jira.atlassian.com/browse/JRACLOUD-75659>
* <https://codebarrel.atlassian.net/browse/AUT-2022>

Best regards,  
Bill