module Data.Time.RFC822 (
formatTimeRFC822, parseTimeRFC822
) where
import Control.Applicative
import Data.Maybe
import Data.Monoid.Textual hiding (foldr, map)
import Data.String (fromString)
import Data.Text (Text)
import Data.Time.Calendar
import Data.Time.Format
import Data.Time.Locale.Compat
import Data.Time.LocalTime
import Data.Time.Util
test1 = "Wed, 02 Oct 2002 13:00:00 GMT"
test2 = "Wed, 02 Oct 2002 13:00:00 +0100"
test3 = "Wed, 02 Oct 2002 13:00 +0100"
test4 = "02 Oct 2002 13:00 +0100"
test5 = "02 Oct 02 13:00 +0100"
tests :: [Text]
tests = [test1, test2, test3, test4, test5]
testParse = length (catMaybes (map parseTimeRFC822 tests)) == length tests
formatTimeRFC822 :: (TextualMonoid t) => ZonedTime -> t
formatTimeRFC822 zonedTime = fromString $ formatTime defaultTimeLocale "%a, %d %b %Y %X %z" zonedTime
formatsRFC822 :: [Text]
formatsRFC822 = [ "%a, %d %b %y %X %z"
, "%a, %d %b %y %X %Z"
, "%a, %d %b %y %H:%M %z"
, "%a, %d %b %y %H:%M %Z"
, "%a, %d %b %Y %X %z"
, "%a, %d %b %Y %X %Z"
, "%a, %d %b %Y %H:%M %z"
, "%a, %d %b %Y %H:%M %Z"
, "%d %b %y %X %z"
, "%d %b %y %X %Z"
, "%d %b %y %H:%M %z"
, "%d %b %y %H:%M %Z"
, "%d %b %Y %X %z"
, "%d %b %Y %X %Z"
, "%d %b %Y %H:%M %z"
, "%d %b %Y %H:%M %Z"
]
parseTimeRFC822 :: (TextualMonoid t) => t -> Maybe ZonedTime
parseTimeRFC822 = parseTimeUsing formatsRFC822