# Main utility for the whole application.
(import manisha :prefix "" :export true)
(import bearimy :prefix "" :export true)
(import marble :prefix "" :export true)
(import bearimy/utils :prefix "" :export true)
(import /neil/guides :prefix "" :export true)
(defn fresh
```
Updates timestamp of `what`.
```
[what]
(merge-into what (stamp)))
(defn stamp-ident
```
Timestamps the instance with `uuid`.
```
[brush uuid]
(-> (load brush uuid) fresh))
(defn valid?
```
Checks if the `what` is valid new instance.
```
[what data]
(case what
:task (new-task-appraiser data)
:project (new-project-appraiser data)
:client (new-client-appraiser data)))
(defn sum-intervals
```
Sums all the intervals in `wis`.
```
[wis]
(reduce
(fn [t wi]
(def e (or (wi :end) (os/time)))
(+ t (- e (wi :start))))
0 wis))
(defn stamps
```
Creates the table with all the timestamps used in stats.
```
[]
(def [tts ydts tdats wts lwts twats mts lmts tmats yts lyts]
(map |(:epoch $)
@[;(map |(days-ago $) (range 3))
;(map |(start-of-week (- $)) (range 3))
;(map |(start-of-month (- $)) (range 3))
;(map |(start-of-year (- $)) (range 2))]))
@{:today [tts] :yesterday [ydts tts] :two-days-ago [tdats ydts]
:week [wts] :last-week [lwts wts] :two-weeks-ago [twats lwts]
:month [mts] :last-month [lmts mts] :two-months-ago [tmats lmts]
:year [yts] :last-year [lyts yts]})
(defn work-intervals-sums
```
Sums all intervals, optionaly for `project` and `state`, for usage in stats.
```
[brush &opt project state]
(if (or (not project)
(present? ((load brush project) :tasks)))
(map-vals |(-> (list-worked brush project state ;$)
sum-intervals
format-interval)
(stamps))))
(defn today-time
```
Computes the time spent working today.
```
[brush]
(->> (:epoch (today))
(list-worked brush nil nil)
sum-intervals))
(defmacro conn-fiber
```
Convenience macro for constructing fiber, handling connection,
which is also set as `dyn`
```
[handling]
~(fiber/new
(fn [conn] (setdyn :conn conn) (,handling conn)) :tp))