aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Date.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Date.hs')
-rw-r--r--src/Model/Date.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/Model/Date.hs b/src/Model/Date.hs
index e095cc6..60108e9 100644
--- a/src/Model/Date.hs
+++ b/src/Model/Date.hs
@@ -2,6 +2,7 @@
module Model.Date
( Date(..)
+ , renderDate
, getCurrentDate
, getNextWeek
, plusDays
@@ -9,12 +10,17 @@ module Model.Date
, isBeforeOrEqualDayAndMonth
, yearsGap
, daysGap
+ , isValid
) where
+import Text.Printf (printf)
+
import Data.Time.Clock
import Data.Time.Calendar
import Data.Time.LocalTime
+import Data.Text (Text)
import qualified Data.Text as T
+import Data.Maybe (isJust)
import Time (formatCurrentLocale)
@@ -24,6 +30,16 @@ data Date = Date
, year :: Int
} deriving (Eq, Show)
+renderDate :: Date -> Text
+renderDate (Date d m y) =
+ T.concat
+ [ T.pack $ printf "%02d" d
+ , "/"
+ , T.pack $ printf "%02d" m
+ , "/"
+ , T.pack . show $ y
+ ]
+
getCurrentDate :: IO Date
getCurrentDate = do
now <- getCurrentTime
@@ -69,3 +85,6 @@ yearsGap d1 d2 = abs (year d2 - year d1)
daysGap :: Date -> Date -> Int
daysGap d1 d2 = abs . fromIntegral $ (dateToDay d1) `diffDays` (dateToDay d2)
+
+isValid :: Date -> Bool
+isValid (Date d m y) = isJust $ fromGregorianValid (toInteger y) m d