diff --git a/src/clojure/monger/joda_time.clj b/src/clojure/monger/joda_time.clj index b957349..66ef7ac 100644 --- a/src/clojure/monger/joda_time.clj +++ b/src/clojure/monger/joda_time.clj @@ -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 ;; diff --git a/test/monger/test/lib_integration_test.clj b/test/monger/test/lib_integration_test.clj index 6777383..b13f221 100644 --- a/test/monger/test/lib_integration_test.clj +++ b/test/monger/test/lib_integration_test.clj @@ -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)))) \ No newline at end of file