aboutsummaryrefslogtreecommitdiff
path: root/src/server/Utils/Time.hs
blob: 0d6ed73308cfe83318e14173623d3b8b115062da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
  }