X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-http.git;a=blobdiff_plain;f=Data%2FTime%2FRFC733%2FInternal.hs;h=9258e65341bfbe02cfd46e3f5166169eade8eb96;hp=d6aea4110904dcbc928f2af3f618fcad55f3b9f2;hb=4e2898d9c40d6e962a33d5d05a3aa80c10c312fc;hpb=98132c09a6383d8d8447e0307207b933f7240f5f diff --git a/Data/Time/RFC733/Internal.hs b/Data/Time/RFC733/Internal.hs index d6aea41..9258e65 100644 --- a/Data/Time/RFC733/Internal.hs +++ b/Data/Time/RFC733/Internal.hs @@ -5,11 +5,16 @@ -- |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. @@ -106,3 +111,28 @@ zone = choice [ string "GMT" *> return (TimeZone 0 False "GMT") , 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