Forums

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

How to round the result of Scriptrunner's Duration Template for Scripted Fields?

Jordan Klein July 16, 2019

Hello,

 

The Scripted Field code below successfully outputs the current time that an issue has been in an Unresolved state. The issue I'm having is that the Scriptrunner duration searcher is displaying the end result like this:

Time Unresolved: 1 week, 1 day, 18 hours, 40 minutes

How can I round the result programmatically so that it is only displaying weeks & days and excluding hours and minutes?

 

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()


def createdDateDiff = System.currentTimeMillis() - issue.getCreated().getTime()


def resolvedName = "Resolved"
def requestClosedName = "Request Closed"
def closedName = "Closed"

def check = false

List<Long> rt = [0L]
//issue.getCreated().getTime()


def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
//changeItems.reverse().each {ChangeItemBean item ->
changeItems.each {ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()

if (check == false)
{
rt << item.created.getTime()-issue.getCreated().getTime()
check = true
}


if (item.toString == resolvedName || item.toString == requestClosedName || item.toString == closedName)
{

rt = [0L]

}

else
{
rt << timeDiff
}
}




def total = rt.sum()

if (total == 0)
{
total = null
return null
}
else
{

return (total / 1000) as long ?: 0L

}

2 answers

3 votes
Matias Stachowski
Contributor
July 22, 2019

You can just remove the hours/minutes/seconds by subtracting the total modulated by 24*60*60*1000

 

def sub = total%(24*60*60*1000)
return ((total-sub) / 1000L) as Long

 

0 votes
Ilya Turov
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 Leaders.
July 17, 2019

You can create a custom template, thats the only way I see.

Suggest an answer

Log in or Sign up to answer