From 6850159bf998a209ad7b6d7103d113a54659937e Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 21 Nov 2015 17:32:28 +0100 Subject: Add filter birthday between function --- src/Main.hs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index 29e9698..d72bd95 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -10,7 +10,7 @@ import qualified Data.Text as T import qualified Data.Text.IO as T import Date (getCurrentDate) -import Birthdate (filterBirthday) +import Birthdate (Birthdate, filterBirthdayAt) import BirthdateParser (parseBirthdates) import Mail (mailSubject, mailBody) import SendMail (sendMail) @@ -43,15 +43,19 @@ main = do , ":\n" , err ] - (Right birthdates, Right config) -> do - currentDate <- getCurrentDate - let birthdays = filterBirthday currentDate birthdates - if not (null birthdays) - then - sendMail - (mailTo config) - (mailFrom config) - (mailSubject birthdays) - (mailBody currentDate birthdays) - else - return () + (Right birthdates, Right config) -> + sendNotificationForBirthdayToday birthdates config + +sendNotificationForBirthdayToday :: [Birthdate] -> Config -> IO () +sendNotificationForBirthdayToday 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 () -- cgit v1.2.3