From 8c24464a4bd0a486cd0ddf846d3b5a323a7aaa9a Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 4 Oct 2015 20:48:32 +0200 Subject: Using incomes to compute a fair computation to designate the payer --- src/server/Utils/Time.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/server/Utils/Time.hs (limited to 'src/server/Utils') diff --git a/src/server/Utils/Time.hs b/src/server/Utils/Time.hs new file mode 100644 index 0000000..0d6ed73 --- /dev/null +++ b/src/server/Utils/Time.hs @@ -0,0 +1,27 @@ +module Utils.Time + ( belongToCurrentMonth + , getLocalDate + , Date(..) + ) where + +import Data.Time.Clock +import Data.Time.LocalTime +import Data.Time.Calendar + +belongToCurrentMonth :: UTCTime -> IO Bool +belongToCurrentMonth time = do + timeMonth <- month <$> getLocalDate time + actualMonth <- month <$> (getCurrentTime >>= getLocalDate) + return (timeMonth == actualMonth) + +getLocalDate :: UTCTime -> IO Date +getLocalDate time = do + timeZone <- getCurrentTimeZone + let (y, m, d) = toGregorian . localDay $ utcToLocalTime timeZone time + return (Date y m d) + +data Date = Date + { year :: Integer + , month :: Int + , day :: Int + } -- cgit v1.2.3