Extend DBObject conversion protocol for more JodaTime types
This commit is contained in:
parent
c2a56cbf77
commit
dc7a8fd6ec
3 changed files with 16 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue