diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index f30701ef6..a2d8f4fda 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -154,12 +154,12 @@ [:add-color [:map {:title "AddColorChange"} [:type [:= :add-color]] - [:color :any]]] + [:color ::ctc/color]]] [:mod-color [:map {:title "ModColorChange"} [:type [:= :mod-color]] - [:color :any]]] + [:color ::ctc/color]]] [:del-color [:map {:title "DelColorChange"} diff --git a/common/src/app/common/schema.cljc b/common/src/app/common/schema.cljc index b1e743f64..fcb3f1107 100644 --- a/common/src/app/common/schema.cljc +++ b/common/src/app/common/schema.cljc @@ -619,20 +619,27 @@ {:title "contains" :description "contains predicate"}}))}) -(define! ::inst +(def type:inst {:type ::inst :pred inst? :type-properties {:title "inst" :description "Satisfies Inst protocol" - :error/message "expected to be number in safe range" + :error/message "should be an instant" :gen/gen (->> (sg/small-int) - (sg/fmap (fn [v] (tm/instant v)))) - ::oapi/type "number" - ::oapi/format "int64"}}) + (sg/fmap (fn [v] (tm/parse-instant v)))) -(define! ::fn - [:schema fn?]) + :decode/string tm/parse-instant + :encode/string tm/format-instant + :decode/json tm/parse-instant + :encode/json tm/format-instant + ::oapi/type "string" + ::oapi/format "iso"}}) + +(register! ::inst type:inst) + +(register! ::fn + [:schema fn?]) (define! ::word-string {:type ::word-string diff --git a/common/src/app/common/time.cljc b/common/src/app/common/time.cljc index 6cd8601d6..45e130deb 100644 --- a/common/src/app/common/time.cljc +++ b/common/src/app/common/time.cljc @@ -12,6 +12,7 @@ ["luxon" :as lxn]) :clj (:import + java.time.format.DateTimeFormatter java.time.Instant java.time.Duration))) @@ -26,10 +27,29 @@ #?(:clj (Instant/now) :cljs (.local ^js DateTime))) -(defn instant +(defn instant? + [o] + #?(:clj (instance? Instant o) + :cljs (instance? DateTime o))) + +(defn parse-instant [s] - #?(:clj (Instant/ofEpochMilli s) - :cljs (.fromMillis ^js DateTime s #js {:zone "local" :setZone false}))) + (cond + (instant? s) + s + + (int? s) + #?(:clj (Instant/ofEpochMilli s) + :cljs (.fromMillis ^js DateTime s #js {:zone "local" :setZone false})) + + (string? s) + #?(:clj (Instant/parse s) + :cljs (.fromISO ^js DateTime s)))) + +(defn format-instant + [v] + #?(:clj (.format DateTimeFormatter/ISO_INSTANT ^Instant v) + :cljs (.toISO ^js v))) #?(:cljs (extend-protocol IComparable