Skip to content

Instantly share code, notes, and snippets.

@adeel
Created May 21, 2012 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeel/2764601 to your computer and use it in GitHub Desktop.
Save adeel/2764601 to your computer and use it in GitHub Desktop.
(ns stopwatch.logger
(:use [clojure.string :only (split-lines)]
[stopwatch.util :only (get-log-path)])
(:require [cljs.nodejs :as node]))
(def fs (node/require "fs"))
(def moment (node/require "moment"))
(defn- parse-datetime [date]
(.toDate (moment date "HH:mm \\o\\n DD.MM.YYYY")))
(defn- parse-record [r]
(let [[_ project start end] (re-find #"([^\:]+)\:\s*(.+) \- (.+)" r)]
{:project project
:start (parse-datetime start)
:end (parse-datetime end)}))
(defn read
([]
(read (get-log-path)))
([filename]
(try
(map parse-record (split-lines (.readFileSync fs filename "utf-8"))))
(catch e [])))
(ns stopwatch.util
(:require [cljs.nodejs :as node]))
(defn get-log-path []
(.-STOPWATCH_LOG_PATH (.-env (js->clj node/process))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment