aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Event.hs
blob: e0d536d02e84c980f4243f540f13f6860ab87618 (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
{-# LANGUAGE OverloadedStrings #-}

module Model.Event
  ( Event(..)
  , renderEvent
  , age
  , filterBirthdayAt
  , filterBirthdayInside
  ) where

import Data.Text (Text)
import qualified Data.Text as T
import Data.Maybe (isJust)

import Model.Date

data Event = Event
  { date :: Date
  , name :: Text
  } deriving (Eq, Show)

renderEvent :: Event -> Text
renderEvent event =
  T.concat
    [ name event
    , " ("
    , renderDate (date event)
    , ")"
    ]

age :: Date -> Event -> Int
age currentDate event = yearsGap currentDate (date event)

filterBirthdayAt :: Date -> [Event] -> [Event]
filterBirthdayAt d = filter (sameDayAndMonth d . date)

filterBirthdayInside :: [Date] -> [Event] -> [Event]
filterBirthdayInside dates = filter (isJust . dayAndMonthInRange dates . date)