--- /dev/null
+module Data.Time.RFC1123
+ ( format
+ , parse
+ )
+ where
+
+import qualified Text.Parsec as P
+
+import Data.Time
+import Data.Time.Calendar.WeekDate
+import Data.Time.HTTP.Common
+import Data.Time.RFC1123.Parsec
+
+{-
+ The syntax for the date is hereby changed to:
+
+ date = 1*2DIGIT month 2*4DIGIT
+-}
+
+format :: ZonedTime -> String
+format zonedTime
+ = let localTime = zonedTimeToLocalTime zonedTime
+ timeZone = zonedTimeZone zonedTime
+ (year, month, day) = toGregorian (localDay localTime)
+ (_, _, week) = toWeekDate (localDay localTime)
+ timeOfDay = localTimeOfDay localTime
+ in
+ concat [ shortWeekDayName week
+ , ", "
+ , show2 day
+ , " "
+ , shortMonthName month
+ , " "
+ , show4 year
+ , " "
+ , show2 (todHour timeOfDay)
+ , ":"
+ , show2 (todMin timeOfDay)
+ , ":"
+ , show2 (floor (todSec timeOfDay))
+ , " "
+ , show4digitsTZ timeZone
+ ]
+
+parse :: String -> Maybe ZonedTime
+parse src = case P.parse p "" src of
+ Right zt -> Just zt
+ Left _ -> Nothing
+ where
+ p = do zt <- rfc1123DateAndTime
+ _ <- P.eof
+ return zt
--- /dev/null
+{-# LANGUAGE FlexibleContexts #-}
+module Data.Time.RFC1123.Parsec
+ ( rfc1123DateAndTime
+ )
+ where
+
+import Control.Monad
+import Data.Fixed
+import Data.Time
+import Data.Time.Calendar.WeekDate
+import Data.Time.HTTP.Common
+import Data.Time.RFC822.Parsec
+import Text.Parsec
+
+
+rfc1123DateAndTime :: Stream s m Char => ParsecT s u m ZonedTime
+rfc1123DateAndTime = dateTime
+
+dateTime :: Stream s m Char => ParsecT s u m ZonedTime
+dateTime = do weekDay <- optionMaybe $
+ do w <- shortWeekDayNameP
+ _ <- string ", "
+ return w
+ gregDay <- date
+ case weekDay of
+ Nothing
+ -> return () -- No day in week exists.
+ Just givenWD
+ -> assertWeekDayIsGood givenWD gregDay
+ (tod, timeZone) <- rfc822time
+ let lt = LocalTime gregDay tod
+ zt = ZonedTime lt timeZone
+ return zt
+
+date :: Stream s m Char => ParsecT s u m Day
+date = do day <- read2
+ _ <- char ' '
+ month <- shortMonthNameP
+ _ <- char ' '
+ year <- read4
+ _ <- char ' '
+ assertGregorianDateIsGood (toInteger year) month day
Right zt -> Just zt
Left _ -> Nothing
where
- p = do zt <- parser
+ p = do zt <- rfc733DateAndTime
_ <- P.eof
return zt
{-# LANGUAGE FlexibleContexts #-}
module Data.Time.RFC733.Parsec
- ( parser
+ ( rfc733DateAndTime
)
where
import Text.Parsec
-parser :: Stream s m Char => ParsecT s u m ZonedTime
-parser = dateTime
+rfc733DateAndTime :: Stream s m Char => ParsecT s u m ZonedTime
+rfc733DateAndTime = dateTime
dateTime :: Stream s m Char => ParsecT s u m ZonedTime
dateTime = do weekDay <- optionMaybe $
Right zt -> Just zt
Left _ -> Nothing
where
- p = do zt <- parser
+ p = do zt <- rfc822DateAndTime
_ <- P.eof
return zt
{-# LANGUAGE FlexibleContexts #-}
module Data.Time.RFC822.Parsec
- ( parser
+ ( rfc822DateAndTime
+
+ -- private
+ , rfc822time
)
where
import Text.Parsec
-parser :: Stream s m Char => ParsecT s u m ZonedTime
-parser = dateTime
+rfc822DateAndTime :: Stream s m Char => ParsecT s u m ZonedTime
+rfc822DateAndTime = dateTime
dateTime :: Stream s m Char => ParsecT s u m ZonedTime
dateTime = do weekDay <- optionMaybe $
-> return () -- No day in week exists.
Just givenWD
-> assertWeekDayIsGood givenWD gregDay
- (tod, timeZone) <- time
+ (tod, timeZone) <- rfc822time
let lt = LocalTime gregDay tod
zt = ZonedTime lt timeZone
return zt
_ <- char ' '
assertGregorianDateIsGood (toInteger year) month day
-time :: Stream s m Char => ParsecT s u m (TimeOfDay, TimeZone)
-time = do tod <- hour
- _ <- char ' '
- tz <- zone
- return (tod, tz)
+rfc822time :: Stream s m Char => ParsecT s u m (TimeOfDay, TimeZone)
+rfc822time = do tod <- hour
+ _ <- char ' '
+ tz <- zone
+ return (tod, tz)
hour :: Stream s m Char => ParsecT s u m TimeOfDay
hour = do hour <- read2
Library
Exposed-modules:
- Data.Time.RFC822
- Data.Time.RFC822.Parsec
Data.Time.RFC733
Data.Time.RFC733.Parsec
+ Data.Time.RFC822
+ Data.Time.RFC822.Parsec
+ Data.Time.RFC1123
+ Data.Time.RFC1123.Parsec
Other-modules:
Data.Time.HTTP.Common