Dear Community,
I have a field that calculates the difference between two dates:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.util.*
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateResponse = customFieldManager.getCustomFieldObjectByName('Date of First Response');
if(issue.getCustomFieldValue(dateResponse) && issue.created)
{
def dateValue= issue.getCustomFieldValue(dateResponse) as Date
def dateValue2= issue.created
def dif = dateValue.getTime() - dateValue2.getTime()
return dif
}
I want to display value of this field in format: "XX Days YY Hours ZZ Minutes QQ Seconds"
Anyone can help me out?
Thanks in advance.
Now it is fixed.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.util.*
import java.util.Date.*
import com.atlassian.core.util.DateUtils
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateResponse = customFieldManager.getCustomFieldObjectByName('Date of First Response');
if(issue.getCustomFieldValue(dateResponse) && issue.created)
{
def dateValue= issue.getCustomFieldValue(dateResponse) as Date
def dateValue2= issue.created
def dif = dateValue.getTime() - dateValue2.getTime() as float
return DateUtils.getDurationString(Math.round(dif / 1000))
}
Script Field:
Template: Text Field (multi-line)
Searcher: Free text searcher
You could use brute force to calculate the d/h/m/s from the raw number of seconds, but I'd use Jira's date formatter myself - https://docs.atlassian.com/software/jira/docs/api/7.12.1/com/atlassian/jira/util/JiraDurationUtils.html
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.
There's sample code on https://scriptrunner.adaptavist.com/4.1.3.7/jira/working-with-tempo.html (I know, a little odd to point you at Tempo integration, but actually the code is for any duration, not just Tempo data)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you. It's working, but the calculation is wrong:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.util.*
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateResponse = customFieldManager.getCustomFieldObjectByName('Date of First Response');
if(issue.getCustomFieldValue(dateResponse) && issue.created)
{
def dateValue= issue.getCustomFieldValue(dateResponse) as Date
def dateValue2= issue.created
def dif = dateValue.getTime() - dateValue2.getTime()
return dif as Long
}
#if($value)
$jiraDurationUtils.getFormattedDuration($value)
#end
Any ideas why?
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.