Giter Site home page Giter Site logo

mn-dimension / calenjars Goto Github PK

View Code? Open in Web Editor NEW

This project forked from piposaude/calenjars

0.0 0.0 0.0 124 KB

A clojure jar generator to create libraries for date arithmetics around non-business days

License: MIT License

Shell 5.38% Clojure 94.62%

calenjars's Introduction

Calenjars

build Clojars Project

Calenjars is a clojure jar generator, designed to create libraries for date arithmetics around non-business days, that you define yourself with a simple DSL.

Usage

Create a new clojure deps project:

curl -LO https://raw.githubusercontent.com/piposaude/calenjars/0.5.0/new-calenjars-project.sh
bash new-calenjars-project.sh

Next, follow the instructions in the README of the generated project to create your holiday calendar definition files and generate your jar

When you import the generated jar as a dependency in your project, you'll be able to do things like:

(ns my-awesome-app
  (:require [my.generated.lib.calendar :refer [relative-date-add]]))

(relative-date-add (LocalDate/of 2020 10 9) 3 :business-days) ; -> 14Oct2020. Skips weekends.

(relative-date-add (LocalDate/of 2020 10 9) 3 :business-days "YOUR-CAL") ; Will skip weekends and any holidays defined by YOUR-CAL

It goes backwards too (this time with juxt/tick):

(ns my-awesome-app
  (:require [my.generated.lib.calendar :refer [relative-date-add]]
            [tick.core :as t]))

(relative-date-add (t/date "2020-10-12") -3 :business-days) ; -> 7Oct2020

Use "zero" business days for getting the next business day:

(ns my-awesome-app
  (:require [my.generated.lib.calendar :refer [relative-date-add]]))

(relative-date-add (LocalDate/of 2020 8 1) 0 :business-days) ; -> 3Aug20, because 1Aug20 is a Saturday
(relative-date-add (LocalDate/of 2020 8 2) 0 :business-days) ; -> 3Aug20, because 2Aug20 is a Sunday
(relative-date-add (LocalDate/of 2020 8 3) 0 :business-days) ; -> 3Aug20, as it's a regular Monday

Also check individual dates:

(ns my-awesome-app
  (:require [my.generated.lib.calendar :refer [weekend? holiday? non-business-day? business-day?]]
            [tick.core :as t]))

(holiday? (t/date "2020-10-12") "BR") ; -> true
(holiday? (t/date "2020-10-11") "BR") ; -> false
(weekend? (t/date "2020-10-12")) ; -> false
(weekend? (t/date "2020-10-11")) ; -> true
(business-day? (t/date "2020-10-12")) ; -> true
(business-day? (t/date "2020-10-12") "BR") ; -> false
(business-day? (t/date "2020-10-11")) ; -> false
(business-day? (t/date "2020-10-11") "BR") ; -> false
(non-business-day? (t/date "2020-10-12")) ; -> false
(non-business-day? (t/date "2020-10-12") "BR") ; -> true
(non-business-day? (t/date "2020-10-11")) ; -> true
(non-business-day? (t/date "2020-10-11") "BR") ; -> true

calenjars's People

Contributors

luciolucio avatar

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.