switching to use real dates.

This commit is contained in:
Bryce Covert
2018-04-12 22:33:57 -07:00
parent e1e0835bee
commit 056bfc38a4
8 changed files with 64 additions and 19 deletions

View File

@@ -4,6 +4,7 @@
[cljs-http.client :as http]
[cljs-time.coerce :as c]
[cljs-time.core :as time]
[cljs-time.format :as format]
[cljs.core.async :refer [<!]]
[clojure.string :as str]
[clojure.walk :as walk]
@@ -23,16 +24,25 @@
(if value
(.setItem js/localStorage name value)
(.removeItem js/localStorage name ))))
(def is-8601 #"^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$")
(defn dates->date-times [x]
(cond (map? x)
(into {} (map (fn [[k v]]
[k (if (instance? js/Date v)
(time/to-default-time-zone (c/from-date v))
v)])
x))
(list? x)
(map dates->date-times x)))
(walk/postwalk
(fn [node]
(cond
(and (string? node)
(re-matches is-8601 node))
(do
(format/parse (format/formatters :date-time) node))
(instance? js/Date node)
(time/to-default-time-zone (c/from-date node))
:else
node))
x))
(re-frame/reg-fx
:http
@@ -74,6 +84,7 @@
(keyword? node)
(snake node)
:else
node))
m))