Added support for LocalDate - required for serializing (clj-time/today).
This commit is contained in:
parent
957650dfe3
commit
679fd2bf92
2 changed files with 39 additions and 0 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
|
||||
;;
|
||||
|
|
|
|||
32
test/monger/test/clj_time_local_date_test.clj
Normal file
32
test/monger/test/clj_time_local_date_test.clj
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
;; requires profile dev2 for clj-time
|
||||
(set! *warn-on-reflection* true)
|
||||
|
||||
(ns monger.test.clj-time-local-date-test
|
||||
(:import java.util.Date)
|
||||
(:require [monger core joda-time]
|
||||
[clojure stacktrace]
|
||||
[monger.collection :as mgcol]
|
||||
[clj-time.core :as dt]
|
||||
[clj-time.coerce :as dt-coerce]
|
||||
[monger.test.helper :as helper])
|
||||
(:use [clojure.test]
|
||||
[monger.operators]
|
||||
[monger.test.fixtures]))
|
||||
|
||||
(monger.core/connect!)
|
||||
(monger.core/set-db! (monger.core/get-db "monger-test"))
|
||||
|
||||
(use-fixtures :each purge-people purge-docs purge-things purge-libraries)
|
||||
|
||||
(deftest find-with-local-date
|
||||
(let [collection "libraries"]
|
||||
(mgcol/insert-batch collection [{:language "Clojure" :name "aleph" :created_at (dt/now)}
|
||||
{:language "R"
|
||||
:name "bayes"
|
||||
:created_at (dt-coerce/to-date-time (dt/plus (dt/today) (dt/days 1)))}])
|
||||
(are [n the-criteria]
|
||||
(= n (.count (mgcol/find collection the-criteria)))
|
||||
2 {:created_at {$gt (dt/today)}}
|
||||
1 {:created_at {"$gte" (dt/today) "$lt" (dt/plus (dt/today) (dt/days 1))}}
|
||||
1 {:created_at {"$gte" (dt/plus (dt/today) (dt/days 1))}})))
|
||||
|
||||
Loading…
Reference in a new issue