DateTime comparison in filter

1,191 views
Skip to first unread message

Anton Bredykhin

unread,
Oct 19, 2014, 10:43:45 PM10/19/14
to scala...@googlegroups.com
Hey, I'm trying to a Column[DateTime] with a date time in filter, but just can't figure out how to make it work. 

import play.api.Play.current
import play.api.db.slick.Config.driver.simple._
import play.api.db.slick._
import org.joda.time.{DateTime, DateTimeComparator, DateTimeZone}

  private val dateComparator = DateTimeComparator.getInstance()

  implicit def dateTimeToScalaWrapper(dt: DateTime): DateTimeWrapper = new DateTimeWrapper(dt)

  class DateTimeWrapper(dt: DateTime) extends Ordered[DateTime] with Ordering[DateTime] {
    def compare(that: DateTime): Int = dateComparator.compare(dt, that)
    def compare(a: DateTime, b: DateTime): Int = dateComparator.compare(a, b)
  }

  implicit def jodaType = MappedColumnType.base[DateTime, Timestamp](
  {d => new Timestamp(d.getMillis)} ,
  {d => new DateTime(d.getTime, UTC)}
  )

  def removeTimeSlots(start: DateTime, end: DateTime, reservationId: Long) : Int = DB withTransaction { implicit session =>
    timeSlots.filter(x => x.reservationId == reservationId && x.startTime >= start && x.starTime <= end).delete
  }



At the point where I compare x.startTime and start I get the following error: 

Error:(90, -1) Play 2 Compiler: 
Reservations.scala:90: polymorphic expression cannot be instantiated to expected type;
  found   : [R]scala.slick.lifted.Column[R]
  required: Boolean


Any chance I can make those comparisons in my code?  

Christopher Vogt

unread,
Oct 20, 2014, 10:20:53 AM10/20/14
to scala...@googlegroups.com
Help other readers! Cross-link posts between SO and the mailing list.

http://stackoverflow.com/questions/26457945/compare-joda-datetime-in-filter
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Slick / ScalaQuery" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scalaquery+...@googlegroups.com
> <mailto:scalaquery+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/scalaquery/66b7a3c6-bd74-4269-a990-f46971e2af4b%40googlegroups.com
> <https://groups.google.com/d/msgid/scalaquery/66b7a3c6-bd74-4269-a990-f46971e2af4b%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages