AutoForms-0.4.0: src/Examples/HCron/Editor3rdLimit.hs
{-# LANGUAGE FlexibleContexts, FlexibleInstances
, MultiParamTypeClasses, TemplateHaskell
, TypeSynonymInstances, UndecidableInstances #-}
module Editor3rdLimit where
import Entry1st
import Graphics.UI.AF.WxFormAll
$(derive [''Entry,''Time,''Month])
main = startWx "Editor3rd" $ editFile specLocation ([]::HCron)
instance TypePresentation (Entry Time) tp1 tp2 tp3 tp4 tp5 where
mkCom x = limit timeLimit ("Incorrect time")
(defaultCom x)
where
timeLimit :: Entry Time -> IO Bool
timeLimit Entry { when = Time y month d h m } = return $
y > 1970 && y < 2100 &&
d >= 1 &&
((month == February && d <= 28) ||
(month == February && d == 29 && y `mod` 4 == 0) ||
(month `elem` [ January, March, May, July, August
, October, December] && d <= 30) ||
(month `elem` [April, June, September, November] && d <= 30)
) &&
h >= 0 && h <= 23 &&
m >= 0 && m <= 59
instance GInstanceCreator Time where
gGenUpTo _ = [Time 2000 January 1 10 00]