{-# 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

-- |This is a parsec parser for date and time formats allowed in
-- HTTP\/1.1 (RFC 2616).
rfc2616DateAndTime :: Stream s m Char => ParsecT s u m UTCTime
rfc2616DateAndTime
    = choice [ liftM zonedTimeToUTC $ try rfc1123DateAndTime
             , liftM zonedTimeToUTC $ try rfc733DateAndTime
             , liftM (localTimeToUTC utc) $ asctime
             ]