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
}
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
You can create a custom template, thats the only way I see.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.