 
 (defn render-card-sparkline
   [card {:keys [rows cols] :as data} render-img]
-  (let [xs (map #(-> % first .getTime) rows)
+  (let [xs (for [row rows :let [x (first row)]] (if (instance? java.util.Date x) (.getTime x) x))
         xmin (apply min xs)
         xmax (apply max xs)
         xrange (- xmax xmin)

          [:tr {:style (str "color: " (if (odd? row-idx) color-grey-2 color-grey-3) ";")}
            (map (fn [col-idx]
                  [:td {:style (str bar-td-style (if (and bar-column (= col-idx 1)) "font-weight: 700;"))}
                    (-> row (nth col-idx) format-cell h)])
                  col-indexes)
            (if bar-column [:td {:style (str bar-td-style "width: 99%;")}
              [:div {:style (str "background-color: " color-purple "; height: 20px; width: " (float (* 100 (/ (bar-column row) max-value))) "%")} "&#160;"]])])

    :else (str (cl-format nil "~,1f" n))))

(defn- format-timestamp
  [timestamp col]
  (log/info timestamp)
  (case (:unit col)
    :hour (f/unparse (f/formatter "h a - MMM YYYY") (c/from-long timestamp))
    :week (f/unparse (f/formatter "w - YYYY") (c/from-long timestamp))
    :month (f/unparse (f/formatter "MMMM YYYY") (c/from-long timestamp))
    :quarter (str "Q" (+ 1 (int (/ (t/month (c/from-long timestamp)) 3))) " - " (t/year (c/from-long timestamp)))
    :year (str timestamp)
    :hour-of-day (str timestamp) ; TODO: probably shouldn't even be showing sparkline for x-of-y groupings?
    :day-of-week (str timestamp)
    :week-of-year (str timestamp)
    :month-of-year (str timestamp)
    (let [date (c/from-long timestamp)
          today (t/today-at 0 00)]
      (cond
        (t/within? (t/interval today (t/plus today (t/days 1))) date) "Today"
        (t/within? (t/interval (t/minus today (t/days 1)) today) date) "Yesterday"
        :else (f/unparse (f/formatter "MMM d, YYYY") date)))))

(defn- format-cell
  [value col]
  (log/info value)
  (cond
    (instance? java.util.Date value) (format-timestamp (.getTime value) col)
    (and (number? value) (not (datetime-field? col))) (format-number value)
    :else (str value)))

(defn card-href
