diff options
author | Joris | 2016-06-26 12:31:24 +0200 |
---|---|---|
committer | Joris | 2016-06-26 12:31:24 +0200 |
commit | 9ec84e3a20c767f6525639f58cd22715e302b88d (patch) | |
tree | a080552859180707472c1a289080857c0a54fc06 /src/client/elm/Validation.elm | |
parent | 5cb36652ccf07c9e0995ebc421a837ad7d258469 (diff) |
Add an editable date field for punctual payment creation
Diffstat (limited to 'src/client/elm/Validation.elm')
-rw-r--r-- | src/client/elm/Validation.elm | 22 |
1 files changed, 22 insertions, 0 deletions
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") + ) |