Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function officeWorkDay (startDay As Date, numWorkDays As Number) As Date
- ' Identify the Monday before (or equal) firstDay
- Dim s As Number, d As Number, endDate As Date
- s = dayOfWeek(startDay, crMonday) - 1
- ' Work out the resulting work day but not yet allowing for holidays
- If numWorkDays > 0 Then
- d = numWorkDays
- endDate = startDay - s ' move to beginning (Monday) of current week
- If (s >= 5) Then
- s = 4 ' Adjustment for start date is never more than 4 WD's
- End If
- d = d + s
- endDate = endDate + (d \ 5) * 7 + d Mod 5
- Else
- If numWorkDays < 0 Then
- d = -1 * numWorkDays
- endDate = startDay + 4 - s ' move to friday of current week
- If (s >= 5) Then
- s = 5 ' Adjustment for start date is never more than 5 WD's
- End If
- d = d + 4 - s
- endDate = endDate - (d \ 5) * 7 - d Mod 5
- Else
- endDate = startDay
- End If
- End If
- ' Work out the number of holidays in the range
- '
- Dim numHolidayDays As Number
- If numWorkDays > 0 Then
- numHolidayDays = officeNumHolidaysIn(startDay, endDate)
- Else
- If numWorkDays < 0 Then
- numHolidayDays = officeNumHolidaysIn(endDate, startDay)
- End If
- End If
- ' Now add this number of workdays onto the end of the range
- ' i.e. add the number of days but checking to ensure they're not holidays as well
- '
- Do While (numHolidayDays > 0)
- endDate = nextWeekDay(endDate, (numWorkDays > 0))
- If Not officeIsNonWorkingDay(endDate) Then
- numHolidayDays = numHolidayDays - 1
- End If
- Loop
- ' Special case if we are adding 0 working days; make sure end date is a working day
- If numWorkDays = 0 Then
- endDate = officeThisOrNextWorkDay(endDate)
- End If
- officeWorkDay = endDate
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement