I am utilizing a post-function script through the Adaptavist Scriptrunner plugin for Jira that is setting the Original Estimate and Remaining Estimate Time-Tracking fields. The script (posted below) is using the System Fields, Created Date and Due Date, to find the difference between the dates in number of days. The script is working properly, and setting the appropriate fields, but there is a bug: it is including weekends in the calculation. I have yet to find an appropriate solution that excludes Saturday's and Sunday's from this calculation, and am wondering if anybody else has had a similar issue and has found a solution. Thanks in advance.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.MutableIssue
import java.util.Date.*
def createdDate = issue.getCreated()
log.warn("Date Created: " + createdDate)
def dueDate = issue.getDueDate()
log.warn("Due Date: " + dueDate)
def numberOfDays = dueDate - createdDate
log.warn("Number of Days Between Dates: " + numberOfDays)
issue.setOriginalEstimate(numberOfDays * 8 * 60 * 60); //Set Original Estimate to number of days between Due Date and Created Date
issue.setEstimate(numberOfDays * 8 * 60 * 60); //Set Remaining Estimate to number of days between Due Date and Created Date