Hello guys!
I'm trying to come up with a script to calculate the time between two transitions. In this case, the cycle time, so how long it took an issue from the In Progress status until a resolution was applied. I'm terrible with Java dates, but I've managed to create a script that returns this difference in a pretty format, the code is below
import java.time.ZonedDateTime
import java.text.SimpleDateFormat
import java.util.Date
import java.util.concurrent.TimeUnit //for pretty format
def issueKey = "TP-5"
// Jira date timestamp field format
def timePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
//get issuedata thrugh API
def issuedata = get("/rest/api/3/issue/${issueKey}?expand=changelog")
.asObject(Map).body
//filter changelogs when enterd 'in progress'
def enterProgress = issuedata.changelog.histories.findAll{it.items.toString.contains("In Progress")}.created
//getting the date of changelog for resolution
def resChanges = issuedata.changelog.histories.findAll{it.items.field.contains("resolution")}.created
def enterProgressDate = new SimpleDateFormat(timePattern).parse(enterProgress)
def resolvedDate = new SimpleDateFormat(timePattern).parse(resChanges)
def diff = resolvedDate.getTime() - enterProgressDate.getTime()
//difference in minuts
long differenceMin = (diff / 1000)/60;
//Difference in pretty format
long DD = TimeUnit.MILLISECONDS.toDays(diff)
long HH = TimeUnit.MILLISECONDS.toHours(diff) %24
long MM = TimeUnit.MILLISECONDS.toMinutes(diff) % 60
long SS = TimeUnit.MILLISECONDS.toSeconds(diff) % 60
String prettyDuration = String.format("%02dd %02dh %02dm %02ds",DD, HH, MM, SS)
return prettyDuration
Now, here's where it gets a little too complicated for me. Is there a way that I can show the time between those status as working days - where 1 day = 8 hours, and also skipping weekends?
Any insight will be of great help! Thanks in advance!