Last active
August 29, 2015 14:26
-
-
Save gbougeard/6d7a05baedbff9b16ba3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def jodaLongOrISO: Rule[JsValue, DateTime] = { | |
val invalid = Failure(Seq(ValidationError("error.DateTime"))) | |
Rule.fromMapping[JsValue, DateTime] { | |
case JsNumber(v) ⇒ jodaTime.validate(v.toLong).asOpt match { | |
case Some(dt) ⇒ Success(dt) | |
case None ⇒ invalid | |
} | |
case JsString(v) ⇒ jodaDate.validate(v).asOpt match { | |
case Some(dt) ⇒ Success(dt) | |
case None ⇒ invalid | |
} | |
case _ ⇒ invalid | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
un truc du genre
?