Script Field with working hours issue is "In Progress"

Victor Seger January 23, 2018

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
TAGS
AUG Leaders

Atlassian Community Events