Code Monkey home page Code Monkey logo

kairos's Introduction

org.pilosus/kairos

Clojars Project codecov

Crontab parsing library for Clojure.

  • Supports vixie-cron syntax
  • Parses a crontab entry into a lazy sequence of java.time.ZonedDateTime objects in UTC timezone
  • Explains a crontab entry in plain English

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

Install

Clojars Project

Usage

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

;; 1. Generate a sequence of Date Time objects for a given crontab entry
(kairos/cron->dt "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. Explain a crontab enrty in plain English
(kairos/cron->text "0 6,10-18/2,22 * * Mon-Fri")

;; at minute 0, past hour 6, every 2nd hour from 10 through 18, hour 22, on every day of week from Monday through Friday, in every month

License

See LICENSE.

kairos's People

Contributors

pilosus avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

kairos's Issues

[FEATURE] Proper values validation

Is your feature request related to a problem? Please describe.
For now there's no explicit validation for values. Meaning that something like this will work just fine:

(take 10 (cron->dt "10-67 9 * * *"))

Invalid values (minutes 60 to 67) will be ignored.

Same works for:

  • cron->text
  • cron->map

Describe the solution you'd like
I think we need to:

  1. Fail fast at the moment when string values are parsed, not at the moment of generating
  2. Apply validation to all entrypoint functions
  3. Have a separate function for cron validation, e.g. (cron-valid? [s])

[BUG] Invalid crontab format may throw NPE in `cron-validate`

Reproduce:

> (cron-validate "Mon-Fri)
Execution error (NullPointerException) at java.util.regex.Matcher/getTextLength (Matcher.java:1770).
Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null

We need to catch base exception to handle the case

[Feature] Human readable text that explains a given crontab string

It would be cool to generate a string explaining in English a given crontab, e.g.

  1. */10 * * 1-6 Mon-Fri => at every 10th minute past every hour on every day of week from Monday through Friday in every month from January through June
  2. 0,15,30 9,12,21 */5 * * => at minute 0, 15, 30 past hour 9, 12, 21 on every 5th day of month
  3. 0,7,15,*/12,*/14,57-59 * * * * => at minute 0, 7, 15, every 12th minute, every 14th minute, and every minute from 57 through 59
  4. * * 1,3-7,*/10 * 1,2,*/3,5-7 => at every minute past every hour on day of month 1, every day of month from 3 through 7, and every 10th day of month or on Monday, Tuesday, every 3rd day of week, and every day of week from Friday through Sunday

So, the format is roughly:

at [concrete value(s), range(s), frequency(ies)][minute] 
past [concrete value(s), range(s), frequency(ies)][hour] 
on [concrete value(s), range(s), frequency(ies)][day of month] or [concrete value(s), range(s), frequency(ies) [day of week]
in [concrete value(s), range(s), frequency(ies)][month]

Values concatenations:

  • concrete values a,b,c,d => a, b, c, d
  • ranges 1-5 => from 1 though 5; Mon-Fri => from Monday through Friday
  • frequencies */5 => every 5th

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.