aboutsummaryrefslogtreecommitdiff
path: root/src/Date.hs
diff options
context:
space:
mode:
authorJoris2015-10-09 23:09:28 +0200
committerJoris2015-10-09 23:09:28 +0200
commit6cfff0cc8dea84e2a304d350118112ff5113adec (patch)
tree94a157b7db5c47f2f9ac282536aae37757076e14 /src/Date.hs
downloadevents-6cfff0cc8dea84e2a304d350118112ff5113adec.tar.gz
events-6cfff0cc8dea84e2a304d350118112ff5113adec.tar.bz2
events-6cfff0cc8dea84e2a304d350118112ff5113adec.zip
Initial commit
Diffstat (limited to 'src/Date.hs')
-rw-r--r--src/Date.hs30
1 files changed, 30 insertions, 0 deletions
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)