MyNixOS website logo
Description

Workday calculations.

Workday calculations. Please see the README.md file.

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.

Metadata

Version

0.1.1

License

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows