From 861d5f00641a770e2f0ab1f0ade24d53d75c1cb5 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 5 Mar 2021 15:22:28 +0100 Subject: [PATCH] :sparkles: Fix incompatibilities with dateFns dependency. --- frontend/src/app/util/time.cljs | 60 +++++++++++++++--------------- frontend/src/app/util/transit.cljs | 12 +++--- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/frontend/src/app/util/time.cljs b/frontend/src/app/util/time.cljs index 5fd7a0b7f..13e87c19c 100644 --- a/frontend/src/app/util/time.cljs +++ b/frontend/src/app/util/time.cljs @@ -5,49 +5,51 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2015-2020 Andrey Antukh +;; Copyright (c) 2015-2021 Andrey Antukh (ns app.util.time (:require - ["date-fns/format" :default df-format] - ["date-fns/formatDistanceToNow" :default df-format-distance] - ["date-fns/formatDistanceToNowStrict" :default df-format-distance-strict] - ["date-fns/locale/fr" :default df-fr-locale] - ["date-fns/locale/en-US" :default df-en-locale] - ["date-fns/locale/es" :default df-es-locale] - ["date-fns/locale/ru" :default df-ru-locale] - [goog.object :as gobj])) - + ["date-fns/parseISO" :as dateFnsParseISO] + ["date-fns/formatISO" :as dateFnsFormatISO] + ["date-fns/format" :as dateFnsFormat] + ["date-fns/formatDistanceToNowStrict" :as dateFnsFormatDistanceToNowStrict] + ["date-fns/locale/fr" :as dateFnsLocalesFr] + ["date-fns/locale/en-US" :as dateFnsLocalesEnUs] + ["date-fns/locale/zh-CN" :as dateFnsLocalesZhCn] + ["date-fns/locale/es" :as dateFnsLocalesEs] + ["date-fns/locale/ru" :as dateFnsLocalesRu] + [app.util.object :as obj])) (def ^:private locales - #js {:default df-en-locale - :en df-en-locale - :en_US df-en-locale - :fr df-fr-locale - :fr_FR df-fr-locale - :es df-es-locale - :es_ES df-es-locale - :ru df-ru-locale - :ru_RU df-ru-locale}) + #js {:en dateFnsLocalesEnUs + :fr dateFnsLocalesFr + :es dateFnsLocalesEs + :ru dateFnsLocalesRu + :zh_cn dateFnsLocalesZhCn}) (defn now "Return the current Instant." [] (js/Date.)) +(defn parse + [v] + (^js dateFnsParseISO v)) + +(defn format-iso + [v] + (^js dateFnsFormatISO v)) + (defn format ([v fmt] (format v fmt nil)) - ([v fmt {:keys [locale] - :or {locale "default"}}] - (df-format v fmt #js {:locale (gobj/get locales locale)}))) + ([v fmt {:keys [locale] :or {locale "en"}}] + (dateFnsFormat v fmt #js {:locale (obj/get locales locale)}))) (defn timeago ([v] (timeago v nil)) - ([v {:keys [seconds? locale] - :or {seconds? true - locale "default"}}] + ([v {:keys [locale] :or {locale "en"}}] (when v - (df-format-distance-strict v - #js {:includeSeconds seconds? - :addSuffix true - :locale (gobj/get locales locale)})))) + (->> #js {:includeSeconds true + :addSuffix true + :locale (obj/get locales locale)} + (dateFnsFormatDistanceToNowStrict v))))) diff --git a/frontend/src/app/util/transit.cljs b/frontend/src/app/util/transit.cljs index 4b63be68b..4187ae82b 100644 --- a/frontend/src/app/util/transit.cljs +++ b/frontend/src/app/util/transit.cljs @@ -5,7 +5,7 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2020 UXBOX Labs SL +;; Copyright (c) 2020-2021 UXBOX Labs SL (ns app.util.transit "A lightweight abstraction for transit serialization." @@ -73,12 +73,12 @@ ;; --- Transit Handlers (def ^:privare +read-handlers+ - {"u" uuid - "n" bigint-read-handler + {"u" uuid + "n" bigint-read-handler "ordered-set" ordered-set-read-handler - "jsonblob" blob-read-handler - "matrix" matrix-read-handler - "point" point-read-handler}) + "jsonblob" blob-read-handler + "matrix" matrix-read-handler + "point" point-read-handler}) (def ^:privare +write-handlers+ {gmt/Matrix matrix-write-handler