Script Library: 1223 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: sunanda

Documentation for: work-days.r


     Author: Sunanda
    Version: 1.0
       Date: 18-feb-2007
 

1. calculate working days

This script calculates the number of working days between two dates.

2. examples:

     do %work-days.r
     calc-work-days now now + 7 []
     == 5   ;; working weeks have five working days

     calc-work-days 1-jan-2008 5-jan-2008 []
     == 3    ;; tue to sat is three working days (wed, thu, fri)
     calc-work-days/non 1-jan-2008 5-jan-2008 []
     == 1    ;; tue to sat is one non-working day (sat)
 

3. usage

3.1. starting the script

do %work-days.r 

3.2. functions

There is just one function with one optional refinement:

3.2.1. calc-work-days start, end, holidays

Where:

  • start is the first date of the period
  • end is the last date of the period
  • holidays is a block of dates which are not working days (eg Christmas, Easter, and/or national holidays). The block must be supplied, but may be empty.

3.3. /non refinement

"inverts" the output -- ie output is number of non-working days in the range.

4. definitions / specification

  • Working days between two dates means whole days, not including the first day in the range. Mon 1-jan to Mon 1-jan (ie the same day) is zero working days as a range (It is of course, one working day if you have to work it)
  • A working day is defined as Monday through Friday. This is not a universally accepted definition, though it does work well in most of the Western world. Please feel free to chip in code changes to parameterise this definition.

5. acknowledgements / credits

This script was written in response to a challenge on the REBOL Mailing List  to produce a better script.

Thanks to Ed O'Conner for providing that initial impetus.

His challenge came from seeing a RUBY version of the script.  It is instructive to compare all the approaches used.

Last updated: 18-Feb-2007