Liking cljdoc? Tell your friends :D

Periods

A small time-period (e.g. 4 months, 3 hours, 2 minutes) library for easy conversion and normalization. Not meant to work on date-times. I repeat, this is not a date-time library.

Installation

Clojars Project

Usage

From this point forward, it is assumed that your require statement looks like this

(require '[periods.core :as periods])

Periods are just maps.

{:hours 25}

The keys are unabbreviated and plural.

(def period-units
  [:years :months :days :hours :minutes :seconds :milliseconds])

Normalize periods to be proper.

(periods/normalize {:hours 25}) ;; => {:days 1, :hours 1}

Want to convert some period into a single period?

(periods/period->mono-period {:years 2 :days 40} :minutes) ;; => {:minutes 1109520}

365.25 days a year

(periods/normalize-milliseconds {:milliseconds 66571200000}) ;; => {:years 2, :months 1, :days 9, :hours 13, :minutes 30}

Can you improve this documentation?Edit on GitHub

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

× close