Liking cljdoc? Tell your friends :D

org.pilosus/kairos

Clojars Project codecov

Crontab parsing library for Clojure.

Supports vixie-cron syntax. Generates a lazy sequence of java.time.ZonedDateTime objects in UTC timezone that satisfy given crontab constraints.

Kairos (καιρός) means the right, critical, or opportune moment.

Install

Clojars Project

Usage

(require '[org.pilosus.kairos :as kairos])

;; 1. Generate a lazy sequence of java.time.ZonedDateTime[UTC] objects
;; that satisfy given crontab constraints:
(kairos/get-dt-seq "0 10 3,7 Dec Mon")

;; (#object[java.time.ZonedDateTime 0x55eb9b05 "2023-12-03T10:00Z[UTC]"]
;;  #object[java.time.ZonedDateTime 0x2ed291ba "2023-12-04T10:00Z[UTC]"]
;;  ...
;;  #object[java.time.ZonedDateTime 0x749adbda "2024-12-30T10:00Z[UTC]"])

;; 2. Generate a Date-Time sequence for a range of years,
;; from start (inclusive) to end (exclusive):
(kairos/get-dt-seq "0 10 3,7 Dec Mon" 2030 2032)

;; ("2030-12-02T10:00Z[UTC]"
;;  "2030-12-03T10:00Z[UTC]"
;;   ...
;;  "2031-12-29T10:00Z[UTC]")

;; 3. Parse crontab string into a map:
(kairos/parse-cron "12,14,17,35-45/3 */2 27 Feb-Jun *")

;; {:minute (12 14 17 35 38 41 44),
;;  :hour (0 2 4 6 8 10 12 14 16 18 20 22),
;;  :day-of-month (27),
;;  :month (2 3 4 5 6),
;;  :day-of-week ()}

License

See LICENSE

Can you improve this documentation?Edit on GitHub

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

× close