Hello,
Server and App details:
Jira Data Center Installed version: 8.22.6
Adaptavist ScriptRunner Installed version: 8.14.0
I found this script on the adaptavist library and it works great. Is there a way to exclude weekends from the duration? Any help would be appreciated as I'm not that great at coding. script below:
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import java.time.temporal.ChronoUnit
// Get the required component
def customFieldManager = ComponentAccessor.customFieldManager
// The name of the lower date custom field
final String lowerDateCustomFieldName = "Start Date/Time"
// The name of the higher date custom field
final String higherDateCustomFieldName = "Resolution Date/Time"
// Get the custom field objects
def lowerDateCustomField = customFieldManager.getCustomFieldObjects(issue).find { it.name == lowerDateCustomFieldName }
def higherDateCustomField = customFieldManager.getCustomFieldObjects(issue).find { it.name == higherDateCustomFieldName }
if (!lowerDateCustomField || !higherDateCustomField) {
log.info "Could not find one ore more of the provided custom fields"
return null
}
// Get the date values from both issues
def lowerDateValue = issue.getCustomFieldValue(lowerDateCustomField) as Timestamp
def higherDateValue = issue.getCustomFieldValue(higherDateCustomField) as Timestamp
// Transform both values to instants
def lowerDateInstant = lowerDateValue?.toInstant()
def higherDateInstant = higherDateValue?.toInstant()
// Change the chrono unit to obtain the difference in other time unit.
final chronoUnit = ChronoUnit.SECONDS
// Calculate the difference between the lower and the higher date.
lowerDateInstant && higherDateInstant ? chronoUnit.between(lowerDateInstant, higherDateInstant) : null