]> gitweb @ CieloNegro.org - time-http.git/blob - Data/Time/RFC733.hs
Everything compiles now.
[time-http.git] / Data / Time / RFC733.hs
1 {-# LANGUAGE
2     UnicodeSyntax
3   #-}
4 -- |This module provides functions to parse and format RFC 733 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 ::= "Monday"    | "Mon" | "Tuesday"  | "Tue"
11 -- >               | "Wednesday" | "Wed" | "Thursday" | "Thu"
12 -- >               | "Friday"    | "Fri" | "Saturday" | "Sat"
13 -- >               | "Sunday"    | "Sun"
14 -- > date        ::= day ("-" | SP) month ("-" | SP) year
15 -- > day         ::= 2DIGIT
16 -- > year        ::= 2DIGIT | 4DIGIT
17 -- > month       ::= "January"   | "Jan" | "February" | "Feb"
18 -- >               | "March"     | "Mar" | "April"    | "Apr"
19 -- >               | "May"               | "June"     | "Jun"
20 -- >               | "July"      | "Jul" | "August"   | "Aug"
21 -- >               | "September" | "Sep" | "October"  | "Oct"
22 -- >               | "November"  | "Nov" | "December" | "Dec"
23 -- > time        ::= hour [ ":" ] minute [ [ ":" ] second ]
24 -- > hour        ::= 2DIGIT
25 -- > minute      ::= 2DIGIT
26 -- > second      ::= 2DIGIT
27 -- > zone        ::= "GMT"              ; Universal Time
28 -- >               | "NST"              ; Newfoundland: -3:30
29 -- >               | "AST" | "ADT"      ; Atlantic    :  -4 /  -3
30 -- >               | "EST" | "EDT"      ; Eastern     :  -5 /  -4
31 -- >               | "CST" | "CDT"      ; Central     :  -6 /  -5
32 -- >               | "MST" | "MDT"      ; Mountain    :  -7 /  -6
33 -- >               | "PST" | "PDT"      ; Pacific     :  -8 /  -7
34 -- >               | "YST" | "YDT"      ; Yukon       :  -9 /  -8
35 -- >               | "HST" | "HDT"      ; Haw/Ala     : -10 /  -9
36 -- >               | "BST" | "BDT"      ; Bering      : -11 / -10
37 -- >               | "Z"                ; GMT
38 -- >               | "A"                ;  -1
39 -- >               | "M"                ; -12
40 -- >               | "N"                ;  +1
41 -- >               | "Y"                ; +12
42 -- >               | ("+" | "-") 4DIGIT ; Local diff: HHMM
43 module Data.Time.RFC733
44     ( -- * Formatting
45       toAscii
46     , toAsciiBuilder
47
48       -- * Parsing
49     , fromAscii
50     , rfc733DateAndTime
51     )
52     where
53 import Data.Ascii (Ascii)
54 import qualified Data.Ascii as A
55 import qualified Data.Attoparsec.Char8 as P
56 import Data.Time
57 import Data.Time.RFC733.Internal
58 import Prelude.Unicode
59
60 -- |Convert a 'ZonedTime' to RFC 733 date and time string.
61 toAscii ∷ ZonedTime → Ascii
62 toAscii = A.fromAsciiBuilder ∘ toAsciiBuilder
63
64 -- |Parse an RFC 733 date and time string. When the string can't be
65 -- parsed, it returns @'Left' err@.
66 fromAscii ∷ Ascii → Either String ZonedTime
67 fromAscii = P.parseOnly p ∘ A.toByteString
68     where
69       p = do zt ← rfc733DateAndTime
70              P.endOfInput
71              return zt