X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FRFC1123DateTime.hs;h=ad683a9b490478e35bad9dfcc552de544212f2e2;hp=9c58e51db91048c196c6a8d54a03c1c9bf272d67;hb=b340a77fa7bd051dd13a41d0a5b1ad30220bc6b6;hpb=62f7c13cae3dd68e639b279a3c9a9a742a559927 diff --git a/Network/HTTP/Lucu/RFC1123DateTime.hs b/Network/HTTP/Lucu/RFC1123DateTime.hs index 9c58e51..ad683a9 100644 --- a/Network/HTTP/Lucu/RFC1123DateTime.hs +++ b/Network/HTTP/Lucu/RFC1123DateTime.hs @@ -1,15 +1,17 @@ module Network.HTTP.Lucu.RFC1123DateTime - ( formatRFC1123DateTime -- CalendarTime -> String - , formatHTTPDateTime -- ClockTime -> String - , parseHTTPDateTime -- String -> Maybe ClockTime + ( formatRFC1123DateTime + , formatHTTPDateTime + , parseHTTPDateTime ) where -import Control.Monad -import System.Time -import System.Locale -import Text.ParserCombinators.Parsec -import Text.Printf +import Control.Monad +import qualified Data.ByteString.Lazy.Char8 as B +import Data.ByteString.Lazy.Char8 (ByteString) +import Network.HTTP.Lucu.Parser +import System.Time +import System.Locale +import Text.Printf month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] week = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] @@ -33,17 +35,18 @@ formatHTTPDateTime = formatRFC1123DateTime . (\cal -> cal { ctTZName = "GMT" }) parseHTTPDateTime :: String -> Maybe ClockTime parseHTTPDateTime src - = case parse httpDateTime "" src of - Right ct -> Just ct - Left err -> Nothing + = case parseStr httpDateTime src of + (Success ct, _) -> Just ct + _ -> Nothing + httpDateTime :: Parser ClockTime -httpDateTime = do foldl (<|>) (unexpected "") (map (try . string) week) +httpDateTime = do foldl (<|>) (fail "") (map string week) char ',' char ' ' day <- liftM read (count 2 digit) char ' ' - mon <- foldl (<|>) (unexpected "") (map tryEqToFst (zip month [1..])) + mon <- foldl (<|>) (fail "") (map tryEqToFst (zip month [1..])) char ' ' year <- liftM read (count 4 digit) char ' ' @@ -71,5 +74,5 @@ httpDateTime = do foldl (<|>) (unexpected "") (map (try . string) week) } where tryEqToFst :: (String, a) -> Parser a - tryEqToFst (str, a) = try $ string str >> return a + tryEqToFst (str, a) = string str >> return a \ No newline at end of file