Files
integreat/src/clj/auto_ap/time.clj
2020-06-19 10:05:55 -07:00

31 lines
815 B
Clojure

(ns auto-ap.time
(:require [clj-time.core :as time]
[clj-time.format :as f]))
(defn local-now []
(time/to-time-zone (time/now) (time/time-zone-for-id "America/Los_Angeles")))
(def normal-date "MM/dd/yyyy")
(def iso-date "yyyy-MM-dd")
(defn parse [v format]
(try
(time/from-time-zone (f/parse (f/formatter format) v)
(time/time-zone-for-id "America/Los_Angeles"))
(catch Exception e
nil)))
(defn unparse [v format]
(try
(f/unparse (f/formatter format) v)
(catch Exception e
nil)))
(defn day-of-week-seq [day]
(let [next-day (loop [d (local-now)]
(if (= (time/day-of-week d) day)
d
(recur (time/plus d (time/days 1)))))]
(iterate #(time/plus % (time/days 7)) next-day)))