diff --git a/backend/src/data_readers.clj b/backend/src/data_readers.clj index 13c949bc7..e23c1f604 100644 --- a/backend/src/data_readers.clj +++ b/backend/src/data_readers.clj @@ -1,2 +1,3 @@ {uxbox/instant uxbox.util.time/from-string - uxbox/cron uxbox.util.time/cron} + uxbox/cron uxbox.util.time/cron + uxbox/duration uxbox.util.time/parse-duration} diff --git a/backend/src/uxbox/util/time.clj b/backend/src/uxbox/util/time.clj index 4d5ff33a9..1bcc13779 100644 --- a/backend/src/uxbox/util/time.clj +++ b/backend/src/uxbox/util/time.clj @@ -2,7 +2,10 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2016 Andrey Antukh +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2016-2020 Andrey Antukh (ns uxbox.util.time (:require @@ -54,9 +57,21 @@ :else (obj->duration ms-or-obj))) +(defn parse-duration + [s] + (assert (string? s)) + (Duration/parse s)) + (extend-protocol clojure.core/Inst java.time.Duration - (inst-ms* [v] (.toMillis ^java.time.Duration v))) + (inst-ms* [v] (.toMillis ^Duration v))) + +(defmethod print-method Duration + [mv ^java.io.Writer writer] + (.write writer (str "#uxbox/duration \"" (.toString ^Duration mv) "\""))) + +(defmethod print-dup Duration [o w] + (print-method o w)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Cron Expression @@ -206,7 +221,7 @@ (defmethod print-method Instant [mv ^java.io.Writer writer] - (.write writer (str "#instant \"" (.toString ^Instant mv) "\""))) + (.write writer (str "#uxbox/instant \"" (.toString ^Instant mv) "\""))) (defmethod print-dup Instant [o w] (print-method o w)) diff --git a/backend/tests/user.clj b/backend/tests/user.clj index fab2a01dd..f701b4450 100644 --- a/backend/tests/user.clj +++ b/backend/tests/user.clj @@ -21,6 +21,7 @@ [promesa.exec :as px] [uxbox.migrations] [uxbox.util.storage :as st] + [uxbox.util.time :as tm] [mount.core :as mount])) ;; --- Benchmarking Tools