Add three days skipping weekends automatically to a Date Picker

Use case

Add three days to a date picker from another date picker field of your choice.


⚒️ Configuration

Add the post function Update fields to the transition of your choice.

Target issue*

Select current issue.

Fields

Field*

Choose a date field to be updated, e.g. Date picker, Planned end date, Planned start date or Due date.

Value*

Select Set field value manually (Jira expression) and enter the following expression after replacing "nnnnn" in "issue?.customfield_nnnnn" with the ID of the source date picker field.

Bash
startDate = issue?.customfield_nnnnn != null ? new Date(issue?.customfield_nnnnn + "T00:00:00Z") : null;
if(startDate == null){return null}
else {
	daysAdded = 3;
	startDateWeekday = startDate.getDay() == 0 ? 7 : startDate.getDay();
	weekendsSkipped = (daysAdded / 5) - (daysAdded / 5) % 1;
	endDate = startDate.plusDays(daysAdded + (weekendsSkipped*2));
	endDateWeekday = endDate.getDay() == 0 ? 7 : endDate.getDay();
		if(startDateWeekday == 6 && endDateWeekday == 6) {return endDate.minusDays(1)}
        else if(startDateWeekday == 7 && endDateWeekday == 7) {return endDate.minusDays(2)}
        else if(startDateWeekday == 6 && endDateWeekday == 7) {return endDate.plusDays(1)}
        else if(startDateWeekday == 7 && endDateWeekday == 6) {return endDate}
        else if(startDateWeekday == 6) {return endDate.plusDays(1)}
        else if(startDateWeekday == 7) {return endDate.plusDays(0)}
        else if(endDateWeekday == 6) {return endDate.plusDays(2)}
        else if(endDateWeekday == 7) {return endDate.plusDays(2)}
        else if(startDateWeekday < endDateWeekday) {return endDate}
        else if(startDateWeekday == endDateWeekday) {return endDate}
        else if(startDateWeekday > endDateWeekday) {return endDate.plusDays(2)}      
        else {return null}
}

 With minor modifications, you will be able to add a different number of days to any date skipping weekends by replacing the number 3 in the daysAdded variable with the desired number of days.


📚 Related use cases