23 lines
942 B
Clojure
23 lines
942 B
Clojure
(ns auto-ap.time-utils
|
|
(:require #?(:clj [clj-time.core :as time]
|
|
:cljs [cljs-time.core :as time])
|
|
#?(:cljs [cljs-time.format :as format]
|
|
:clj [clj-time.format :as format])))
|
|
|
|
(def pretty (format/formatter "MM/dd/yyyy"))
|
|
|
|
(defn user-friendly-date [d]
|
|
(some->> d (format/unparse pretty)))
|
|
|
|
(defn next-dom [date dom]
|
|
(when date
|
|
(let [candidate (time/date-time (time/year date) (time/month date)
|
|
#?(:clj (Math/min (int dom)
|
|
(time/day (time/last-day-of-the-month (time/year date) (time/month date))))
|
|
:cljs (Math/min dom
|
|
(time/day (time/last-day-of-the-month (time/year date) (time/month date))))))]
|
|
|
|
(if (time/before? candidate date)
|
|
(time/plus candidate (time/months 1))
|
|
candidate))))
|