diff --git a/ChangeLog.md b/ChangeLog.md index 0525607..dbf455a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,12 @@ ## Changes between 1.0.0-rc2 and 1.0.0 -No changes yet. +### Extended support for BSON serialization for Joda Time types + +`monger.joda-time` previously only extended BSON (DBObjects) conversion protocol for `org.joda.time.DateTime`. While `DateTime` is the most +commonly used type in JodaTime, plenty of other types are also used and may need to be stored in MongoDB documents. + +Now Monger handles serialization for all JodaTime types that inherit from `org.joda.time.base.AbstractInstant`, for example, `org.joda.time.DateTime` +and `org.joda.time.DateMidnight`. ## Changes between 1.0.0-rc1 and 1.0.0-rc2 diff --git a/src/clojure/monger/joda_time.clj b/src/clojure/monger/joda_time.clj index 5ca4f5b..f60e772 100644 --- a/src/clojure/monger/joda_time.clj +++ b/src/clojure/monger/joda_time.clj @@ -19,8 +19,8 @@ ;; (extend-protocol ConvertToDBObject - org.joda.time.DateTime - (to-db-object [^DateTime input] + org.joda.time.base.AbstractInstant + (to-db-object [^AbstractInstant input] (to-db-object (.toDate input)))) (extend-protocol ConvertFromDBObject diff --git a/test/monger/test/lib_integration_test.clj b/test/monger/test/lib_integration_test.clj index 0e3cd62..58e17f2 100644 --- a/test/monger/test/lib_integration_test.clj +++ b/test/monger/test/lib_integration_test.clj @@ -3,7 +3,7 @@ monger.json monger.joda-time monger.conversion) - (:import org.joda.time.DateTime + (:import [org.joda.time DateTime DateMidnight] org.bson.types.ObjectId com.mongodb.DBObject) (:require [clojure.data.json :as json] @@ -23,6 +23,12 @@ (is (= 1318550100000 (.getTime ^java.util.Date d))))) +(deftest conversion-of-joda-datemidnight-to-db-object + (let [d (to-db-object (DateMidnight. (t/date-time 2011 10 13)))] + (is (instance? java.util.Date d)) + (is (= 1318464000000 (.getTime ^java.util.Date d))))) + + (deftest conversion-of-java-util-date-to-joda-datetime (let [input (.toDate ^DateTime (t/date-time 2011 10 13 23 55 0)) output (from-db-object input false)]