Description
Next business day calculates two business days if the start time is on weekends, holidays, or before business hours.
Steps to Reproduce
-
Navigate to Scripts - Background.
-
Run the following script include.
For more information, see the product documentation topic Using DurationCalculator to calculate a due date.
var dc = new DurationCalculator();
var tz = "Europe/Brussels";
dc.setSchedule("090eecae0a0a0b260077e1dfa71da828", tz); //8-5 weekdays excluding holidays
dc.setStartDateTime("2016-07-01 13:26:40");
dc.calcRelativeDuration("3bfa9bd10a0a0b5200c18037fbaa9a2c"); //End of next business day
gs.print(dc.getEndDateTime()); -
Run the same script, but change the value of dc.setStartDateTime("");.
The output shows unexpected relative end time. Note that July 4 in this scenario is a holiday.
SET START TIME OUTPUT COMMENT
dc.setStartDateTime("2016-07-01 13:26:40"); *** Script: 2016-07-05 15:00:00 This is correct
dc.setStartDateTime("2016-07-02 13:26:40"); *** Script: 2016-07-06 15:00:00 This is not correct, expected output: 2016-07-05
dc.setStartDateTime("2016-07-03 13:26:40"); *** Script: 2016-07-06 15:00:00 This is not correct, expected output: 2016-07-05
dc.setStartDateTime("2016-07-04 13:26:40"); *** Script: 2016-07-06 15:00:00 This is not correct, expected output: 2016-07-05
dc.setStartDateTime("2016-07-05 05:26:40"); *** Script: 2016-07-06 15:00:00 This is not correct, expected output: 2016-07-05, because the business time has not occured yet
dc.setStartDateTime("2016-07-05 09:26:40"); *** Script: 2016-07-06 15:00:00 This is correct
Workaround
Create a new Relative Duration[cmn_relative_duration] in order to avoid having the calculation be two days when the current time is outside of the schedule. Use the following script:
/////// Start Script
var days = 0; var initialStartDateTime = calculator.startDateTime; if (calculator.schedule.isInSchedule(calculator.startDateTime)) days=1; else // Making sure the calculation is not affected when start time is outisde the schedule but after a daily end (example, Friday 19:00). calculator.startDateTime.add(calculator.schedule.whenNext(calculator.startDateTime, calculator.timezone)); calculator.calcRelativeDueDate(calculator.startDateTime, days, "17:00:00"); calculator.startDateTime = initialStartDateTime; /////// End Script
Related Problem: PRB1032810