The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner: show time in status in hours

Jakob KN
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
September 24, 2019

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.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Eduard Dubilyer
August 19, 2025

I've translated time in status to a pretty format (jira style 2d 1h 2m) here:
https://github.com/dubilyer/jira-time-in-status

0 votes
Deniz Oğuz - The Starware
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
September 24, 2019

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.

Jakob KN
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 14, 2019

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?