Skip to content

LocalDateTime

Giuseppe Cannella edited this page Jan 6, 2019 · 6 revisions
Type name example
LocalDateTime 2000-12-31T11:21:19
import java.time.LocalDateTime    
assert(validate[LocalDateTime]("2000-12-31T11:21:19") == Some("2000-12-31T11:21:19"))

Custom pattern

{
      import com.github.gekomad.regexcollection.Ops.ValidatorF
      import com.github.gekomad.regexcollection.util.TryBool._
      import java.time.format.DateTimeFormatter
      implicit val validator: ValidatorF[LocalDateTime] = ValidatorF[LocalDateTime]((a: String) => tryBool(LocalDateTime.parse(a, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.0"))))
      assert(validate[LocalDateTime]("2000-12-31 11:21:19.0") == Some("2000-12-31 11:21:19.0"))
    }

Clone this wiki locally