• Community
  • Answers Developer Questions
  • Questions
  • Automated Due-dates implemented in jira - Need help excluding weekendsmport com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.Cu

Automated Due-dates implemented in jira - Need help excluding weekendsmport com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.Cu

Warren McInnes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2014

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

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2014

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)

Warren McInnes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2014

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

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2014

:-) If you accept an answer or upvote an answer or like a comment the author gets karma points. So, everything's fine, thanks!

0 votes
Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

I have done something similar for a listener. You can check it here.

0 votes
Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2014

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";
  }
}



Warren McInnes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

Hi, Thanks for your input...but I'm not sure that logic may work?

Any other suggestions?

Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

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.


Satish_Kumar August 4, 2016

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 

TAGS
AUG Leaders

Atlassian Community Events