diff options
author | Joris | 2015-11-29 14:43:06 +0100 |
---|---|---|
committer | Joris | 2015-11-29 14:43:06 +0100 |
commit | e6269b6750d50c2f72bf534e32c020f0554705a7 (patch) | |
tree | 5247f2f6a8f207a8ee022b02614ba01b7488849c /src/Model/Mail.hs | |
parent | b0f00782ebc9ca6825a6c87b41e5c4888c009a65 (diff) |
Use next week range to compute next week age and next week day of birthdates
Diffstat (limited to 'src/Model/Mail.hs')
-rw-r--r-- | src/Model/Mail.hs | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/src/Model/Mail.hs b/src/Model/Mail.hs index deb720a..8cc8116 100644 --- a/src/Model/Mail.hs +++ b/src/Model/Mail.hs @@ -7,6 +7,7 @@ module Model.Mail import Data.Text (Text) import qualified Data.Text as T +import Data.Maybe (fromMaybe) import Model.Date import Model.Birthdate @@ -49,24 +50,24 @@ mailSubjectSentence event birthdates = , if event == Today then "today" else "next week" ] -mailBody :: Date -> [Birthdate] -> [Birthdate] -> Text -mailBody currentDate birthdaysToday birthdaysNextWeek = +mailBody :: Date -> SuccessiveDates -> [Birthdate] -> [Birthdate] -> Text +mailBody currentDate nextWeek birthdaysToday birthdaysNextWeek = T.concat [ if not . null $ birthdaysToday - then mailBodySentence Today currentDate birthdaysToday + then mailBodySentence Today currentDate nextWeek birthdaysToday else "" , if not . null $ birthdaysNextWeek then T.concat [ if not . null $ birthdaysToday then " " else "" - , mailBodySentence NextWeek currentDate birthdaysNextWeek + , mailBodySentence NextWeek currentDate nextWeek birthdaysNextWeek ] else "" ] -mailBodySentence :: Event -> Date -> [Birthdate] -> Text -mailBodySentence event currentDate birthdates = - T.concat $ map (mailBodyPart event currentDate) (attachLines birthdates) +mailBodySentence :: Event -> Date -> SuccessiveDates -> [Birthdate] -> Text +mailBodySentence event currentDate nextWeek birthdates = + T.concat $ map (mailBodyPart event currentDate nextWeek) (attachLines birthdates) attachLines :: [Birthdate] -> [(Line, Birthdate)] attachLines birthdates = @@ -83,32 +84,30 @@ data Line = | LastLine deriving (Eq, Show) -mailBodyPart :: Event -> Date -> (Line, Birthdate) -> Text -mailBodyPart event currDate (line, birthdate) = - T.concat - [ case line of - x | x `elem` [SingleLine, FirstLine] -> - if event == Today then "Today, " else "Next week, " - MiddleLine -> - ", " - LastLine -> - " and " - _ -> - "" - , fullname birthdate - , if event == Today then " is " else " will be " - , T.pack . show $ - if event == Today - then age currDate birthdate - else ageNextWeek currDate birthdate - , " years old" - , if event == NextWeek - then - T.concat - [ " on " - , getWeekDay $ (date birthdate) { year = year currDate } - ] - else - "" - , if line == SingleLine || line == LastLine then "." else "" - ] +mailBodyPart :: Event -> Date -> SuccessiveDates -> (Line, Birthdate) -> Text +mailBodyPart event currDate nextWeek (line, birthdate) = + let nextWeekDay = dayAndMonthInRange nextWeek (date birthdate) + in T.concat + [ case line of + x | x `elem` [SingleLine, FirstLine] -> + if event == Today then "Today, " else "Next week, " + MiddleLine -> + ", " + LastLine -> + " and " + _ -> + "" + , fullname birthdate + , if event == Today then " is " else " will be " + , T.pack . show $ + if event == Today + then age currDate birthdate + else fromMaybe 0 $ (\d -> year d - year (date birthdate)) <$> nextWeekDay + , " years old" + , if event == NextWeek + then + fromMaybe "" $ (\d -> T.concat [" on " , getWeekDay d]) <$> nextWeekDay + else + "" + , if line == SingleLine || line == LastLine then "." else "" + ] |