-
Notifications
You must be signed in to change notification settings - Fork 0
LocalDateTime
Giuseppe Cannella edited this page Feb 19, 2020
·
6 revisions
Type name | example |
---|---|
LocalDateTime | 2000-12-31T11:21:19 |
import com.github.gekomad.regexcollection.Validate.validate
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.Validate.validate
import java.time.LocalDateTime
import com.github.gekomad.regexcollection.Collection.Validator
import java.time.format.DateTimeFormatter
implicit val validator =
Validator[LocalDateTime]((a: String) => scala.util.Try(LocalDateTime.parse(a, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.0"))).toOption.map(_ => a))
assert(validate[LocalDateTime]("2000-12-31 11:21:19.0") == Some("2000-12-31 11:21:19.0"))