Skip to content

cljam-date

npm

Date handling for cljam. Construction, accessors, arithmetic, and formatting via cljam.date.

Installation

bash
npm install @regibyte/cljam-date
typescript
import { library as dateLib } from '@regibyte/cljam-date'

const session = createSession({ ...nodePreset(), libraries: [dateLib] })

Usage

clojure
(require '[cljam.date :as d])

;; Construction
(def now     (d/now))
(def past    (d/from-millis 0))
(def release (d/from-iso "2026-04-11T00:00:00Z"))

;; Accessors
(d/year now)    ;; => 2026
(d/month now)   ;; => 4   (1-indexed, January = 1)
(d/day now)     ;; => 14
(d/hour now)    ;; => 23

;; Serialization
(d/to-iso now)    ;; => "2026-04-14T23:00:00.000Z"
(d/to-millis now) ;; => 1744671600000

;; Arithmetic
(d/add-days now 7)       ;; => date 7 days from now
(d/add-hours now 3)      ;; => date 3 hours from now
(d/diff-days past now)   ;; => whole days between past and now

;; Formatting (wraps Intl.DateTimeFormat)
(d/format now)                             ;; system locale, default options
(d/format now "en-US")
(d/format now "de-DE" {:year "numeric" :month "long" :day "numeric"})
;; => "14. April 2026"

API

FunctionSignatureDescription
now() → dateCurrent instant
from-millis(ms) → dateFrom epoch milliseconds
from-iso(s) → dateFrom ISO 8601 string
to-millis(d) → numberEpoch milliseconds
to-iso(d) → stringISO 8601 string
year(d) → numberFull year
month(d) → numberMonth, 1-indexed (Jan = 1)
day(d) → numberDay of month (1–31)
hour(d) → numberHours (0–23)
minute(d) → numberMinutes (0–59)
second(d) → numberSeconds (0–59)
format(d), (d locale), (d locale opts) → stringFormat via Intl.DateTimeFormat
add-days(d n) → dateAdd n days
add-hours(d n) → dateAdd n hours
diff-days(a b) → numberWhole days between a and b

Built with ❤️ for Clojure and its ideas, by RegiByte.