Get business days in calculation

Jesper Mandrup Keld October 29, 2019

Hey Guys

I'm trying to do a calculation in jira that only includes business hours, but I can't seem to crack the nut. I'm right now using the "JMCF time in status" functionality with a field that just states the raw time. Then i have another field where i'm trying to use a groovy script to show <one thing> if time is <= 8 working hours else <another thing> is that at all possible or should I take another approach? 

The script that i'm currently using is below - it works fine except that it takes raw hours and not working hours.  

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def field = customFieldManager.getCustomFieldObject(00001);

def value = issue.getCustomFieldValue(field);

if (value < 28800) return "one thing";
else return "another thing";

 Hope you can help me crack the nut - thanks

1 answer

0 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2019

Hi Jesper,

you simply cannot use the Time in Status custom field for that, since that custom field type has _no idea_ what "business hours" means. This is actually a complicated problem: the time spent in a particular status is really the time that elapsed between the moment the issue entered the status and the moment it left the status. Calculating the absolute duration is easy, but what about business time? That would require knowing exactly which day is a business day (excluding weekends and holidays), and also when the business day starts and when it ends. Not to mention, this could be different for different users, and it's also dependent on the timezone of the user, etc.

So if you know exactly how to calculate this duration, you can indeed create a Calculated Duration custom field, but you'll need to implement the algorithm yourself based on your own definition of business time.

Suggest an answer

Log in or Sign up to answer