Hi Community!
I'm trying to create a scripted field with Scriptrunner, which shows the time difference between two Date Time custom fields (called Start Date & End Date).
I'm using the Duration template, since I want the field to be shown in the dates-panel on the right.
When i test my script against different issues, it always returns the correct number of days between the two dates, but followed by "Seconds".
The goal is to have the field shown "XX months XX weeks XX hours and XX minutes".
My script looks as follows:
import com.atlassian.jira.component.ComponentAccessor
final String firstDate = "Start Date"
final String secondDate = "End Date"
def customFieldManager = ComponentAccessor.customFieldManager
def firstDateObject = customFieldManager.getCustomFieldObjects(issue).find { it.name == firstDate }
def secondDateObject = customFieldManager.getCustomFieldObjects(issue).find { it.name == secondDate }
if (!firstDateObject || !secondDateObject) {
return null
}
def firstDateValue = issue.getCustomFieldValue(firstDateObject) as Date
def secondDateValue = issue.getCustomFieldValue(secondDateObject) as Date
secondDateValue - firstDateValue
Any help or suggestion will be much appreciated.
I'm on Jira Data Center 8.2.3, with Scriptrunner 5.5.7.1-jira8