{-# LANGUAGE OverloadedStrings #-} module Model.Birthdate ( Birthdate(..) , fullname , age , filterBirthdayAt , filterBirthdayBetween ) where import Data.Text (Text) import qualified Data.Text as T import Model.Date data Birthdate = Birthdate { date :: Date , firstname :: Text , lastname :: Text } deriving (Eq, Show) fullname :: Birthdate -> Text fullname d = T.concat [firstname d, " ", lastname d] age :: Date -> Birthdate -> Int age currentDate birthdate = yearsGap currentDate (date birthdate) ageNextWeek :: Date -> Birthdate -> Int ageNextWeek currentDate birthdate = (+1) $ (daysGap currentDate (date birthdate)) `div` 365 filterBirthdayAt :: Date -> [Birthdate] -> [Birthdate] filterBirthdayAt d = filter (sameDayAndMonth d . date) filterBirthdayBetween :: Date -> Date -> [Birthdate] -> [Birthdate] filterBirthdayBetween begin end = filter (\bd -> let d = date bd in ( begin `isBeforeOrEqualDayAndMonth` d && d `isBeforeOrEqualDayAndMonth` end ) )