Skip to content

Instantly share code, notes, and snippets.

@vikrantyadav11
Created April 27, 2021 05:29
Show Gist options
  • Save vikrantyadav11/83e112392d67f3d5e8a561dcd6a62b9b to your computer and use it in GitHub Desktop.
Save vikrantyadav11/83e112392d67f3d5e8a561dcd6a62b9b to your computer and use it in GitHub Desktop.
Calculate TIme in a Status
import com.atlassian.jira.component.ComponentAccessor
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def currentStatusName = issue?.status?.name
def rt = [0L]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == currentStatusName) {
rt << -timeDiff
}
if (item.toString == currentStatusName){
rt << timeDiff
}
}
def total = rt.sum() as Long
return (total / 1000) as long ?: 0L
//return (Math.round(rt.sum() / 3600000 / 24)) as Double
//return (Math.round(rt.sum() / 3600000)) as Double
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment