5 -- |Internal functions for "Data.Time.RFC1123".
6 module Data.Time.RFC1123.Internal
11 import Data.Ascii (AsciiBuilder)
12 import qualified Data.Ascii as A
13 import Data.Attoparsec.Char8
14 import Data.Convertible.Base
15 import Data.Monoid.Unicode
18 import Data.Time.Calendar.WeekDate
19 import Data.Time.HTTP.Common
20 import Data.Time.RFC822
22 -- |Parse an RFC 1123 date and time string.
23 rfc1123DateAndTime ∷ Parser ZonedTime
24 rfc1123DateAndTime = dateTime
26 dateTime ∷ Parser ZonedTime
27 dateTime = do weekDay ← optionMaybe $
28 do w ← shortWeekDayNameP
36 → assertWeekDayIsGood givenWD gregDay
37 (tod, timeZone) ← rfc822Time
38 let lt = LocalTime gregDay tod
39 zt = ZonedTime lt timeZone
45 month ← shortMonthNameP
49 assertGregorianDateIsGood year month day
51 -- |Convert a 'ZonedTime' to RFC 1123 date and time string.
52 toAsciiBuilder ∷ ZonedTime → AsciiBuilder
53 toAsciiBuilder zonedTime
54 = let localTime = zonedTimeToLocalTime zonedTime
55 timeZone = zonedTimeZone zonedTime
56 (year, month, day) = toGregorian (localDay localTime)
57 (_, _, week) = toWeekDate (localDay localTime)
58 timeOfDay = localTimeOfDay localTime
61 ⊕ A.toAsciiBuilder ", "
63 ⊕ A.toAsciiBuilder " "
64 ⊕ shortMonthName month
65 ⊕ A.toAsciiBuilder " "
67 ⊕ A.toAsciiBuilder " "
68 ⊕ show2 (todHour timeOfDay)
69 ⊕ A.toAsciiBuilder ":"
70 ⊕ show2 (todMin timeOfDay)
71 ⊕ A.toAsciiBuilder ":"
72 ⊕ show2 (floor (todSec timeOfDay) ∷ Int)
73 ⊕ A.toAsciiBuilder " "
74 ⊕ untag (cs timeZone ∷ Tagged RFC822 AsciiBuilder)