aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Income/Model.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/LoggedIn/Income/Model.elm')
-rw-r--r--src/client/elm/LoggedIn/Income/Model.elm24
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")
)