Missed Team ’24? Catch up on announcements here.

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

How can I calculate time to close?

Jenifer Kuntz January 19, 2015

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
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 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()
Jenifer Kuntz January 21, 2015

Thank you!

0 votes
Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 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

 

Jenifer Kuntz January 20, 2015

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
AUG Leaders

Atlassian Community Events