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.Monoid.Unicode
16 import Data.Time.Calendar.WeekDate
17 import Data.Time.HTTP.Common
18 import Data.Time.RFC822.Internal hiding (toAsciiBuilder)
20 -- |Parse an RFC 1123 date and time string.
21 rfc1123DateAndTime ∷ Parser ZonedTime
22 rfc1123DateAndTime = dateTime
24 dateTime ∷ Parser ZonedTime
25 dateTime = do weekDay ← optionMaybe $
26 do w ← shortWeekDayNameP
34 → assertWeekDayIsGood givenWD gregDay
35 (tod, timeZone) ← rfc822time
36 let lt = LocalTime gregDay tod
37 zt = ZonedTime lt timeZone
43 month ← shortMonthNameP
47 assertGregorianDateIsGood year month day
49 -- |Convert a 'ZonedTime' to RFC 1123 date and time string.
50 toAsciiBuilder ∷ ZonedTime → AsciiBuilder
51 toAsciiBuilder zonedTime
52 = let localTime = zonedTimeToLocalTime zonedTime
53 timeZone = zonedTimeZone zonedTime
54 (year, month, day) = toGregorian (localDay localTime)
55 (_, _, week) = toWeekDate (localDay localTime)
56 timeOfDay = localTimeOfDay localTime
59 ⊕ A.toAsciiBuilder ", "
61 ⊕ A.toAsciiBuilder " "
62 ⊕ shortMonthName month
63 ⊕ A.toAsciiBuilder " "
65 ⊕ A.toAsciiBuilder " "
66 ⊕ show2 (todHour timeOfDay)
67 ⊕ A.toAsciiBuilder ":"
68 ⊕ show2 (todMin timeOfDay)
69 ⊕ A.toAsciiBuilder ":"
70 ⊕ show2 (floor (todSec timeOfDay) ∷ Int)
71 ⊕ A.toAsciiBuilder " "
72 ⊕ showRFC822TimeZone timeZone