Skip to content

Commit

Permalink
Extend Inst to org.joda.time.ReadableInstant on Clojure 1.9 (#248) (#249
Browse files Browse the repository at this point in the history
)
  • Loading branch information
glts authored and seancorfield committed May 11, 2018
1 parent 6bb1a05 commit 34071ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/clj_time/core.clj
Expand Up @@ -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))))
10 changes: 10 additions & 0 deletions 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)))))

0 comments on commit 34071ab

Please sign in to comment.