From b977bb5ba3d5ad8f8008aa4ceb60d1f988a82a0a Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 22 Nov 2015 01:56:20 +0100 Subject: Generate a mail that contains both birthdays today and birthdays next week --- src/Model/Date.hs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/Model/Date.hs') diff --git a/src/Model/Date.hs b/src/Model/Date.hs index 96c15e9..e095cc6 100644 --- a/src/Model/Date.hs +++ b/src/Model/Date.hs @@ -7,8 +7,8 @@ module Model.Date , plusDays , sameDayAndMonth , isBeforeOrEqualDayAndMonth - , isAfterOrEqualDayAndMonth , yearsGap + , daysGap ) where import Data.Time.Clock @@ -40,8 +40,10 @@ getNextWeek = do return (begin, end) plusDays :: Date -> Int -> Date -plusDays (Date d m y) n = - dateFromDay . addDays (toInteger n) $ fromGregorian (toInteger y) m d +plusDays date n = dateFromDay . addDays (toInteger n) . dateToDay $ date + +dateToDay :: Date -> Day +dateToDay (Date d m y) = fromGregorian (toInteger y) m d dateFromDay :: Day -> Date dateFromDay dayTime = @@ -62,13 +64,8 @@ isBeforeOrEqualDayAndMonth d1 d2 = ) ) -isAfterOrEqualDayAndMonth :: Date -> Date -> Bool -isAfterOrEqualDayAndMonth d1 d2 = - ( month d1 > month d2 - || ( month d1 == month d2 - && day d1 >= day d2 - ) - ) - yearsGap :: Date -> Date -> Int yearsGap d1 d2 = abs (year d2 - year d1) + +daysGap :: Date -> Date -> Int +daysGap d1 d2 = abs . fromIntegral $ (dateToDay d1) `diffDays` (dateToDay d2) -- cgit v1.2.3