--- /dev/null
+module Data.Time.HTTP
+ ( format
+ , parse
+ )
+ where
+
+import qualified Data.Time.RFC1123 as RFC1123
+import qualified Text.Parsec as P
+
+import Data.Time
+import Data.Time.HTTP.Parsec
+
+
+format :: UTCTime -> String
+format utcTime
+ = let timeZone = TimeZone 0 False "GMT"
+ zonedTime = utcToZonedTime timeZone utcTime
+ in
+ RFC1123.format zonedTime
+
+
+parse :: String -> Maybe UTCTime
+parse src = case P.parse p "" src of
+ Right ut -> Just ut
+ Left _ -> Nothing
+ where
+ p = do zt <- rfc2616DateAndTime
+ _ <- P.eof
+ return zt
--- /dev/null
+{-# LANGUAGE FlexibleContexts #-}
+module Data.Time.HTTP.Parsec
+ ( rfc2616DateAndTime
+ )
+ where
+
+import Control.Monad
+import Data.Time
+import Data.Time.RFC1123.Parsec
+import Data.Time.RFC733.Parsec
+import Data.Time.Asctime.Parsec
+import Text.Parsec
+
+
+rfc2616DateAndTime :: Stream s m Char => ParsecT s u m UTCTime
+rfc2616DateAndTime
+ = choice [ liftM zonedTimeToUTC $ try rfc1123DateAndTime
+ , liftM zonedTimeToUTC $ try rfc733DateAndTime
+ , liftM (localTimeToUTC utc) $ asctime
+ ]
import Data.Time
import Data.Time.Calendar.WeekDate
import Data.Time.HTTP.Common
+import Data.Time.RFC822 (showRFC822TimeZone)
import Data.Time.RFC1123.Parsec
{-
, ":"
, show2 (floor (todSec timeOfDay))
, " "
- , show4digitsTZ timeZone
+ , showRFC822TimeZone timeZone
]
parse :: String -> Maybe ZonedTime
module Data.Time.RFC822
( format
, parse
+
+ -- private
+ , showRFC822TimeZone
)
where
, ":"
, show2 (floor (todSec timeOfDay))
, " "
- , show4digitsTZ timeZone
+ , showRFC822TimeZone timeZone
]
+showRFC822TimeZone :: TimeZone -> String
+showRFC822TimeZone tz
+ | timeZoneMinutes tz == 0 = "GMT"
+ | otherwise = show4digitsTZ tz
+
parse :: String -> Maybe ZonedTime
parse src = case P.parse p "" src of
Right zt -> Just zt
Data.Time.RFC1123.Parsec
Data.Time.Asctime
Data.Time.Asctime.Parsec
+ Data.Time.HTTP
+ Data.Time.HTTP.Parsec
Other-modules:
Data.Time.HTTP.Common