-- |Internal functions for "Data.Time.RFC733".
module Data.Time.RFC733.Internal
( rfc733DateAndTime
+ , toAsciiBuilder
)
where
+import Data.Ascii (AsciiBuilder)
+import qualified Data.Ascii as A
import Control.Applicative
import Data.Attoparsec.Char8
+import Data.Monoid.Unicode
import Data.Time
+import Data.Time.Calendar.WeekDate
import Data.Time.HTTP.Common
-- |Parse RFC 733 date and time strings.
, char 'Z' *> return (TimeZone 0 False "Z")
, read4digitsTZ
]
+
+-- |Convert a 'ZonedTime' to RFC 733 date and time string.
+toAsciiBuilder ∷ ZonedTime → AsciiBuilder
+toAsciiBuilder zonedTime
+ = let localTime = zonedTimeToLocalTime zonedTime
+ timeZone = zonedTimeZone zonedTime
+ (year, month, day) = toGregorian (localDay localTime)
+ (_, _, week) = toWeekDate (localDay localTime)
+ timeOfDay = localTimeOfDay localTime
+ in
+ longWeekDayName week
+ ⊕ A.toAsciiBuilder ", "
+ ⊕ show2 day
+ ⊕ A.toAsciiBuilder "-"
+ ⊕ shortMonthName month
+ ⊕ A.toAsciiBuilder "-"
+ ⊕ show4 year
+ ⊕ A.toAsciiBuilder " "
+ ⊕ show2 (todHour timeOfDay)
+ ⊕ A.toAsciiBuilder ":"
+ ⊕ show2 (todMin timeOfDay)
+ ⊕ A.toAsciiBuilder ":"
+ ⊕ show2 (floor (todSec timeOfDay) ∷ Int)
+ ⊕ A.toAsciiBuilder "-"
+ ⊕ show4digitsTZ timeZone