diff options
author | Joris | 2016-06-12 23:54:17 +0200 |
---|---|---|
committer | Joris | 2016-06-12 23:54:17 +0200 |
commit | 6a0c5087f716ed6c876a666db6573491bfd3e094 (patch) | |
tree | bf439109143c7a1749c2661fc8b805b83a993027 /src/client/elm/LoggedIn/Income/Model.elm | |
parent | 38896af4281d2e191cbde15836a23e4c0274fff6 (diff) |
Design income form
Diffstat (limited to 'src/client/elm/LoggedIn/Income/Model.elm')
-rw-r--r-- | src/client/elm/LoggedIn/Income/Model.elm | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/client/elm/LoggedIn/Income/Model.elm b/src/client/elm/LoggedIn/Income/Model.elm index bc09f0e..873eaf1 100644 --- a/src/client/elm/LoggedIn/Income/Model.elm +++ b/src/client/elm/LoggedIn/Income/Model.elm @@ -5,20 +5,20 @@ module LoggedIn.Income.Model exposing ) import String exposing (toInt, split) -import Date exposing (Date) +import Date +import Time exposing (Time) import Date.Extra.Create exposing (dateFromFields) -import Utils.Date exposing (numToMonth) +import Date.Extra.Core exposing (intToMonth) import Form exposing (Form) import Form.Validate as Validate exposing (..) -import Form.Error exposing (Error(InvalidString)) type alias Model = - { addIncome : Form () AddIncome + { addIncome : Form String AddIncome } type alias AddIncome = - { creation : Date + { time : Time , amount : Int } @@ -27,20 +27,20 @@ init = { addIncome = Form.initial [] validate } -validate : Validation () AddIncome +validate : Validation String AddIncome validate = form2 AddIncome - (get "creation" dateValidation) + (get "creation" timeValidation) (get "amount" (int `andThen` (minInt 1))) -dateValidation : Validation () Date -dateValidation = +timeValidation : Validation String Time +timeValidation = 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 (numToMonth monthNum) dayNum 0 0 0 0) - _ -> Err InvalidString - _ -> Err InvalidString + Ok (Date.toTime (dateFromFields yearNum (intToMonth monthNum) dayNum 0 0 0 0)) + _ -> Err (customError "InvalidDate") + _ -> Err (customError "InvalidDate") ) |