X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-http.git;a=blobdiff_plain;f=Data%2FTime%2FRFC733.hs;h=6234c1b50b8fb9848123ccd602a6a1814de22ffc;hp=9073cd7d11848e6eab7091800320f7936b5f6bfb;hb=4e2898d9c40d6e962a33d5d05a3aa80c10c312fc;hpb=98132c09a6383d8d8447e0307207b933f7240f5f diff --git a/Data/Time/RFC733.hs b/Data/Time/RFC733.hs index 9073cd7..6234c1b 100644 --- a/Data/Time/RFC733.hs +++ b/Data/Time/RFC733.hs @@ -1,3 +1,6 @@ +{-# LANGUAGE + UnicodeSyntax + #-} -- |This module provides functions to parse and format RFC 733 date -- and time formats. -- @@ -38,48 +41,31 @@ -- > | "Y" ; +12 -- > | ("+" | "-") 4DIGIT ; Local diff: HHMM module Data.Time.RFC733 - ( format - , parse + ( -- * Formatting + toAscii + , toAsciiBuilder + + -- * Parsing + , fromAscii + , rfc733DateAndTime ) where +import Data.Ascii (Ascii) +import qualified Data.Ascii as A +import qualified Data.Attoparsec.Char8 as P import Data.Time -import Data.Time.Calendar.WeekDate -import Data.Time.HTTP.Common import Data.Time.RFC733.Internal +import Prelude.Unicode --- |Format a 'ZonedTime' in RFC 733. -format :: ZonedTime -> String -format zonedTime - = let localTime = zonedTimeToLocalTime zonedTime - timeZone = zonedTimeZone zonedTime - (year, month, day) = toGregorian (localDay localTime) - (_, _, week) = toWeekDate (localDay localTime) - timeOfDay = localTimeOfDay localTime - in - concat [ longWeekDayName week - , ", " - , show2 day - , "-" - , shortMonthName month - , "-" - , show4 year - , " " - , show2 (todHour timeOfDay) - , ":" - , show2 (todMin timeOfDay) - , ":" - , show2 (floor (todSec timeOfDay)) - , "-" - , show4digitsTZ timeZone - ] +-- |Convert a 'ZonedTime' to RFC 733 date and time string. +toAscii ∷ ZonedTime → Ascii +toAscii = A.fromAsciiBuilder ∘ toAsciiBuilder -- |Parse an RFC 733 date and time string. When the string can't be --- parsed, it returns 'Nothing'. -parse :: String -> Maybe ZonedTime -parse src = case P.parse p "" src of - Right zt -> Just zt - Left _ -> Nothing +-- parsed, it returns @'Left' err@. +fromAscii ∷ Ascii → Either String ZonedTime +fromAscii = P.parseOnly p ∘ A.toByteString where - p = do zt <- rfc733DateAndTime - _ <- P.eof + p = do zt ← rfc733DateAndTime + P.endOfInput return zt