aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Birthdate.hs
blob: 96783a7dc35791ebd3ff7fd34f3cbe35180bda5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{-# 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)