Merge pull request #61 from timgluz/local_date
Added support for LocalDate - required for serializing clj-time/today objects.
This commit is contained in:
commit
7890c94496
2 changed files with 19 additions and 2 deletions
|
|
@ -26,6 +26,9 @@
|
|||
(extend-protocol ConvertToDBObject
|
||||
org.joda.time.base.AbstractInstant
|
||||
(to-db-object [^AbstractInstant input]
|
||||
(to-db-object (.toDate input)))
|
||||
org.joda.time.base.AbstractPartial
|
||||
(to-db-object [^AbstractPartial input]
|
||||
(to-db-object (.toDate input))))
|
||||
|
||||
(extend-protocol ConvertFromDBObject
|
||||
|
|
@ -56,6 +59,10 @@
|
|||
(print-dup (.toDate d) out))
|
||||
|
||||
|
||||
(defmethod print-dup org.joda.time.base.AbstractPartial
|
||||
[^org.joda.time.base.AbstractPartial d out]
|
||||
(print-dup (.toDate d) out))
|
||||
|
||||
;;
|
||||
;; JSON serialization
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
(ns monger.test.lib-integration-test
|
||||
(:use clojure.test
|
||||
monger.conversion)
|
||||
(:import [org.joda.time DateTime DateMidnight]
|
||||
(:import [org.joda.time DateTime DateMidnight LocalDate]
|
||||
org.bson.types.ObjectId
|
||||
com.mongodb.DBObject)
|
||||
(:require monger.json
|
||||
|
|
@ -31,6 +31,12 @@
|
|||
(is (instance? java.util.Date d))
|
||||
(is (= 1318464000000 (.getTime ^java.util.Date d)))))
|
||||
|
||||
(deftest ^{:integration true} conversion-of-joda-localdate-to-db-object
|
||||
(let [d (to-db-object (LocalDate. 2011 10 13))]
|
||||
(is (instance? java.util.Date d))
|
||||
(is (= 111 (.getYear ^java.util.Date d))) ;; how many years since 1900
|
||||
(is (= 9 (.getMonth ^java.util.Date d))) ;; java.util.Date counts from 0
|
||||
(is (= 13 (.getDate ^java.util.Date d)))))
|
||||
|
||||
(deftest ^{:integration true} conversion-of-java-util-date-to-joda-datetime
|
||||
(let [input (.toDate ^DateTime (t/date-time 2011 10 13 23 55 0))
|
||||
|
|
@ -38,8 +44,12 @@
|
|||
(is (instance? org.joda.time.DateTime output))
|
||||
(is (= input (.toDate ^DateTime output)))))
|
||||
|
||||
|
||||
(deftest ^{:integration true} test-reader-extensions
|
||||
(let [^DateTime d (t/date-time 2011 10 13 23 55 0)]
|
||||
(binding [*print-dup* true]
|
||||
(pr-str d))))
|
||||
|
||||
(deftest ^{:integration true} test-reader-extensions-for-localdate
|
||||
(let [^DateTime d (t/today)]
|
||||
(binding [*print-dup* true]
|
||||
(pr-str d))))
|
||||
Loading…
Reference in a new issue