X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-http.git;a=blobdiff_plain;f=Data%2FTime%2FRFC822%2FParsec.hs;h=138b9a4390232f5aadf53af2baf8c923b749c31f;hp=f80633efb5fbd60987f14fc097252d0671fb1795;hb=01d923fe509a76afa27efdc7370438c5d4900492;hpb=9f9ed0471883b50fec1b091621f332d62477a34c diff --git a/Data/Time/RFC822/Parsec.hs b/Data/Time/RFC822/Parsec.hs index f80633e..138b9a4 100644 --- a/Data/Time/RFC822/Parsec.hs +++ b/Data/Time/RFC822/Parsec.hs @@ -15,7 +15,6 @@ import Text.Parsec parser :: Stream s m Char => ParsecT s u m ZonedTime parser = dateTime - dateTime :: Stream s m Char => ParsecT s u m ZonedTime dateTime = do weekDay <- optionMaybe $ do w <- shortWeekDayNameP @@ -26,32 +25,11 @@ dateTime = do weekDay <- optionMaybe $ Nothing -> return () -- No day in week exists. Just givenWD - -> let (_, _, correctWD) = toWeekDate gregDay - in - if correctWD == givenWD then - return () -- Correct day in the week. - else - let (year, month, day) = toGregorian gregDay - in - fail $ concat [ "Gregorian day " - , show year - , "-" - , show month - , "-" - , show day - , " is " - , longWeekDayName correctWD - , ", not " - , longWeekDayName givenWD - ] + -> assertWeekDayIsGood givenWD gregDay (tod, timeZone) <- time - return ZonedTime { - zonedTimeToLocalTime = LocalTime { - localDay = gregDay - , localTimeOfDay = tod - } - , zonedTimeZone = timeZone - } + let lt = LocalTime gregDay tod + zt = ZonedTime lt timeZone + return zt date :: Stream s m Char => ParsecT s u m Day date = do day <- read2 @@ -60,18 +38,7 @@ date = do day <- read2 _ <- char ' ' year <- liftM (+ 1900) read2 _ <- char ' ' - - case fromGregorianValid (toInteger year) month day of - Nothing - -> fail $ concat [ "Invalid gregorian day: " - , show year - , "-" - , show month - , "-" - , show day - ] - Just gregDay - -> return gregDay + assertGregorianDateIsGood (toInteger year) month day time :: Stream s m Char => ParsecT s u m (TimeOfDay, TimeZone) time = do tod <- hour @@ -83,17 +50,7 @@ hour :: Stream s m Char => ParsecT s u m TimeOfDay hour = do hour <- read2 minute <- char ':' >> read2 second <- option 0 (char ':' >> read2) - case makeTimeOfDayValid hour minute second of - Nothing - -> fail $ concat [ "Invalid time of day: " - , show hour - , ":" - , show minute - , ":" - , showFixed True second - ] - Just tod - -> return tod + assertTimeOfDayIsGood hour minute second zone :: Stream s m Char => ParsecT s u m TimeZone zone = choice [ string "UT" >> return (TimeZone 0 False "UT" ) @@ -119,15 +76,5 @@ zone = choice [ string "UT" >> return (TimeZone 0 False "UT" ) , char 'A' >> return (TimeZone ((-1) * 60) False "A") , char 'N' >> return (TimeZone ( 1 * 60) False "N") , char 'Y' >> return (TimeZone ( 12 * 60) False "Y") - , do sign <- (char '+' >> return 1) - <|> - (char '-' >> return (-1)) - hour <- read2 - minute <- read2 - let tz = TimeZone { - timeZoneMinutes = (sign * (hour * 60 + minute)) - , timeZoneSummerOnly = False - , timeZoneName = timeZoneOffsetString tz - } - return tz + , read4digitsTZ ]