home *** CD-ROM | disk | FTP | other *** search
- *********
- * Function : WEEKDAYS
- * By : Leonard Zerman
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax : WEEKDAYS( <startdate>, <expN days> )
- * Returns: <expD> date +- <expN> days
- ***********
- FUNCTION WEEKDAYS
- PARAMETERS tr_startdt, tr_nbr_days
- MEMVAR weeks, counter
- PRIVATE weeks, counter
- IF tr_nbr_days = 0
- RETURN tr_startdt
- ENDIF
- IF DOW( tr_startdt ) = 1
- IF tr_nbr_days > 0
- tr_startdt = tr_startdt + 1
- tr_nbr_days = tr_nbr_days - 1
- ELSE
- tr_startdt = tr_startdt - 2
- tr_nbr_days = tr_nbr_days + 1
- ENDIF
- ENDIF
- IF DOW( tr_startdt ) = 7
- IF tr_nbr_days > 0
- tr_startdt = tr_startdt + 2
- tr_nbr_days = tr_nbr_days - 1
- ELSE
- tr_startdt = tr_startdt - 1
- tr_nbr_days = tr_nbr_days + 1
- ENDIF
- ENDIF
- IF tr_nbr_days = 0
- RETURN tr_startdt
- ENDIF
- weeks = INT( tr_nbr_days / 5 ) && Five work days a week
- tr_startdt = tr_startdt + ( weeks * 7 ) && add or sub 7 days a week
- counter = ABS( tr_nbr_days ) - ABS( weeks * 5 )
- DO WHILE counter > 0 && loop though remaining days
- IF tr_nbr_days > 0 && not decrementing for
- tr_startdt = tr_startdt + 1 && weekend days
- ELSE && the day can not land on a
- tr_startdt = tr_startdt - 1 && weekend
- ENDIF && Fri, Sat, Sun, land on Monday
- IF .NOT. ISWKEND( tr_startdt ) && when adding
- counter = counter - 1 && Mon, Sun, Sat, land on Friday
- ENDIF && when subtracting
- ENDDO
- RETURN tr_startdt
- * eof weekdays *
-
-