blob: 63830d339c132ea802ff6530db9b63651b496656 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
module Date
( Date(..)
, getCurrentDate
, sameDayAndMonth
, isBeforeOrEqualDayAndMonth
, isAfterOrEqualDayAndMonth
, 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
)
isBeforeOrEqualDayAndMonth :: Date -> Date -> Bool
isBeforeOrEqualDayAndMonth d1 d2 =
( month d1 < month d2
|| ( month d1 == month d2
&& day d1 <= day d2
)
)
isAfterOrEqualDayAndMonth :: Date -> Date -> Bool
isAfterOrEqualDayAndMonth d1 d2 =
( month d1 > month d2
|| ( month d1 == month d2
&& day d1 >= day d2
)
)
yearsGap :: Date -> Date -> Int
yearsGap d1 d2 = abs (year d2 - year d1)
|