Reputation: 1437
I have a value of type UTCTime
representing the current time, and other value of type Day
which I would like to know if is greater or equal than the current time.
Upvotes: 3
Views: 350
Reputation: 7705
A UTCTime
is composed of a Day
(utctDay
) and the number of seconds since midnight (utctDayTime
). Here's a GHCi session showing how to access the day:
ghci > import Data.Time
ghci > time <- getCurrentTime
ghci > :t time
time :: UTCTime
ghci > utctDay time
2016-04-30
ghci > :t utctDay time
utctDay time :: Day
Once you have access to the Day
, you can use standard comparison functions (>
, >=
==
, <
and <=
):
ghci > t1 <- getCurrentTime
ghci > t2 <- getCurrentTime
ghci > t1
2016-04-30 21:59:06.808488 UTC
ghci > t2
2016-04-30 21:59:11.920389 UTC
ghci > (utctDay t1) >= (utctDay t2)
True
You might also want to check out the Haddocks for UTCTime
.
Upvotes: 4