0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 16:30:37 -05:00

Fix incompatibilities with dateFns dependency.

This commit is contained in:
Andrey Antukh 2021-03-05 15:22:28 +01:00
parent 34c4f23e49
commit 861d5f0064
2 changed files with 37 additions and 35 deletions

View file

@ -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 <niwi@niwi.nz>
;; Copyright (c) 2015-2021 Andrey Antukh <niwi@niwi.nz>
(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)))))

View file

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