]> gitweb @ CieloNegro.org - time-http.git/blob - Data/Time/RFC1123.hs
Data.Time.{RFC1123,Asctime} now compiles.
[time-http.git] / Data / Time / RFC1123.hs
1 {-# LANGUAGE
2     UnicodeSyntax
3   #-}
4 -- |This module provides functions to parse and format RFC 1123 date
5 -- and time formats.
6 --
7 -- The format is basically same as RFC 822, but the syntax for @date@
8 -- is changed from:
9 --
10 -- > year ::= 2DIGIT
11 --
12 -- to:
13 --
14 -- > year ::= 4DIGIT
15 module Data.Time.RFC1123
16     ( -- * Formatting
17       toAscii
18     , toAsciiBuilder
19
20       -- * Parsing
21     , fromAscii
22     , rfc1123DateAndTime
23     )
24     where
25 import Data.Ascii (Ascii)
26 import qualified Data.Ascii as A
27 import qualified Data.Attoparsec.Char8 as P
28 import Data.Time
29 import Data.Time.RFC1123.Internal
30 import Prelude.Unicode
31
32 -- |Convert a 'ZonedTime' to RFC 1123 date and time string.
33 toAscii ∷ ZonedTime → Ascii
34 toAscii = A.fromAsciiBuilder ∘ toAsciiBuilder
35
36 -- |Parse an RFC 1123 date and time string. When the string can't be
37 -- parsed, it returns @'Left' err@.
38 fromAscii ∷ Ascii → Either String ZonedTime
39 fromAscii = P.parseOnly p ∘ A.toByteString
40     where
41       p = do zt ← rfc1123DateAndTime
42              P.endOfInput
43              return zt