Skip to content

Instantly share code, notes, and snippets.

@ctcarrier
Created April 1, 2014 16:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ctcarrier/9918087 to your computer and use it in GitHub Desktop.
Save ctcarrier/9918087 to your computer and use it in GitHub Desktop.
Joda DateTime Serializer for ReactiveMongo
import reactivemongo.bson.{BSONHandler, BSONDateTime, Macros}
import org.joda.time.format.ISODateTimeFormat
import org.joda.time.{DateTime, DateTimeZone}
package object myApp {
DateTimeZone.setDefault(DateTimeZone.UTC)
implicit object BSONDateTimeHandler extends BSONHandler[BSONDateTime, DateTime] {
val fmt = ISODateTimeFormat.dateTime()
def read(time: BSONDateTime) = new DateTime(time.value)
def write(jdtime: DateTime) = BSONDateTime(jdtime.getMillis)
}
}
@estaub
Copy link

estaub commented Mar 21, 2015

Thanks much. Shared on StackOverflow, with minor mods.

@fxlae
Copy link

fxlae commented Dec 16, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment