Mark,
As I have discussed with you...I am done a similar app as yourself...Employee Leave Management.
In mine the non working day for an Employee is not just limited to Weekends. It could be any day of the week. I agree with Rod, that you need to start by stripping the leading and trainling target days and then test in between. I spent yesterday nutting through this logic and present it below for you to try.
I have tested each part and it works.
The awesomeness about Aware is that the Rule engine will continue to execute these Rules all the while the conditions are true. Hence, no matter how long your Event is, it will be broken up into as many smaller Events as necessary to avoid an Event day falling on your non-work day.
Monday is Unique, but Sunday and Tuesday to Saturday are virtually the same with just number alterations....
SUNDAY:
Strip Starting Sunday
DAY_NUMBER_IN_WEEK(Event.StartDate)=1
Is the Start Day a Sunday
Event.StartDate=DATE_ADD(Event.StartDate,1)
If Yes, Then Move the Start Date forward by 1 Day. If No, Do Nothing
Strip Ending Sunday
DAY_NUMBER_IN_WEEK(Event.EndDate)=1
Is the End Day a Sunday?
Event.EndDate=DATE_ADD(Event.EndDate,-1)
If Yes, Then Move the End Date backward by 1 Day. If No, Do Nothing
Does the Event Still Contain a Sunday?
Is the a Sunday within a week of our Start Date
END_OF_WEEK(Event.StartDate)>Event.StartDate AND
END_OF_WEEK(Event.StartDate)<Event.EndDate
Is the Date of Next Sunday > our Start Date
Is the Date of Next Sunday < our End Date?
IF so, Create a New Event
Set New Start to 1 Day after Next Sunday…Monday
CREATE Event WITH
Event.StartDate=DATE_ADD(END_OF_WEEK(ThisEvent.StartDate),1),
Event.EndDate=ThisEvent.EndDate
Set End Date to Original Event End Date and Adjust Existing Event
Set End Date to Next Saturday. Day Before Sunday
ThisEvent.EndDate=DATE_ADD(END_OF_WEEK(ThisEvent.StartDate),-1)
MONDAY:
Strip Starting Monday
DAY_NUMBER_IN_WEEK(Event.StartDate)=2
Is the Start Day a Monday
Event.StartDate=DATE_ADD(Event.StartDate,1)
If Yes, Then Move the Start Date forward by 1 Day. If No, Do Nothing
Strip Ending Monday
DAY_NUMBER_IN_WEEK(Event.EndDate)=2
Is the End Day a Monday?
Event.EndDate=DATE_ADD(Event.EndDate,-1)
If Yes, Then Move the End Date backward by 1 Day. If No, Do Nothing
Does the Event Still Contain a Monday?
Is the a Monday within a week of our Start Date
DATE_ADD(END_OF_WEEK(Event.StartDate),1)>Event.StartDate AND
DATE_ADD(END_OF_WEEK(Event.StartDate),1)<Event.EndDate
Is the Date of Next Monday > our Start Date
Is the Date of Next Monday < our End Date
IF so, Create a New Event
Set New Start to 2 Days after Next Sunday…Tuesday
CREATE Event WITH
Event.StartDate=DATE_ADD(END_OF_WEEK(ThisEvent.StartDate),2),
Event.EndDate=ThisEvent.EndDate
Set End Date to Original Event End Date
and Adjust Existing Event Set End Date to Next Sunday. Day Before Monday
ThisEvent.EndDate=END_OF_WEEK(ThisEvent.StartDate)
For Tuesday, Wednesday....Saturday, you need to Increment the number in the DAY_NUMBER_IN_WEEK functions when stripping leading and trailing, the number of days to add in the DATE_ADD functions.
Also, the last Action for Monday needs to revert back to same style as for Sunday when you do Tuesday...Saturday...but the days to add increments from 1 for Tues ..... 5 for Sat as below...
Tue:
ThisEvent.EndDate=DATE_ADD(END_OF_WEEK(ThisEvent.StartDate),1)
Wed:
ThisEvent.EndDate=DATE_ADD(END_OF_WEEK(ThisEvent.StartDate),2)
Thu
ThisEvent.EndDate=DATE_ADD(END_OF_WEEK(ThisEvent.StartDate),3)
Fri
ThisEvent.EndDate=DATE_ADD(END_OF_WEEK(ThisEvent.StartDate),4)
Sat
ThisEvent.EndDate=DATE_ADD(END_OF_WEEK(ThisEvent.StartDate),5)
Hope this helps.