]> gitweb @ CieloNegro.org - time-http.git/blob - Data/Time/RFC822.hs
Fix build error
[time-http.git] / Data / Time / RFC822.hs
1 {-# LANGUAGE
2     UnicodeSyntax
3   #-}
4 -- |This module provides functions to parse and format RFC 822 date
5 -- and time formats.
6 --
7 -- The syntax is as follows:
8 --
9 -- > date-time   ::= [ day-of-week ", " ] date SP time SP zone
10 -- > day-of-week ::= "Mon" | "Tue" | "Wed" | "Thu"
11 -- >               | "Fri" | "Sat" | "Sun"
12 -- > date        ::= day SP month SP year
13 -- > day         ::= 2DIGIT
14 -- > year        ::= 2DIGIT             ; Yes, only 2 digits.
15 -- > month       ::= "Jan" | "Feb" | "Mar" | "Apr"
16 -- >               | "May" | "Jun" | "Jul" | "Aug"
17 -- >               | "Sep" | "Oct" | "Nov" | "Dec"
18 -- > time        ::= hour ":" minute [ ":" second ]
19 -- > hour        ::= 2DIGIT
20 -- > minute      ::= 2DIGIT
21 -- > second      ::= 2DIGIT
22 -- > zone        ::= "UT"  | "GMT"      ; Universal Time
23 -- >               | "EST" | "EDT"      ; Eastern : -5 / -4
24 -- >               | "CST" | "CDT"      ; Central : -6 / -5
25 -- >               | "MST" | "MDT"      ; Mountain: -7 / -6
26 -- >               | "PST" | "PDT"      ; Pacific : -8 / -7
27 -- >               | "Z"                ; UT
28 -- >               | "A"                ;  -1
29 -- >               | "M"                ; -12
30 -- >               | "N"                ;  +1
31 -- >               | "Y"                ; +12
32 -- >               | ("+" | "-") 4DIGIT ; Local diff: HHMM
33 module Data.Time.RFC822
34     ( -- * Formatting
35       toAscii
36     , toAsciiBuilder
37
38       -- * Parsing
39     , fromAscii
40     , rfc822DateAndTime
41     )
42     where
43 import Data.Ascii (Ascii)
44 import qualified Data.Ascii as A
45 import qualified Data.Attoparsec.Char8 as P
46 import Data.Time
47 import Data.Time.RFC822.Internal
48 import Prelude.Unicode
49
50 -- |Convert a 'ZonedTime' to RFC 822 date and time string.
51 toAscii ∷ ZonedTime → Ascii
52 toAscii = A.fromAsciiBuilder ∘ toAsciiBuilder
53
54 -- |Parse an RFC 822 date and time string. When the string can't be
55 -- parsed, it returns @'Left' err@.
56 fromAscii ∷ Ascii → Either String ZonedTime
57 fromAscii = P.parseOnly p ∘ A.toByteString
58     where
59       p = do zt ← rfc822DateAndTime
60              P.endOfInput
61              return zt