X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FRFC1123DateTime.hs;h=e9300a5d3def1fe31fe564f336f231fbe25499ca;hb=0dc3d31312a12f2b085242841b29eb0d96e9c4ac;hp=3be2dd414b0bd67ba39166a6d9d95c2395977c16;hpb=858129cb755aa09da2b7bd758efb8519f2c89103;p=Lucu.git diff --git a/Network/HTTP/Lucu/RFC1123DateTime.hs b/Network/HTTP/Lucu/RFC1123DateTime.hs index 3be2dd4..e9300a5 100644 --- a/Network/HTTP/Lucu/RFC1123DateTime.hs +++ b/Network/HTTP/Lucu/RFC1123DateTime.hs @@ -9,12 +9,9 @@ module Network.HTTP.Lucu.RFC1123DateTime where import Control.Monad -import qualified Data.ByteString.Lazy.Char8 as B -import Data.ByteString.Lazy.Char8 (ByteString) import Network.HTTP.Lucu.Format import Network.HTTP.Lucu.Parser import System.Time -import System.Locale month :: [String] month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] @@ -22,7 +19,8 @@ month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", week :: [String] week = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] --- |Format a @CalendarTime@ to RFC 1123 Date and Time string. +-- |Format a 'System.Time.CalendarTime' to RFC 1123 Date and Time +-- string. formatRFC1123DateTime :: CalendarTime -> String formatRFC1123DateTime time = time `seq` @@ -40,12 +38,12 @@ formatRFC1123DateTime time fmtDec 2 (ctMin time) ++ ":" ++ fmtDec 2 (ctSec time) - ++ ":" ++ + ++ " " ++ id (ctTZName time) --- |Format a @ClockTime@ to HTTP Date and Time. Time zone will be --- always UTC but prints as GMT. +-- |Format a 'System.Time.ClockTime' to HTTP Date and Time. Time zone +-- will be always UTC but prints as GMT. formatHTTPDateTime :: ClockTime -> String formatHTTPDateTime time = time `seq` @@ -68,17 +66,17 @@ formatHTTPDateTime time parseHTTPDateTime :: String -> Maybe ClockTime parseHTTPDateTime src = case parseStr httpDateTime src of - (Success ct, _) -> Just ct - _ -> Nothing + (# Success ct, _ #) -> Just ct + (# _ , _ #) -> Nothing httpDateTime :: Parser ClockTime -httpDateTime = do foldl (<|>) (fail "") (map string week) +httpDateTime = do foldl (<|>) failP (map string week) char ',' char ' ' day <- liftM read (count 2 digit) char ' ' - mon <- foldl (<|>) (fail "") (map tryEqToFst (zip month [1..])) + mon <- foldl (<|>) failP (map tryEqToFst (zip month [1..])) char ' ' year <- liftM read (count 4 digit) char ' '