blob: 170ab36b52a5e5134e4da0d487ff04be202c054f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
module Utils.Time
( belongToCurrentMonth
, timeToDay
) where
import Data.Time.Clock
import Data.Time.LocalTime
import Data.Time.Calendar
belongToCurrentMonth :: UTCTime -> IO Bool
belongToCurrentMonth time = do
timeMonth <- dayMonth <$> timeToDay time
actualMonth <- dayMonth <$> (getCurrentTime >>= timeToDay)
return (timeMonth == actualMonth)
timeToDay :: UTCTime -> IO Day
timeToDay time = localDay . (flip utcToLocalTime time) <$> getTimeZone time
dayMonth :: Day -> Int
dayMonth day =
let (_, month, _) = toGregorian day
in month
|