Hi,
I am using the following script to return the time difference between two date-time custom fields
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_10220');
def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_13605');
if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue = issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2 = issue.getCustomFieldValue(dateFieldObject2) as Date
def calculation = (dateValue.getTime() - dateValue2.getTime())
return calculation ;
}
How to return the difference between two days as Months: Days: Hours: Minutes:
Thanks
Just a side note: you could also use an app like JMCF to create a calculated _duration_ field, which would not only display the value like a duration but also make it searchable like a duration.
I modified the script as below,
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_10802');
def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_10801');
if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue = issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2 = issue.getCustomFieldValue(dateFieldObject2) as Date
def calculation = (dateValue.getTime() - dateValue2.getTime())/(1000*60)
//return calculation /1000 / 3600 / 24 ;
def hours = calculation / 60;
def minutes = (calculation ).doubleValue() % 60;
def days = hours / 24;
def years = days / 365;
hours = hours.doubleValue() % 24;
days = days.doubleValue() % 365;
return ("Days: " + days.floatValue() + " Hours: " + hours.floatValue() + " Minutes: " + minutes.floatValue());
}
I got the result Days: 46.499306 Hours: 11.983334 Minutes: 59.0
Q- How to round the floating up to 2 decimals only?
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.