diff options
author | Joris | 2015-11-21 21:41:38 +0100 |
---|---|---|
committer | Joris | 2015-11-21 21:41:38 +0100 |
commit | 5375ad26dd78220185f1ffe05222250c06dc1a0c (patch) | |
tree | 30998d4fe19206e8c5c9e564db116d2022e5e313 /src/Notification.hs | |
parent | 7acd7a42f7663aa79d18e24bdb9fe19bf15f8fae (diff) |
Get next week birthdays and send an empty mail for the moment
Diffstat (limited to 'src/Notification.hs')
-rw-r--r-- | src/Notification.hs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Notification.hs b/src/Notification.hs new file mode 100644 index 0000000..de4a591 --- /dev/null +++ b/src/Notification.hs @@ -0,0 +1,49 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Notification + ( today + , nextWeek + ) where + +import qualified Data.Text as T + +import SendMail (sendMail) +import Time (formatCurrentLocale) + +import Model.Date (getCurrentDate, getNextWeek) +import Model.Birthdate (Birthdate, filterBirthdayAt, filterBirthdayBetween) +import Model.Mail (mailSubject, mailBody) +import Model.Config + +today :: [Birthdate] -> Config -> IO () +today birthdates config = do + currentDate <- getCurrentDate + let birthdays = filterBirthdayAt currentDate birthdates + if not (null birthdays) + then + sendMail + (mailTo config) + (mailFrom config) + (mailSubject birthdays) + (mailBody currentDate birthdays) + else + return () + +nextWeek :: [Birthdate] -> Config -> IO () +nextWeek birthdates config = do + currentDayOfWeek <- formatCurrentLocale "%A" + if T.toLower currentDayOfWeek == T.toLower (dayForNextWeekNotification config) + then do + (begin, end) <- getNextWeek + let birthdays = filterBirthdayBetween begin end birthdates + if not (null birthdays) + then + sendMail + (mailTo config) + (mailFrom config) + "" + "" + else + return () + else + return () |