我正在嘗試在過濾器中使用日期時間的Column [DateTime],但無法弄清楚如何使其工作。比較過濾器中的joda.DateTime
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
}
在這裏我比較x.startTime開始我得到以下錯誤點:
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
任何機會,我可以把這些比較在我的代碼?
幫助其他讀者!在SO和郵件列表之間交叉鏈接。 https://groups.google.com/d/msgid/scalaquery/66b7a3c6-bd74-4269-a990-f46971e2af4b%40googlegroups.com?utm_medium=email&utm_source=footer – cvogt 2014-10-20 14:21:13
將來會做。感謝您的鏈接 – Anton 2014-10-20 16:43:20