Script Field with working hours issue is "In Progress"

We need to create a Script Field that shows the user how many working hours (9AM to 6PM).

 

We have managed to generate the following script that is returning the TOTAL time that the issue is "In Progress" status.

 

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def inProgressName = "In Progress"

List<Long> rt = [0L]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->

def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == inProgressName) {
rt << -timeDiff
}
if (item.toString == inProgressName){
rt << timeDiff
}
}

def total = rt.sum() as Long
total = (total/1000) as long ?: 0L

BigDecimal tot = total/3600

return tot

 

But we need to filter this to count the time only during the working hours (9AM to 6PM) and whenever this status is set to "In Progress" (even if it changes to other status beyond the working hours).

How can we do this?

Regards,

Victor Seger

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Asked yesterday in Data Center

Hi! I'm Cameron Deatsch, enterprise enthusiast and Head of Server at Atlassian. AMA!

Hey team! I'm Cameron Deatsch, Head of Server at Atlassian. At our European Summit just a few weeks ago, I spoke about the latest regarding our Server and Data center products and o...

14,034 views 3 4
View question

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you