Hi All, I have 2 custom field date-time picker, and I want to get the difference of them using scripted field, but my field returns milliseconds. How can I convert it to days hours using:
Search Template : Duration Picker or Date Time Range Picker
Template : Custom ,
code : $datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)
script -->
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_10806');
def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_10807');
if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date
return dateValue.getTime() - dateValue2.getTime() as Date
}
it says cannot return value of type long 2382000000 on method for java.util.Date. Thanks
Hello @Alvin
In your code the statement
dateValue.getTime() - dateValue2.getTime()
returns long value and you are trying to cast it to "Date" thus you see this error.
Instead you should return
return new Date(dateValue.getTime() - dateValue2.getTime())
Hi @Tarun Sapra , thank you for a quick response . Can you check this out, I configured my code based on your suggestion but it returns like this:
Description :
Dates:
I need to return it something like XX Days XX Hours XX Mins, can you help me out? Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, @Alvin in order to return the value in days, hours etc, it's possible to do that. Just use JiraDurationUtils.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tarun Sapra , I already managed to do that, but it is visible on Description Tab. not on the Dates Tab, how can I fix that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Alvin
In the custom template, use the following snippet
$jiraDurationUtils.getFormattedDuration($value)
And from your script return (i.e. returned value should be long) which is passed to jira duration utils.
return dateValue.getTime() - dateValue2.getTime()
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.