mirror of
https://github.com/penpot/penpot.git
synced 2026-03-15 06:56:06 +00:00
🐛 Make ct/format-inst nil safe (#8612)
Prevent JS TypeError when date is nil in date formatting. Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
@@ -204,40 +204,41 @@
|
||||
(defn format-inst
|
||||
([v] (format-inst v :iso))
|
||||
([v fmt]
|
||||
(case fmt
|
||||
(:iso :iso8601)
|
||||
#?(:clj (.format DateTimeFormatter/ISO_INSTANT ^Instant v)
|
||||
:cljs (dfn-format-iso v))
|
||||
(when (some? v)
|
||||
(case fmt
|
||||
(:iso :iso8601)
|
||||
#?(:clj (.format DateTimeFormatter/ISO_INSTANT ^Instant v)
|
||||
:cljs (dfn-format-iso v))
|
||||
|
||||
:iso-date
|
||||
#?(:clj (.format DateTimeFormatter/ISO_LOCAL_DATE
|
||||
^ZonedDateTime (ZonedDateTime/ofInstant v (ZoneId/of "UTC")))
|
||||
:cljs (dfn-format-iso v #js {:representation "date"}))
|
||||
:iso-date
|
||||
#?(:clj (.format DateTimeFormatter/ISO_LOCAL_DATE
|
||||
^ZonedDateTime (ZonedDateTime/ofInstant v (ZoneId/of "UTC")))
|
||||
:cljs (dfn-format-iso v #js {:representation "date"}))
|
||||
|
||||
(:rfc1123 :http)
|
||||
#?(:clj (.format DateTimeFormatter/RFC_1123_DATE_TIME
|
||||
^ZonedDateTime (ZonedDateTime/ofInstant v (ZoneId/of "UTC")))
|
||||
:cljs (dfn-format v "EEE, dd LLL yyyy HH:mm:ss 'GMT'"))
|
||||
(:rfc1123 :http)
|
||||
#?(:clj (.format DateTimeFormatter/RFC_1123_DATE_TIME
|
||||
^ZonedDateTime (ZonedDateTime/ofInstant v (ZoneId/of "UTC")))
|
||||
:cljs (dfn-format v "EEE, dd LLL yyyy HH:mm:ss 'GMT'"))
|
||||
|
||||
#?@(:cljs [:time-24-simple
|
||||
(dfn-format v "HH:mm")
|
||||
#?@(:cljs [:time-24-simple
|
||||
(dfn-format v "HH:mm")
|
||||
|
||||
;; DEPRECATED
|
||||
:date-full
|
||||
(dfn-format v "PPP")
|
||||
;; DEPRECATED
|
||||
:date-full
|
||||
(dfn-format v "PPP")
|
||||
|
||||
:localized-date
|
||||
(dfn-format v "PPP")
|
||||
:localized-date
|
||||
(dfn-format v "PPP")
|
||||
|
||||
:localized-time
|
||||
(dfn-format v "p")
|
||||
:localized-time
|
||||
(dfn-format v "p")
|
||||
|
||||
:localized-date-time
|
||||
(dfn-format v "PPP . p")
|
||||
:localized-date-time
|
||||
(dfn-format v "PPP . p")
|
||||
|
||||
(if (string? fmt)
|
||||
(dfn-format v fmt)
|
||||
(throw (js/Error. "unpexted format")))]))))
|
||||
(if (string? fmt)
|
||||
(dfn-format v fmt)
|
||||
(throw (js/Error. "unpexted format")))])))))
|
||||
|
||||
#?(:cljs
|
||||
(def locales
|
||||
|
||||
@@ -137,16 +137,16 @@
|
||||
(ptk/reify ::pin-version
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [version (->> (dm/get-in state [:workspace-versions :data])
|
||||
(d/seek #(= (:id %) id)))
|
||||
params {:id id
|
||||
:label (ct/format-inst (:created-at version) :localized-date)}]
|
||||
(when-let [version (->> (dm/get-in state [:workspace-versions :data])
|
||||
(d/seek #(= (:id %) id)))]
|
||||
(let [params {:id id
|
||||
:label (ct/format-inst (:created-at version) :localized-date)}]
|
||||
|
||||
(->> (rp/cmd! :update-file-snapshot params)
|
||||
(rx/mapcat (fn [_]
|
||||
(rx/of (update-versions-state {:editing id})
|
||||
(fetch-versions)
|
||||
(ptk/event ::ev/event {::ev/name "pin-version"})))))))))
|
||||
(->> (rp/cmd! :update-file-snapshot params)
|
||||
(rx/mapcat (fn [_]
|
||||
(rx/of (update-versions-state {:editing id})
|
||||
(fetch-versions)
|
||||
(ptk/event ::ev/event {::ev/name "pin-version"}))))))))))
|
||||
|
||||
(defn lock-version
|
||||
[id]
|
||||
|
||||
Reference in New Issue
Block a user