workdays: Workday calculations

[ library, mit, time ] [ Propose Tags ] [ Report a vulnerability ]

Workday calculations. Please see the README.md file.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.1.1
Dependencies base (>=4.7 && <5), containers, time [details]
License MIT
Copyright 2016 Stack Builders
Author Juan Pedro Villa Isaza
Maintainer hackage@stackbuilders.com
Category Time
Home page https://github.com/stackbuilders/workdays
Bug tracker https://github.com/stackbuilders/workdays/issues
Source repo head: git clone https://github.com/stackbuilders/workdays
Uploaded by jpvillaisaza at 2016-11-17T16:37:56Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1517 total (1 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-11-17 [all 1 reports]

Readme for workdays-0.1.1

[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.

License

Licensed under the MIT License.