class MyLocalDate(d: Date) extends DateField(d) { }
implicit def myLocalDateToLocalDate(date: MyLocalDate): LocalDate = { val instant = Instant.ofEpochMilli(date.value.getTime) LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate }
implicit def optionMyLocalDateToLocalDate(date: Option[MyLocalDate]): Option[LocalDate] = { date.map{tmp => val instant = Instant.ofEpochMilli(tmp.value.getTime) Some(LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate) }.getOrElse(None) }
implicit def localDateToMyLocalDate(date: LocalDate): MyLocalDate = { val instant = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant() new MyLocalDate(Date.from(instant)) }
implicit def optionLocalDateToMyLocalDate(date: Option[LocalDate]): Option[MyLocalDate] = { date.map{tmp => val instant = tmp.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant() Some(new MyLocalDate(Date.from(instant))) }.getOrElse(None) }
--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
case class Employee( id: Long, surname: String, firstname: String, lastname: String, birthday: Option[MyLocalDate], citizenship: String, insurance_number: String, tax_number: String, sex: Boolean, @Column("relationship_status_id") val relationshipStatus: Int, @Column("nationality_id") val nationalityId: Int, override var created_at: TimeStamp, override var updated_at: TimeStamp ) extends Entity[Long] { override def save = inTransaction { super.save.asInstanceOf[Employee] }
def update = inTransaction { Employee.findById(this.id).map { employee => val tmp = this.copy(created_at = employee.created_at, updated_at = employee.updated_at) tmp.save } }}
val tmp = Employee(0,1, 1, .........,None (here is field Option(MyLocalDate),....).save
Are you using Lift Record here? Can you give an example of where you want the conversion to be applied?