X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-http.git;a=blobdiff_plain;f=Data%2FTime%2FFormat%2FRFC733.hs;fp=Data%2FTime%2FRFC733%2FInternal.hs;h=58dec8dfde636aed9b79bd24eb0335df331c0ab3;hp=4037918b7ff4409b1d3a5449e45260eb7560bfc1;hb=2064aacf48e193924b6ffe18a50853d233c16b98;hpb=901a3635d37e25a2d4c2e1562c32c68c410fbdd3 diff --git a/Data/Time/RFC733/Internal.hs b/Data/Time/Format/RFC733.hs similarity index 58% rename from Data/Time/RFC733/Internal.hs rename to Data/Time/Format/RFC733.hs index 4037918..58dec8d 100644 --- a/Data/Time/RFC733/Internal.hs +++ b/Data/Time/Format/RFC733.hs @@ -1,24 +1,95 @@ {-# LANGUAGE - OverloadedStrings + FlexibleInstances + , MultiParamTypeClasses + , OverloadedStrings + , TemplateHaskell , UnicodeSyntax #-} --- |Internal functions for "Data.Time.RFC733". -module Data.Time.RFC733.Internal - ( rfc733DateAndTime - , toAsciiBuilder +-- |This module provides functions to parse and format RFC 733 date +-- and time strings (). +-- +-- The syntax is as follows: +-- +-- > date-time ::= [ day-of-week ", " ] date SP time ("-" | SP) zone +-- > day-of-week ::= "Monday" | "Mon" | "Tuesday" | "Tue" +-- > | "Wednesday" | "Wed" | "Thursday" | "Thu" +-- > | "Friday" | "Fri" | "Saturday" | "Sat" +-- > | "Sunday" | "Sun" +-- > date ::= day ("-" | SP) month ("-" | SP) year +-- > day ::= 2DIGIT +-- > year ::= 2DIGIT | 4DIGIT +-- > month ::= "January" | "Jan" | "February" | "Feb" +-- > | "March" | "Mar" | "April" | "Apr" +-- > | "May" | "June" | "Jun" +-- > | "July" | "Jul" | "August" | "Aug" +-- > | "September" | "Sep" | "October" | "Oct" +-- > | "November" | "Nov" | "December" | "Dec" +-- > time ::= hour [ ":" ] minute [ [ ":" ] second ] +-- > hour ::= 2DIGIT +-- > minute ::= 2DIGIT +-- > second ::= 2DIGIT +-- > zone ::= "GMT" ; Universal Time +-- > | "NST" ; Newfoundland: -3:30 +-- > | "AST" | "ADT" ; Atlantic : -4 / -3 +-- > | "EST" | "EDT" ; Eastern : -5 / -4 +-- > | "CST" | "CDT" ; Central : -6 / -5 +-- > | "MST" | "MDT" ; Mountain : -7 / -6 +-- > | "PST" | "PDT" ; Pacific : -8 / -7 +-- > | "YST" | "YDT" ; Yukon : -9 / -8 +-- > | "HST" | "HDT" ; Haw/Ala : -10 / -9 +-- > | "BST" | "BDT" ; Bering : -11 / -10 +-- > | "Z" ; GMT +-- > | "A" ; -1 +-- > | "M" ; -12 +-- > | "N" ; +1 +-- > | "Y" ; +12 +-- > | ("+" | "-") 4DIGIT ; Local diff: HHMM +module Data.Time.Format.RFC733 + ( RFC733 + , rfc733 + , rfc733DateAndTime ) where -import Data.Ascii (AsciiBuilder) -import qualified Data.Ascii as A import Control.Applicative +import Data.Ascii (Ascii, AsciiBuilder) +import qualified Data.Ascii as A import Data.Attoparsec.Char8 +import Data.Convertible.Base import Data.Monoid.Unicode +import Data.Proxy +import Data.Tagged import Data.Time import Data.Time.Calendar.WeekDate -import Data.Time.HTTP.Common -import Data.Time.RFC822.Internal hiding (toAsciiBuilder) +import Data.Time.Format.HTTP.Common +import Data.Time.Format.RFC822.Internal +import Prelude.Unicode + +-- |The phantom type for conversions between RFC 733 date and time +-- strings and 'ZonedTime'. +-- +-- >>> convertSuccess (ZonedTime (LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37)) utc) +-- Tagged "Sunday, 06-Nov-1994 08:49:37 GMT" +data RFC733 + +-- |The proxy for conversions between RFC 733 date and time strings +-- and 'ZonedTime'. +rfc733 ∷ Proxy RFC733 +{-# INLINE CONLIKE rfc733 #-} +rfc733 = Proxy --- |Parse RFC 733 date and time strings. +instance ConvertSuccess ZonedTime (Tagged RFC733 Ascii) where + {-# INLINE convertSuccess #-} + convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs + +instance ConvertSuccess ZonedTime (Tagged RFC733 AsciiBuilder) where + {-# INLINE convertSuccess #-} + convertSuccess = Tagged ∘ toAsciiBuilder + +instance ConvertAttempt (Tagged RFC733 Ascii) ZonedTime where + {-# INLINE convertAttempt #-} + convertAttempt = parseAttempt' rfc733DateAndTime ∘ untag + +-- |Parse an RFC 733 date and time string. rfc733DateAndTime ∷ Parser ZonedTime rfc733DateAndTime = dateTime @@ -113,7 +184,6 @@ zone = choice [ string "GMT" *> return (TimeZone 0 False "GMT") , read4digitsTZ ] --- |Convert a 'ZonedTime' to RFC 733 date and time string. toAsciiBuilder ∷ ZonedTime → AsciiBuilder toAsciiBuilder zonedTime = let localTime = zonedTimeToLocalTime zonedTime @@ -136,4 +206,8 @@ toAsciiBuilder zonedTime ⊕ A.toAsciiBuilder ":" ⊕ show2 (floor (todSec timeOfDay) ∷ Int) ⊕ A.toAsciiBuilder " " - ⊕ showRFC822TimeZone timeZone + ⊕ untag (cs timeZone ∷ Tagged RFC822 AsciiBuilder) + +deriveAttempts [ ([t| ZonedTime |], [t| Tagged RFC733 Ascii |]) + , ([t| ZonedTime |], [t| Tagged RFC733 AsciiBuilder |]) + ]