3 , MultiParamTypeClasses
8 -- |This module provides functions to parse and format RFC 1123 date
11 -- The format is basically same as RFC 822, but the syntax for @date@
19 module Data.Time.RFC1123
24 import Control.Applicative
25 import Data.Ascii (Ascii, AsciiBuilder)
26 import qualified Data.Ascii as A
27 import Data.Attoparsec.Char8
28 import Data.Convertible.Base
29 import Data.Monoid.Unicode
32 import Data.Time.Calendar.WeekDate
33 import Data.Time.HTTP.Common
34 import Data.Time.RFC822.Internal
35 import Prelude.Unicode
40 instance ConvertSuccess ZonedTime (Tagged RFC1123 Ascii) where
41 {-# INLINE convertSuccess #-}
42 convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs
44 instance ConvertSuccess ZonedTime (Tagged RFC1123 AsciiBuilder) where
45 {-# INLINE convertSuccess #-}
46 convertSuccess = Tagged ∘ toAsciiBuilder
48 instance ConvertAttempt (Tagged RFC1123 Ascii) ZonedTime where
49 {-# INLINE convertAttempt #-}
50 convertAttempt = parseAttempt' rfc1123DateAndTime ∘ untag
52 -- |Parse an RFC 1123 date and time string.
53 rfc1123DateAndTime ∷ Parser ZonedTime
54 rfc1123DateAndTime = dateTime
56 dateTime ∷ Parser ZonedTime
57 dateTime = do weekDay ← optionMaybe $
58 do w ← shortWeekDayNameP
66 → assertWeekDayIsGood givenWD gregDay
67 (tod, timeZone) ← rfc822Time
68 let lt = LocalTime gregDay tod
69 zt = ZonedTime lt timeZone
75 month ← shortMonthNameP
79 assertGregorianDateIsGood year month day
81 toAsciiBuilder ∷ ZonedTime → AsciiBuilder
82 toAsciiBuilder zonedTime
83 = let localTime = zonedTimeToLocalTime zonedTime
84 timeZone = zonedTimeZone zonedTime
85 (year, month, day) = toGregorian (localDay localTime)
86 (_, _, week) = toWeekDate (localDay localTime)
87 timeOfDay = localTimeOfDay localTime
90 ⊕ A.toAsciiBuilder ", "
92 ⊕ A.toAsciiBuilder " "
93 ⊕ shortMonthName month
94 ⊕ A.toAsciiBuilder " "
96 ⊕ A.toAsciiBuilder " "
97 ⊕ show2 (todHour timeOfDay)
98 ⊕ A.toAsciiBuilder ":"
99 ⊕ show2 (todMin timeOfDay)
100 ⊕ A.toAsciiBuilder ":"
101 ⊕ show2 (floor (todSec timeOfDay) ∷ Int)
102 ⊕ A.toAsciiBuilder " "
103 ⊕ untag (cs timeZone ∷ Tagged RFC822 AsciiBuilder)
105 deriveAttempts [ ([t| ZonedTime |], [t| Tagged RFC1123 Ascii |])
106 , ([t| ZonedTime |], [t| Tagged RFC1123 AsciiBuilder |])