Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you