[Haskell-beginners] find element of tupels

Henk-Jan van Tuyl hjgtuyl at chello.nl
Thu Dec 17 14:44:34 EST 2009


On Thu, 17 Dec 2009 17:18:41 +0100, <kane96 at gmx.de> wrote:

> thanks Magnus, great, works so far. I added to check that myDay have to  
> be greater 0:
>
> legalDate :: Date -> Bool
> legalDate (myDay, myMonth, myYear) = maybe False id $ do
>     days <- lookup myMonth monthAndMaxDay
>     return (not (myDay <= 0) && (myDay <= days))
>
> Another thing is, that I have to check for leapYears. I have a function  
> that checks if a year is a leap year
>
> isLeapYear :: Int -> Bool
> isLeapYear year = mod year 4 == 0

That is not entirely correct; from package time:
   isLeapYear :: Integer -> Bool
   isLeapYear year = (mod year 4 == 0) && ((mod year 400 == 0) || not (mod  
year 100 == 0))


>
> monthAndMaxDay has 30 days for February which have to be fix. So i have  
> to check in legalDate if the year is a leap year. If so I have to check  
> myDay in February for 29 days, otherwise for 28 days. How can I  
> implement this to isLegalDate?

Use fromGregorianValid from package time.

Regards,
Henk-Jan van Tuyl


--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--



-- 


More information about the Beginners mailing list