-
Notifications
You must be signed in to change notification settings - Fork 10
/
time.clj
48 lines (40 loc) · 1.65 KB
/
time.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(ns leiningen.polylith.time
(:require [clojure.pprint :as pp]
[leiningen.polylith.file :as file])
(:import (java.io FileNotFoundException)
(java.util Date)
(java.text SimpleDateFormat)))
(defn time-bookmarks [ws-path]
(try
(read-string (slurp (str ws-path "/.polylith/time.edn")))
(catch FileNotFoundException _ {})))
(defn last-successful-build-time [ws-path]
(or (:last-successful-build (time-bookmarks ws-path))
0))
(defn set-last-successful-build! [ws-path]
(let [paths (file/valid-paths ws-path)
latest-change (file/latest-modified paths)
bookmarks (assoc (time-bookmarks ws-path)
:last-successful-build latest-change)
file (str ws-path "/.polylith/time.edn")]
(pp/pprint bookmarks (clojure.java.io/writer file))))
(def formatter (SimpleDateFormat. "yyyy-MM-dd HH:mm:ss"))
(defn ->time [timestamp]
(.format formatter (Date. timestamp)))
(defn parse-timestamp [bookmark-or-point-in-time]
(try
[true (Long/parseLong bookmark-or-point-in-time)]
(catch Exception _ [false])))
(defn parse-time-argument [ws-path bookmark-or-point-in-time]
(let [[ok? timestamp] (parse-timestamp bookmark-or-point-in-time)]
(if ok?
timestamp
(let [bookmarks (time-bookmarks ws-path)
bookmark (keyword bookmark-or-point-in-time)
point-in-time (bookmarks bookmark)]
(or point-in-time 0)))))
(defn parse-time-args [ws-path [bookmark-or-point-in-time]]
(let [time (if bookmark-or-point-in-time
(parse-time-argument ws-path bookmark-or-point-in-time)
(last-successful-build-time ws-path))]
time))