aboutsummaryrefslogtreecommitdiff
path: root/src/server/Utils/Time.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Utils/Time.hs')
-rw-r--r--src/server/Utils/Time.hs27
1 files changed, 27 insertions, 0 deletions
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
+ }