aboutsummaryrefslogtreecommitdiff
path: root/src/Date.hs
blob: 07f0672250b2f4b601e10c3587e8e1c6a2259d15 (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
  { year :: Int
  , month :: Int
  , day :: 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 (fromIntegral y) m d

sameDayAndMonth :: Date -> Date -> Bool
sameDayAndMonth (Date _ m1 d1) (Date _ m2 d2) = m1 == m2 && d1 == d2

yearsGap :: Date -> Date -> Int
yearsGap (Date y1 _ _) (Date y2 _ _) = abs (y2 - y1)