diff options
Diffstat (limited to 'src/Model/BirthdateParser.hs')
-rw-r--r-- | src/Model/BirthdateParser.hs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Model/BirthdateParser.hs b/src/Model/BirthdateParser.hs index c9ac3b9..8e8489b 100644 --- a/src/Model/BirthdateParser.hs +++ b/src/Model/BirthdateParser.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE OverloadedStrings #-} + module Model.BirthdateParser ( parseBirthdates ) where @@ -14,9 +16,20 @@ import Model.Date parseBirthdates :: Text -> Either Text [Birthdate] parseBirthdates input = - left - (T.pack . show) - (parse birthdatesParser "" (T.unpack input)) + left (T.pack . show) (parse birthdatesParser "" (T.unpack input)) >>= validateBirthdates + +validateBirthdates :: [Birthdate] -> Either Text [Birthdate] +validateBirthdates birthdates = + let invalid = filter (not . isValid . date) birthdates + in if null invalid + then + Right birthdates + else + Left $ + T.concat + [ "Invalid birthdates: " + , T.intercalate ", " (map renderBirthdate invalid) + ] birthdatesParser :: Parser [Birthdate] birthdatesParser = many (many newline >> birthdateParser <* many newline) |