How to calculate the time difference from open to closing of an issue?

Vineet Kumar March 17, 2016

Hi All, How can i calculate the total time spent while closing(from open) an issue in JIRA. Please advise.

1 answer

1 vote
Vasiliy Zverev
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.
March 17, 2016

Here is a version for culculated field provided by ScriptRunner.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean

/**
 * Return time between two statuses
 */

//Issue issue = null;
long endStatusTime = 0;

String endStatusName = "Закрыт"

ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
for(ChangeHistory changeHistory: changeHistoryManager.getChangeHistories(issue))
    for(ChangeItemBean changeItemBean: changeHistory.getChangeItemBeans()) {
        if (changeItemBean.getField().equals("status")){

            if( changeItemBean.getToString().equals(endStatusName) ){
                endStatusTime = changeItemBean.getCreated().getTime()
            }
        }
    }

return  String.format("%.2f", (endStatusTime - issue.getCreated().getTime())/(1000*60*60*24))

If you do  not want to use this plugin you could get this data via SQL.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events