# workdays: Workday calculations

[ library, mit, time ] [ Propose Tags ]

Versions [RSS] [faq] 0.1.0, 0.1.1 base (>=4.7 && <5), containers, time [details] MIT 2016 Stack Builders Juan Pedro Villa Isaza hackage@stackbuilders.com Time https://github.com/stackbuilders/workdays https://github.com/stackbuilders/workdays/issues head: git clone https://github.com/stackbuilders/workdays by jpvillaisaza at 2016-11-17T16:37:56Z NixOS:0.1.1 1284 total (15 in the last 30 days) (no votes yet) [estimated by Bayesian average] λ λ λ Docs available Last success reported on 2016-11-17

## Modules

[Index]

#### Maintainer's Corner

For package maintainers and hackage trustees

Candidates

• No Candidates

[back to package description]

# Workdays: Workday calculations in Haskell

“Let us sit here for five minutes and think of nothing.”

The workdays library allows to do workday (and weekday) calculations in Haskell.

Based on the workdays Python package.

## Examples

(Tested with GHC 8.0.1.)

In order to use the workdays library, import the Workdays module:

λ> import Workdays


To specify dates, we need to create values of Date using the Date constructor:

λ> :type Date
Date :: Year -> Month -> DayOfMonth -> Date


A value of type Date is a year (Integer), a month (Int), and a day of month (Int).

Here's December 1, 2016:

λ> Date 2016 12 01
Date {dateYear = 2016, dateMonth = 12, dateDay = 1}


The workdays function is used to calculate the number of workdays between two dates:

λ> :type workdays
workdays :: Date -> Date -> Set Date -> Integer


This function takes start and end dates, and a set of dates to exclude.

Let's calculate the number of workdays between December 1, 2016 and December 31, 2016 without excluding dates:

λ> workdays (Date 2016 12 01) (Date 2016 12 31) []
22


If there are no dates to exclude, we're calculating weekdays. We can use the weekdays function instead:

λ> weekdays (Date 2016 12 01) (Date 2016 12 31)
22


To create sets of dates, we need to import the Set data type from the containers library:

λ> import Data.Set (Set)


And we can activate the overloaded lists language extension to create sets as lists:

λ> :set -XOverloadedLists


Let's use some holidays in Colombia as examples. For now, just Christmas Day:

λ> holidays = [Date 2016 12 25] :: Set Date


We can use this set as the set of dates to exclude from the workdays calculation:

λ> workdays (Date 2016 12 01) (Date 2016 12 31) holidays
22


Unfortunately, Christmas Day is a Sunday, so the result is still 22. Some countries observe Christmas Day on Monday, but not Colombia.

Let's add December 8, 2016 (the Feast of the Immaculate Conception) to the set of dates to exclude:

λ> holidays = [Date 2016 12 08, Date 2016 12 25] :: Set Date


And try again:

λ> workdays (Date 2016 12 01) (Date 2016 12 31) holidays
21


The result is now 21, which is the actual number of workdays for December, 2016 in Colombia.