aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Validation.elm
blob: 1729daa6bb2b686400e830ae8021aa1dd7c71eef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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")
  )