Ep 018: Did I Work Late on Tuesday?

Play Episode

Christoph wants to teach filter some vocabulary.

Related episodes:

Clojure in this episode:

Code sample from this episode:

(ns time.week-04
  (:require
    [time.week-03 :as week-03]
    [java-time :as jt]))


; Helper for loading up time entries

(defn log-times
  [filename]
  (->> (week-03/lines filename)
       (week-03/times)))


; Extractors

(defn day-of-week
  [entry]
  (jt/day-of-week (-> entry :date)))


; Predicates

(defn spans-midnight?
  [entry]
  (not= (jt/local-date (:start entry)) (jt/local-date (:end entry))))

(defn day-of-week?
  [day entry]
  (= (day-of-week entry) (jt/day-of-week day)))

(defn weekend?
  [entry]
  (or (day-of-week? :saturday entry)
      (day-of-week? :sunday entry)))

(defn weekday?
  [entry]
  (not (weekend? entry)))


; Aggregations

(defn total-minutes
  [entries]
  (->> entries
       (map :minutes)
       (reduce +)))


(comment
  (->> (log-times "time-log.txt")
       (filter spans-midnight?))
  (->> (log-times "time-log.txt")
       (filter (partial day-of-week? :wednesday)))
  (->> (log-times "time-log.txt")
       (filter weekend?))
  (->> (log-times "time-log.txt")
       (filter weekday?)
       (total-minutes))
  )