From 6cfff0cc8dea84e2a304d350118112ff5113adec Mon Sep 17 00:00:00 2001 From: Joris Date: Fri, 9 Oct 2015 23:09:28 +0200 Subject: Initial commit --- src/Date.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Date.hs (limited to 'src/Date.hs') diff --git a/src/Date.hs b/src/Date.hs new file mode 100644 index 0000000..efbef8c --- /dev/null +++ b/src/Date.hs @@ -0,0 +1,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 (year, month, day) = toGregorian $ localDay zoneNow + return $ Date (fromIntegral year) month day + +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) -- cgit v1.2.3