Created
May 21, 2012 20:51
-
-
Save adeel/2764601 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 []))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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