Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Convert Milliseconds to Day Hours Min Format using Scripted Field

Alvin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 01, 2018

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

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 01, 2018 • edited

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())
Alvin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 01, 2018

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 :

Screenshot from 2018-10-02 09_49_03.png

 

Dates:

 Screenshot from 2018-10-02 09_48_44.png

I need to return it something like XX Days XX Hours XX Mins, can you help me out? Thanks!

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 02, 2018

Hello, @Alvin in order to return the value in days, hours etc, it's possible to do that. Just use JiraDurationUtils.

Alvin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 02, 2018

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?

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 02, 2018

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()
TAGS
AUG Leaders

Atlassian Community Events