Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

SIL Script to take into account business days

Karoly Guerrero
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 8, 2021

I am trying to set the due date of a sub-task based on the starting date of the parent-task plus the days assigned for the sub-task. I have to take into account weekends. Example of my code:

// this one does not take into account the weekends, but works fine

date startdate = %key%.customfield_15303;
string issueSummary1 = "Request for contract"
string issue1 = createIssue("X", key, "Unteraufgabe", issueSummary1, "", "", {}, startdate+"5d", "", "", "");

I tried to make a function to take into account just working days, which goes like this:

function businessDays(date startDate, number addedDays){

while (addedDays > workingdays){
string nd = (string)workingdays + "d";
date eachDay = startDate + nd;
string dayofweek = dayOfWeek(eachDay);

if(dayofweek == "Mon" || dayofweek == "Tue" || dayofweek == "Wed" || dayofweek == "Thu" || dayofweek == "Fri"){
workingdays = workingdays + 1;
}
}
nd = (string)workingdays + "d";
date dueDate = startDate + nd;
return(dueDate);
}

string issueSummary1 = "Request for contract"
date assign_dd = businessDays(startdate, 5);
string issue7 = createIssue("X", key, "Unteraufgabe", issueSummary1, "", "", {}, assign_dd, "", "", "");

 But it is not working, are there any other ways to achieve this?

1 answer

0 votes
STAGIL Support
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 26, 2022

Hey @Karoly Guerrero

Was your issue resolved?

Karoly Guerrero
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 26, 2022

Yes, thank you, just did some changes in the code :)

Like STAGIL Support likes this

Suggest an answer

Log in or Sign up to answer