Documention for: work-days.r Created by: sunanda on: 18-Feb-2007 Format: text/editable Downloaded on: 30-Apr-2025 [numbering-on [contents [asis Author: Sunanda Version: 1.0 Date: 18-feb-2007 asis] [h2 calculate working days [p This script calculates the number of **working days** between two dates. [h2 examples: [asis 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) asis] [h2 usage [h3 starting the script [asis do %work-days.r asis] [h3 functions [p There is just one function with one optional refinement: [h4 calc-work-days **start**, **end**, **holidays** [p Where: [li **start** is the first date of the period [li **end** is the last date of the period [li **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. list] [h3 /non refinement [p ""inverts"" the output -- ie output is number of non-working days in the range. [h2 definitions / specification [li **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) [li 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. list] [h2 acknowledgements / credits [p This script was written in response to a challenge on the [link/fsl http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-thread.r?m=rmlTFJC "REBOL Mailing List" to produce a better script. [p Thanks to Ed O'Conner for providing that initial impetus. [p His challenge came from seeing a [link/class/fsl http://www.railsonwave.com/railsonwave/2007/1/30/calculate-the-number-of-working-days-between-two-dates "RUBY version of the script." It is instructive to compare all the approaches used. [p [date