X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-http.git;a=blobdiff_plain;f=Data%2FTime%2FRFC822.hs;h=152d99290f57e89915e72eaf80efd36e72c22e1e;hp=72e3b28f2634b2ce39416b35d3b70b19244b4cd3;hb=d82d61b;hpb=746e89579242035ff05ceec12dd151b4b9931a5f diff --git a/Data/Time/RFC822.hs b/Data/Time/RFC822.hs index 72e3b28..152d992 100644 --- a/Data/Time/RFC822.hs +++ b/Data/Time/RFC822.hs @@ -1,4 +1,61 @@ +{-# LANGUAGE + UnicodeSyntax + #-} +-- |This module provides functions to parse and format RFC 822 date +-- and time formats. +-- +-- The syntax is as follows: +-- +-- > date-time ::= [ day-of-week ", " ] date SP time SP zone +-- > day-of-week ::= "Mon" | "Tue" | "Wed" | "Thu" +-- > | "Fri" | "Sat" | "Sun" +-- > date ::= day SP month SP year +-- > day ::= 2DIGIT +-- > year ::= 2DIGIT ; Yes, only 2 digits. +-- > month ::= "Jan" | "Feb" | "Mar" | "Apr" +-- > | "May" | "Jun" | "Jul" | "Aug" +-- > | "Sep" | "Oct" | "Nov" | "Dec" +-- > time ::= hour ":" minute [ ":" second ] +-- > hour ::= 2DIGIT +-- > minute ::= 2DIGIT +-- > second ::= 2DIGIT +-- > zone ::= "UT" | "GMT" ; Universal Time +-- > | "EST" | "EDT" ; Eastern : -5 / -4 +-- > | "CST" | "CDT" ; Central : -6 / -5 +-- > | "MST" | "MDT" ; Mountain: -7 / -6 +-- > | "PST" | "PDT" ; Pacific : -8 / -7 +-- > | "Z" ; UT +-- > | "A" ; -1 +-- > | "M" ; -12 +-- > | "N" ; +1 +-- > | "Y" ; +12 +-- > | ("+" | "-") 4DIGIT ; Local diff: HHMM module Data.Time.RFC822 - ( + ( -- * Formatting + toAscii + , toAsciiBuilder + + -- * Parsing + , fromAscii + , rfc822DateAndTime ) where +import Data.Ascii (Ascii) +import qualified Data.Ascii as A +import qualified Data.Attoparsec.Char8 as P +import Data.Time +import Data.Time.RFC822.Internal +import Prelude.Unicode + +-- |Convert a 'ZonedTime' to RFC 822 date and time string. +toAscii ∷ ZonedTime → Ascii +toAscii = A.fromAsciiBuilder ∘ toAsciiBuilder + +-- |Parse an RFC 822 date and time string. When the string can't be +-- parsed, it returns @'Left' err@. +fromAscii ∷ Ascii → Either String ZonedTime +fromAscii = P.parseOnly p ∘ A.toByteString + where + p = do zt ← rfc822DateAndTime + P.endOfInput + return zt