]> gitweb @ CieloNegro.org - time-http.git/blob - Data/Time/HTTP/Internal.hs
Data.Time.HTTP now compiles.
[time-http.git] / Data / Time / HTTP / Internal.hs
1 {-# LANGUAGE
2     UnicodeSyntax
3   #-}
4 -- |Internal functions for "Data.Time.HTTP".
5 module Data.Time.HTTP.Internal
6     ( httpDateAndTime
7     , toAsciiBuilder
8     )
9     where
10 import Control.Applicative
11 import Data.Ascii (AsciiBuilder)
12 import Data.Attoparsec.Char8
13 import Data.Time
14 import qualified Data.Time.RFC1123.Internal as RFC1123
15 import qualified Data.Time.RFC733.Internal  as RFC733
16 import qualified Data.Time.Asctime.Internal as Asctime
17 import Prelude.Unicode
18
19 -- |Parse a date and time string in any formats allowed by HTTP\/1.1
20 -- (RFC 2616).
21 httpDateAndTime ∷ Parser UTCTime
22 httpDateAndTime
23     = choice [ zonedTimeToUTC     <$> try RFC1123.rfc1123DateAndTime
24              , zonedTimeToUTC     <$> try RFC733.rfc733DateAndTime
25              , localTimeToUTC utc <$> Asctime.asctime
26              ]
27
28 -- |Convert a 'UTCTime' to RFC 1123 date and time string.
29 toAsciiBuilder ∷ UTCTime → AsciiBuilder
30 toAsciiBuilder = RFC1123.toAsciiBuilder ∘ ut2zt
31     where
32       ut2zt ∷ UTCTime → ZonedTime
33       ut2zt = utcToZonedTime gmt
34
35       gmt ∷ TimeZone
36       gmt = TimeZone 0 False "GMT"