From 9ec84e3a20c767f6525639f58cd22715e302b88d Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 26 Jun 2016 12:31:24 +0200 Subject: Add an editable date field for punctual payment creation --- src/server/Utils/Time.hs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/server/Utils') diff --git a/src/server/Utils/Time.hs b/src/server/Utils/Time.hs index 0d6ed73..e8c7ac1 100644 --- a/src/server/Utils/Time.hs +++ b/src/server/Utils/Time.hs @@ -1,7 +1,6 @@ module Utils.Time ( belongToCurrentMonth - , getLocalDate - , Date(..) + , timeToDay ) where import Data.Time.Clock @@ -10,18 +9,16 @@ import Data.Time.Calendar belongToCurrentMonth :: UTCTime -> IO Bool belongToCurrentMonth time = do - timeMonth <- month <$> getLocalDate time - actualMonth <- month <$> (getCurrentTime >>= getLocalDate) + timeMonth <- dayMonth <$> timeToDay time + actualMonth <- dayMonth <$> (getCurrentTime >>= timeToDay) return (timeMonth == actualMonth) -getLocalDate :: UTCTime -> IO Date -getLocalDate time = do +timeToDay :: UTCTime -> IO Day +timeToDay time = do timeZone <- getCurrentTimeZone - let (y, m, d) = toGregorian . localDay $ utcToLocalTime timeZone time - return (Date y m d) + return . localDay $ utcToLocalTime timeZone time -data Date = Date - { year :: Integer - , month :: Int - , day :: Int - } +dayMonth :: Day -> Int +dayMonth day = + let (_, month, _) = toGregorian day + in month -- cgit v1.2.3