]> gitweb @ CieloNegro.org - time-http.git/blob - Data/Time/HTTP/Internal.hs
RFC822.Internal
[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.Convertible.Base
14 import Data.Tagged
15 import Data.Time
16 import Data.Time.RFC1123
17 import Data.Time.RFC733
18 import Data.Time.Asctime
19 import Prelude.Unicode
20
21 -- |Parse a date and time string in any formats allowed by HTTP\/1.1
22 -- (RFC 2616).
23 httpDateAndTime ∷ Parser UTCTime
24 httpDateAndTime
25     = choice [ zonedTimeToUTC     <$> try rfc1123DateAndTime
26              , zonedTimeToUTC     <$> try rfc733DateAndTime
27              , localTimeToUTC utc <$> asctime
28              ]
29
30 -- |Convert a 'UTCTime' to RFC 1123 date and time string.
31 toAsciiBuilder ∷ UTCTime → AsciiBuilder
32 toAsciiBuilder = untag' ∘ cs ∘ ut2zt
33     where
34       untag' ∷ Tagged RFC1123 AsciiBuilder → AsciiBuilder
35       {-# INLINE CONLIKE untag' #-}
36       untag' = untag
37
38       ut2zt ∷ UTCTime → ZonedTime
39       {-# INLINE ut2zt #-}
40       ut2zt = utcToZonedTime gmt
41
42       gmt ∷ TimeZone
43       {-# INLINE CONLIKE gmt #-}
44       gmt = TimeZone 0 False "GMT"