🐛 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:
Andrey Antukh
2026-03-12 19:55:51 +01:00
committed by GitHub
parent 25df9f2f83
commit e7e6303184
2 changed files with 36 additions and 35 deletions

View File

@@ -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

View File

@@ -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]