diff options
author | Joris | 2015-10-10 11:22:03 +0200 |
---|---|---|
committer | Joris | 2015-10-10 11:22:03 +0200 |
commit | 7825b27d262af7252b48e9179a5bbf86b0f30d22 (patch) | |
tree | 2d85883a427fa1183cd5f7737b58e29ba2471828 /src/Birthdate.hs | |
parent | dd16fd43b09a881a43433174728cf45792cce8ae (diff) |
More readable birthdates in csv file
Diffstat (limited to 'src/Birthdate.hs')
-rw-r--r-- | src/Birthdate.hs | 50 |
1 files changed, 1 insertions, 49 deletions
diff --git a/src/Birthdate.hs b/src/Birthdate.hs index 2ef1bcb..4c6e398 100644 --- a/src/Birthdate.hs +++ b/src/Birthdate.hs @@ -4,17 +4,13 @@ module Birthdate ( Birthdate(..) , fullname , age - , readBirthdates , filterBirthday ) where import Data.Text (Text) import qualified Data.Text as T -import qualified Data.Text.IO as T -import qualified Data.Text.Read as T -import Data.Either (partitionEithers) -import Date (Date(Date), sameDayAndMonth, yearsGap) +import Date (Date, sameDayAndMonth, yearsGap) data Birthdate = Birthdate { date :: Date @@ -28,49 +24,5 @@ fullname d = T.concat [firstname d, " ", lastname d] age :: Date -> Birthdate -> Int age currentDate birthdate = yearsGap currentDate (date birthdate) -readBirthdates :: FilePath -> IO (Either Text [Birthdate]) -readBirthdates path = do - eitherBirthdates <- map parseBirthdate . zip [1..] . T.lines <$> T.readFile path - return $ - case partitionEithers eitherBirthdates of - ([], birthdates) -> - Right birthdates - (errors, _) -> - Left $ T.intercalate "\n" errors - -parseBirthdate :: (Int, Text) -> Either Text Birthdate -parseBirthdate (line, text) = - case map T.strip $ T.splitOn "," text of - [date, lastname, firstname] -> - case map T.decimal $ T.splitOn "/" date of - [Right (day, ""), Right (month, ""), Right (year, "")] -> - Right Birthdate - { date = Date year month day - , lastname = lastname - , firstname = firstname - } - _ -> - Left $ T.concat - [ lineOutput line - , " birthdate: " - , date - , ". (Required: year/month/day)" - ] - _ -> - Left $ T.concat - [ lineOutput line - , " line: " - , text - , ". (Required: date, lastname, firstname)" - ] - -lineOutput :: Int -> Text -lineOutput line = - T.concat - [ "[L" - , T.pack . show $ line - , "]" - ] - filterBirthday :: Date -> [Birthdate] -> [Birthdate] filterBirthday d = filter (sameDayAndMonth d . date) |