blob: 8ab9fd25de508f88b0cc8ae3fbaffd23744031cd (
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
28
29
30
31
32
33
|
module Date
( Date(..)
, getCurrentDate
, sameDayAndMonth
, yearsGap
) where
import Data.Time.Clock
import Data.Time.Calendar
import Data.Time.LocalTime
data Date = Date
{ day :: Int
, month :: Int
, year :: Int
} deriving (Eq, Show)
getCurrentDate :: IO Date
getCurrentDate = do
now <- getCurrentTime
timezone <- getCurrentTimeZone
let zoneNow = utcToLocalTime timezone now
let (y, m, d) = toGregorian $ localDay zoneNow
return $ Date d m (fromIntegral y)
sameDayAndMonth :: Date -> Date -> Bool
sameDayAndMonth d1 d2 =
( day d1 == day d2
&& month d1 == month d2
)
yearsGap :: Date -> Date -> Int
yearsGap d1 d2 = abs (year d2 - year d1)
|