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

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

kiranmai genkolla November 11, 2020

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

Comment

Log in or Sign up to comment
Tomáš Vrabec
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.
November 11, 2020
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 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
TAGS
AUG Leaders

Atlassian Community Events