From: PHO Date: Wed, 28 Sep 2011 14:58:01 +0000 (+0900) Subject: Everything compiles now. X-Git-Tag: RELEASE-0.2~10 X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=4e2898d;p=time-http.git Everything compiles now. Ditz-issue: 85eb4c20935bf29db052a35d75039c638817227b --- 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 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