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
  }