Hi Community!
I have created a custom field through scriptrunner, which shows the time an issue have been in the status "Under Review".
The field is created with the Duration template and is scripted as follows:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def inProgressName = "Under Review"
List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.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
return (total / 1000) as long ?: 0L
Currently the field displays the time in status with Weeks, Days, Hours and Minutes.
What i need, is for it to display the total time in hours only.
From looking around here in the community, I can see that i might have to import:
com.atlassian.jira.util.JiraDurationUtils.HoursDurationFormatter
But, I am unsure of how i change the actual output shown in the field, so it's only showing the total amount of hours.
Any help or hints are greatly appreciated.
You can access JiraDurationUtils using following code.
ComponentAccessor.getComponent(
com.atlassian.jira.util.
JiraDurationUtils.class);
This class converts seconds to user readable strings but as far as I can remember it counts each day as 8 hours, and each week as 5 day depending on Jira settings. So 28800 seconds (8 hours) may be displayed as 1day.
Hi Deniz,
Thanks for you reply!
I need days to be counted as 24 hours, due to how the team works in the project.
along with that, 24 hours shouldn't be shown as "1 day" but instead 24 hours.
What i'm looking to do, is simply show the total amount of hours an issue have been in a certain status.
Do you know how this would be done?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.