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"]
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 ' '
}
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