]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/RFC1123DateTime.hs
Documentation
[Lucu.git] / Network / HTTP / Lucu / RFC1123DateTime.hs
index 9c58e51db91048c196c6a8d54a03c1c9bf272d67..ad683a9b490478e35bad9dfcc552de544212f2e2 100644 (file)
@@ -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