Hi all,
We have used the following approach to implement automated due dates, how ever as you may see in the title, We need help excluding weekends.
Original post: https://answers.atlassian.com/questions/195955/automatic-due-date-by-issue-type-when-creating-ticket
Here is the code in use (Groovy):
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.CustomFieldType import com.atlassian.jira.issue.fields.CustomField import java.sql.Timestamp; MutableIssue myIssue = issue Calendar cal = Calendar.getInstance(); // set due date to: current date + 8 days Timestamp mydueDate = new Timestamp(cal.getTimeInMillis()+ 8*1000*24*60*60); myIssue.setDueDate(mydueDate);
How ever if we could exclude weekends, that would help. If anyone would be assist?
Thanks
Community moderators have prevented the ability to post new answers.
Hi,
it's from the other answer but maybe I get some Karma here :-)
import com.atlassian.jira.issue.MutableIssue import java.sql.Timestamp; MutableIssue myIssue = issue; Calendar duedate = Calendar.getInstance() duedate.add(Calendar.DATE,1) while ([Calendar.SATURDAY, Calendar.SUNDAY].contains(duedate.get(Calendar.DAY_OF_WEEK))) { duedate.add(Calendar.DATE,1) } def dueTimestamp = new Timestamp(duedate.getTimeInMillis()) myIssue.setDueDate(dueTimestamp) log.warn ("script setduedate is running...and dueTimestamp is:" + dueTimestamp)
Hi Henning, Thanks for your effort but i have managed to be successful with the following solution:
import org.apache.log4j.Category import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.CustomFieldType import com.atlassian.jira.issue.fields.CustomField import java.sql.Timestamp; int days = 8; int dayOfWeek = 0; Date today = new Date(); MutableIssue myIssue = issue Calendar dueDate = Calendar.getInstance(); while ((dayOfWeek == 0) || (dayOfWeek == Calendar.SATURDAY) || (dayOfWeek == Calendar.SUNDAY)) { dueDate.setTimeInMillis(today.getTime() + days*1000*24*60*60); dayOfWeek = dueDate.get(Calendar.DAY_OF_WEEK); days = days + 1; } System.out.println("script setduedate is running...and mydueDate is:" + dueDate.getTime()); myIssue.setDueDate(new Timestamp(dueDate.getTime().getTime()));
However for all your help over the past few months I don't mind to award you with Karma, But I don't know how. If you tell me u shall recieve.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
:-) If you accept an answer or upvote an answer or like a comment the author gets karma points. So, everything's fine, thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have done something similar for a listener. You can check it here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In our company we use JJUPIN (sil) scripting plugin to calculate due date excluding weekends.
This example script can give you some idea and help to calculate due date excluding weekends (have some indicators for SLA).
We put this script in the post function of workflow.
interval intervalTime="2d"; //interval time to do a task string day = dayOfWeek(currentDate()); dueDate = currentDate()+delais; //dayOfWeek(date) can return "Sun","Mon","Tue","Wed","Thu","Fri","Sat" dueDate = currentDate()+intervalTime; //In our country , weekend are friday and Saturday and wa can work in weekend if(day=="Thu" or day=="Wed" or day=="Fri"){ dueDate = dueDate+"2d"; } else{ if(day=="Sat"){ dueDate=dueDate+"1d"; } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Thanks for your input...but I'm not sure that logic may work?
Any other suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I assure you that this is how we calculated the due date excluding
(tested and approved).
weekend but valid for only one week.
For more than a week (eg IntervalTime = "21d" 3 weeks) the script is like this
interval intervalTime="21d"; //interval time to do a task string day = dayOfWeek(currentDate()); dueDate = currentDate()+delais; //dayOfWeek(date) can return "Sun","Mon","Tue","Wed","Thu","Fri","Sat" dueDate = currentDate()+intervalTime; //In our country , weekend are Friday and Saturday and wa can work in weekend if(day=="Sat"){ dueDate=dueDate+"5d";//there are 2 weekends and 1 day if user work in Saturday } else{ dueDate=dueDate+"6d"; //there are 3 weekends = 6 days in 21 days }
In our company, we use JJUPIN is why I gave you this example so that you can have an idea. Another method I do not know, but I think there are.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you are using JJUPIN, do check the getworkinginterval function present in the below URL. It's pretty cool.
https://confluence.kepler-rominfo.com/display/JJUP20/getWorkingInterval
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.