Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,262,384
Community Members
 
Community Events
164
Community Groups

How can I calculate time to close?

I am trying to calculate the time an issue is created until the time it is closed.  I created a time date field (Closed Date) that is populate with the date the issue is closed in a post function. I found code that allows me to calculate the time to resolution and I am trying to make it work for closed also but can not figure out the how to pull in the custom date field.  Any help would be much appreciated.

 

Using Script Runner Scripted Fields

This is the code I am using for Time to Resolution:

import com.atlassian.core.util.DateUtils
def resolvedNames = ["Resolved""Closed"]
def timeDiff;
if (issue.statusObject.name in resolvedNames) {
    timeDiff = issue.getResolutionDate().getTime() - issue.getCreated().getTime()
else {
    timeDiff = System.currentTimeMillis() - issue.getCreated().getTime()
}
// NOTE: doesn't show anything if less than 60 seconds
DateUtils.getDurationString(Math.round(timeDiff / 1000))

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Paul Pasler Marketplace Partner Jan 21, 2015

You need to access the custom filed itself and retrieve the value for the issue.

Try this:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

....

def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(ClosedDate)
def closedDate = (Date)issue.getCustomFieldValue(field); 
timeDiff = closedDate.getTime() - issue.getCreated().getTime()
0 votes
Paul Pasler Marketplace Partner Jan 19, 2015

You want to write the value of DateUtils.getDurationString to the custom field, right? Try

return DateUtils.getDurationString(Math.round(timeDiff / 1000))

Or do you want to read from the custom field? Maybe this helps:

https://answers.atlassian.com/questions/284367

The code is from here: https://jamieechlin.atlassian.net/wiki/display/GRV/Scripted+Fields

 

I am actually trying to figure out how to perform this part 

timeDiff = issue.getResolutionDate().getTime() - issue.getCreated().getTime()

I need the bold part to reflect the custom field I created called ClosedDate

I tried issue.getClosedDAte().getTime() but that did not work

TAGS
Community showcase
Published in Apps & Integrations

Mini New Cloud App Roundup: Business Teams

We are sharing mini new cloud roundups by use case to celebrate the Atlassian Marketplace's 10th Anniversary! This mini roundup is the fourth in a series of six. Check out others in the series based ...

22 views 0 0
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you