Open cvogt opened 10 years ago
Also consider Java 8 date/time support.
Let's see if we can do something about this in the GSoC project for adding database-specific features. Assigning to 2.2.
@dimitrkovalsky is the corresponding GSOC student.
Wasn't handled in the GSOC project. Another Stackoverflow instance of this: http://stackoverflow.com/questions/26457945/compare-joda-datetime-in-filter
Works for me:
def testMappedNumeric = {
implicit val javaDateMapper = MappedColumnType.base[java.util.Date, java.sql.Timestamp](
d => new java.sql.Timestamp(d.getTime),
d => new java.util.Date(d.getTime))
class T(tag: Tag) extends Table[(Int, java.util.Date)](tag, u"t") {
def id = column[Int]("id", O.PrimaryKey)
def d = column[java.util.Date]("d")
def * = (id, d)
}
val ts = TableQuery[T]
val d1 = new java.util.Date(java.sql.Date.valueOf("2012-12-24").getTime)
val d2 = new java.util.Date(java.sql.Date.valueOf("2012-12-25").getTime)
val d3 = new java.util.Date(java.sql.Date.valueOf("2012-12-26").getTime)
val d4 = new java.util.Date(java.sql.Date.valueOf("2012-12-27").getTime)
seq(
ts.schema.create,
ts ++= Seq((1, d1), (2, d2), (3, d3), (4, d4)),
ts.filter(_.d === d2).map(_.id).to[Set].result.map(_ shouldBe Set(2)),
ts.filter(_.d >= d2).map(_.id).to[Set].result.map(_ shouldBe Set(2, 3, 4))
)
}
It looks like the problem in the SO posts is that people use ==
instead of ===
somehow related to https://github.com/tototoshi/slick-joda-mapper http://stackoverflow.com/questions/21350399/filtering-all-records-which-have-a-joda-datetime-date-equal-to-today