Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,538
Community Members
 
Community Events
168
Community Groups

need to write the script in the postfunction to add the current date + 10 Days excluding the weekend

need to write the script in the postfunction of the workflow  to add the current date + 10 Days excluding the weekend

Please help me in exclude the weekends

eg : current date = 9th nov 4:12 +10 days  means the result should show as 

result = 23 nov 4:12 ( as weekend will fall on saturday and sunday)

 

Already written the script which is adding 10 days but including the weekends:

import com.atlassian.jira.component.ComponentAccessor

import java.sql.Timestamp

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def dateCf = customFieldManager.getCustomFieldObject("customfield_18761") issue.setCustomFieldValue(dateCf, new Timestamp((new Date() + 7).time))

return dateCf

 

2 comments

Leo Community Leader Nov 11, 2020

Hi @kiranmai genkolla,

I've written custom listener similar to your requirement quite long back(it's for 5 days)

this may give you some idea for start point

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.core.util.DateUtils
import java.util.Date.*
import java.text.SimpleDateFormat;
import java.text.DateFormat;

Issue issue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def baselineName = customFieldManager.getCustomFieldObjectByName("Base Date Field")
def baselineValue = issue.getCustomFieldValue(baselineName) as Date
DateFormat df = new SimpleDateFormat("dd/MMM/yyyy");

if(baselineValue != null)
{

Calendar baselineDate = GregorianCalendar.getInstance();
baselineDate.setTime(baselineValue);
int nod = 5
int weeks = (nod/5).intValue();
int remDays = nod%5;
baselineDate.add(Calendar.WEEK_OF_YEAR, weeks);

for(int i=1;i<=remDays;i++){
baselineDate.add(Calendar.DAY_OF_MONTH, 1);
if (baselineDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
baselineDate.add(Calendar.DAY_OF_MONTH, 1);
if (baselineDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
baselineDate.add(Calendar.DAY_OF_MONTH, 1);
}

if (baselineDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
baselineDate.add(Calendar.DAY_OF_MONTH, 1);
if (baselineDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
baselineDate.add(Calendar.DAY_OF_MONTH, 1);


baselineDate.clearTime()

//c1.getTime()
return baselineDate.getTime()
}
else {}

 

BR,

Leo

Like Alexander Bondarev likes this

Comment

Log in or Sign up to comment