   "zero pad timepicker digits"
   (goog.string/format "%02d" num))
 
-(defn get-hours []
-  (.getHours @selected-time))
-
-(defn get-minutes []
-  (.getMinutes @selected-time))
-
-(defn set-hours! [new-hours]
-  (swap! selected-time #(doto % (.setHours new-hours))))
-
-(defn set-minutes! [new-mins]
-  (swap! selected-time #(doto % (.setMinutes new-mins))))
+(defn minutes-to-ms [mins]
+  (* mins 60000))
+
+(defn hours-to-ms [hours]
+  (* hours 3600000))
 
 (defn sync-time-with-snapshot! []
-  (reset! selected-time (js/Date. (:time (@snapshot-list @snapshot-index)))))
+  (reset! selected-time (:time (@snapshot-list @snapshot-index))))
 
 ; TODO: This could be improved. Probably need to rethink my data model
 (defn show-closest-snapshot! []
-  (let [timestamp (.getTime @selected-time)
+  (let [timestamp @selected-time
         earlier-index (first (keep-indexed #(if (>= timestamp (:time %2)) %1) @snapshot-list))
         later-index (max (dec earlier-index) 0)
         later (:time (@snapshot-list later-index))

    (reset! selected-time (.-time e))))

(defn on-datetime-change []
  (let [date (.datepicker ($ "#datepicker") "getDate")
        new-time (doto date
                    (.setMinutes (.getMinutes @selected-time))
                    (.setHours (.getHours @selected-time)))]
    (reset! selected-time new-time)))

(defn click-toggle-meridian []
  (let [hours (+ (get-hours) 12)
        hours (if (>= 24 ) (- 24 hours) hours)]
    (set-hours! hours)
    (show-closest-snapshot!)))

(defn click-decrement-hour []
  (set-hours! (dec (get-hours)))
  (show-closest-snapshot!))

(defn click-increment-hour []
  (set-hours! (inc (get-hours)))
  (show-closest-snapshot!))

(defn click-decrement-Minute []
  (set-minutes! (dec (get-minutes)))
  (show-closest-snapshot!))

(defn click-increment-minute []
  (set-minutes! (inc (get-minutes)))
  (show-closest-snapshot!))

(defn click-later []

    (reset! snapshot-index display-index)))

(defn set-url! [timestamp]
  (let [base-url (first (.split js/document.URL "?"))
        new-url (str base-url "?time=" timestamp)]
    (.replaceState js/history nil nil new-url)))

