From 34071ab7dc14203516116a1a18e44baa55a7bf1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=BCrgin?= Date: Fri, 11 May 2018 18:52:46 +0200 Subject: [PATCH] Extend Inst to org.joda.time.ReadableInstant on Clojure 1.9 (#248) (#249) --- src/clj_time/core.clj | 10 ++++++++++ test_clj_1.9/clj_time/inst_test.clj | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test_clj_1.9/clj_time/inst_test.clj diff --git a/src/clj_time/core.clj b/src/clj_time/core.clj index 24734b2..d76540e 100644 --- a/src/clj_time/core.clj +++ b/src/clj_time/core.clj @@ -781,3 +781,13 @@ (concat (take-while (partial not= dt-fn) dt-fns) [dt-fn]) (repeat [dt]))) tz)))) + +(defmacro ^:private when-available [sym & body] + (when (resolve sym) + `(do ~@body))) + +(when-available Inst + (extend-protocol Inst + org.joda.time.ReadableInstant + (inst-ms* [inst] + (.getMillis inst)))) diff --git a/test_clj_1.9/clj_time/inst_test.clj b/test_clj_1.9/clj_time/inst_test.clj new file mode 100644 index 0000000..058f188 --- /dev/null +++ b/test_clj_1.9/clj_time/inst_test.clj @@ -0,0 +1,10 @@ +(ns clj-time.inst-test + (:refer-clojure :exclude [extend second]) + (:require [clojure.test :refer :all] + [clj-time.core :refer :all]) + (:import org.joda.time.DateTime)) + +(deftest test-inst + (let [^DateTime n (now)] + (is (inst? n)) + (is (= (inst-ms n) (.getMillis n)))))