hi,
I was trying to calculate cycle time (time since) of issue in the current state using the below code.
It is not giving consistent results.
Don't know why
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def currentTime = System.currentTimeMillis()
def stateTime = 0
def items = changeHistoryManager.getChangeItemsForField (issue, "status").reverse()
if (items) {
stateTime = items.first().created.time
}
else {
stateTime = issue.getCreated().time
}
def stateCycleTime = (currentTime - stateTime) / (1000*60*60*24)
return (stateCycleTime as Double).round(2) ;
Can any one help in understanding the problem and a good fix