Liking cljdoc? Tell your friends :D

Tips and tricks

"Same or next" business day

Use n = 0 to get same or next semantics, that is:

  • If the date is a business day already, just return the same date
  • Otherwise it's as if you had used n = 1
(ns my-app
  (:require [luciolucio.holi :as holi]
    [tick.core :as t]))

(holi/add (t/date "2022-07-06") 0 :business-days) ; -> 2022-07-08, because 2022-07-06 is a Saturday
(holi/add (t/date "2022-07-07") 0 :business-days) ; -> 2022-07-08, because 2022-07-07 is a Sunday
(holi/add (t/date "2022-07-08") 0 :business-days) ; -> 2022-07-08, as it's a regular Monday

One situation where this is useful is, say, when something is "due next month, on the same day of the month, but in case that's a weekend then it's only due the following business day":

(-> (t/date "2022-06-06")
    (holi/add 1 :months)         ; 2022-07-06, Sat
    (holi/add 0 :business-days)) ; 2022-07-08, Mon

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close