From 9ec84e3a20c767f6525639f58cd22715e302b88d Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 26 Jun 2016 12:31:24 +0200 Subject: Add an editable date field for punctual payment creation --- src/client/elm/Validation.elm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/client/elm/Validation.elm (limited to 'src/client/elm/Validation.elm') diff --git a/src/client/elm/Validation.elm b/src/client/elm/Validation.elm new file mode 100644 index 0000000..1729daa --- /dev/null +++ b/src/client/elm/Validation.elm @@ -0,0 +1,22 @@ +module Validation exposing + ( date + ) + +import String exposing (toInt, split) +import Date exposing (Date) +import Date.Extra.Create exposing (dateFromFields) +import Date.Extra.Core exposing (intToMonth) + +import Form.Validate as Validate exposing (..) + +date : Validation String Date +date = + customValidation string (\str -> + case split "/" str of + [day, month, year] -> + case (toInt day, toInt month, toInt year) of + (Ok dayNum, Ok monthNum, Ok yearNum) -> + Ok (dateFromFields yearNum (intToMonth monthNum) dayNum 0 0 0 0) + _ -> Err (customError "InvalidDate") + _ -> Err (customError "InvalidDate") + ) -- cgit v1.2.3