blob: 6660f246bbce0a0a1c2314f4d51756b56d564e5b (
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
|
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 (Date d1 m1 _) (Date d2 m2 _) = m1 == m2 && d1 == d2
yearsGap :: Date -> Date -> Int
yearsGap (Date _ _ y1) (Date _ _ y2) = abs (y2 - y1)
|