{-# LANGUAGE OverloadedStrings #-} module Model.Birthdate ( Birthdate(..) , renderBirthdate , fullname , age , filterBirthdayAt , filterBirthdayInside ) where import Data.Text (Text) import qualified Data.Text as T import Data.Maybe (isJust) import Model.Date data Birthdate = Birthdate { date :: Date , firstname :: Text , lastname :: Text } deriving (Eq, Show) renderBirthdate :: Birthdate -> Text renderBirthdate birthdate = T.concat [ fullname birthdate , " (" , renderDate (date birthdate) , ")" ] fullname :: Birthdate -> Text fullname d = T.concat [firstname d, " ", lastname d] age :: Date -> Birthdate -> Int age currentDate birthdate = yearsGap currentDate (date birthdate) filterBirthdayAt :: Date -> [Birthdate] -> [Birthdate] filterBirthdayAt d = filter (sameDayAndMonth d . date) filterBirthdayInside :: [Date] -> [Birthdate] -> [Birthdate] filterBirthdayInside dates = filter (isJust . dayAndMonthInRange dates . date)