diff options
Diffstat (limited to 'src/Model/Birthdate.hs')
-rw-r--r-- | src/Model/Birthdate.hs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Model/Birthdate.hs b/src/Model/Birthdate.hs new file mode 100644 index 0000000..d135419 --- /dev/null +++ b/src/Model/Birthdate.hs @@ -0,0 +1,38 @@ +{-# 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) + +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 ( d `isAfterOrEqualDayAndMonth` begin + && d `isBeforeOrEqualDayAndMonth` end + ) + ) |