Holi is a Clojure and ClojureScript library for working with non-business days
(ns my-app
(:require [luciolucio.holi :as holi]
[tick.core :as t]))
; July 2019
; Su Mo Tu We Th Fr Sa
; 1 2 3 4 5 6
; 7 8 9 10 11 12 13
; 14 15 16 17 18 19 20
; 21 22 23 24 25 26 27
; 28 29 30 31
(holi/add (t/date "2019-07-12") 3 :business-days) ; 17Jul2020 (skips weekends)
(holi/add (t/date "2019-07-03") 1 :business-days "US") ; 5Jul2019 (skips 4th of July as a US holiday)
(holi/weekend? (t/date "2019-07-06")) ; -> true
(holi/holiday? (t/date "2019-07-04") "US") ; -> true
Use of juxt/tick is not required, but highly recommended.
Import the latest version from clojars into your project dependencies
Holi has been successfully tested when built with shadow-cljs and run on a browser. If you have issues with other setups,
hit me up on clojurians Slack: @Lucio Assis
(add [date n unit & calendars])
Adds n of unit to date and returns a new date. Skips holidays in calendars when unit is :business-days.
| Parameter | Description | Example |
|---|---|---|
date | An instance of java.time.LocalDate or java.time.LocalDateTime | (LocalDate/of 2020 10 9) |
n | An integer | 2, -1, 0 |
unit | Unit of n | :days :weeks :months :years or :business-days |
calendars | One or more strings representing holiday calendars (:business-days only) | "US", "BR" |
LocalDate in will return a LocalDateLocalDateTime instanceunit will accept both :weeks and :week etc. That way you can say 1 :week or 1 :business-day.(weekend? [date])
Returns true if date is in a weekend, and false otherwise
| Parameter | Description | Example |
|---|---|---|
date | An instance of java.time.LocalDate or java.time.LocalDateTime | (LocalDate/of 2020 10 9) |
(holiday? [date calendar])
Returns true if date is a holiday in the given calendar, and false otherwise
| Parameter | Description | Example |
|---|---|---|
date | An instance of java.time.LocalDate or java.time.LocalDateTime | (LocalDate/of 2020 10 9) |
calendar | A string representing a holiday calendar | "US", "BR" |
(non-business-day? [date & calendars])
Returns true only if date is whether in a weekend or a holiday in one of the given calendars. Returns false otherwise.
| Parameter | Description | Example |
|---|---|---|
date | An instance of java.time.LocalDate or java.time.LocalDateTime | (LocalDate/of 2020 10 9) |
calendars | One or more strings representing holiday calendars | "US", "BR" |
(business-day? [date & calendars])
Returns true only if date is not in a weekend and also not a holiday in any of the given calendars. Returns false otherwise.
| Parameter | Description | Example |
|---|---|---|
date | An instance of java.time.LocalDate or java.time.LocalDateTime | (LocalDate/of 2020 10 9) |
calendars | One or more strings representing holiday calendars | "US", "BR" |
Use n = 0 to get same or next semantics, that is:
n = 1(ns my-app
(:require [luciolucio.holi :as holi]
[tick.core :as t]))
(holi/add (t/date "2022-07-06") 0 :business-days) ; -> 8Jul22, because 6Jul22 is a Saturday
(holi/add (t/date "2022-07-07") 0 :business-days) ; -> 8Jul22, because 7Jul22 is a Sunday
(holi/add (t/date "2022-07-08") 0 :business-days) ; -> 8Jul22, as it's a regular Monday
One way this is useful is for things like "This is due next month, on the same day of the month, but if it's a weekend then it's the following business day":
(-> (t/date "2022-06-06")
(holi/add 1 :months) ; 6Jul22, Sat
(holi/add 0 :business-days)) ; 8Jul22, Mon
| Holiday calendar | Description |
|---|---|
| US | United States holidays |
| GB | Great Britain holidays |
| BR | Brazilian holidays |
| brazil/sao-paulo | São Paulo city holidays |
What do I do if a date is wrong or a holiday calendar is missing for <insert location here>?
You have two options:
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |