In the steps below, i show you how you calculate the next working day when we add a number of working days(B) to any date(A), considering weekends and holidays(C) using K2.
Example: Calculate the next working date given 4 working days and the date (7/17/2019) considering that 7/23/2019 is a holiday.
Solution: We get as result 7/24/2019, image below.
1. Create a smartbox SMO which will keep all your holidays.
2. Generate a list view on the holidays SMO which will permit you to manage your holidays.
NOTE: The _WeekEndOrNot rule contains advance condition which tests the value returned by the expression below (i). But If the expression returns a Saturday OR Sunday then we conclude that its a weekend and transfer “Yes” to dl_IsWeekEnd else we transfer a “No” to dl_IsWeekEnd.
i. An expression that collects the date in dl_NextWorkingDate and returns the dayname, image below
In 1, we initialise dl_ActiveWorkingDays to 1 then we store the date in Cldr_Date in dl_GivenDate. In 2, we execute Ex_AddDate and keep its value in dl_NextWorkingDate which calls the rule in point 7 below.
From the image above,
In A we store the current value of dl_NextWorkingDate in “dl_GivenDate” .
B Permits to add 1 day to dl_NextWorkingDate which calls when dl_NextWorkingDate Changes(Loop) rule, until we get a working day.
II. Checks if dl_NextWorkingDate contains a working day and we have not added the number of days the user gave.
In C we update dl_ActiveDayCounter by passing to it Ex_DayCounter.
D Keep working date in dl_GivenDate.
E Permits to add 1 day to dl_NextWorkingDate which calls when dl_NextWorkingDate Changes(Loop), till we get a working day.
III. Finally, we check if we have added all the days the user gave and if the actual date in dl_NextWorkingDate is a working day.