From: PHO Date: Thu, 15 Dec 2011 09:30:18 +0000 (+0900) Subject: Rename Asctime -> C X-Git-Tag: RELEASE-0.3~1^2~1 X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=feaeeec;p=time-http.git Rename Asctime -> C Ditz-issue: 0a3272772c73cf31486eb2b6691fa38232d3c4c5 --- diff --git a/Data/Time/Format/Asctime.hs b/Data/Time/Format/C.hs similarity index 80% rename from Data/Time/Format/Asctime.hs rename to Data/Time/Format/C.hs index 8e280b5..0c204d5 100644 --- a/Data/Time/Format/Asctime.hs +++ b/Data/Time/Format/C.hs @@ -22,9 +22,10 @@ -- > day ::= 2DIGIT | SP 1DIGIT -- > time ::= 2DIGIT ':' 2DIGIT [':' 2DIGIT] -- > year ::= 4DIGIT -module Data.Time.Format.Asctime - ( Asctime - , asctime +module Data.Time.Format.C + ( C + , c + , cDateAndTime ) where import Control.Applicative @@ -33,6 +34,7 @@ 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 @@ -40,27 +42,33 @@ import Data.Time.Format.HTTP.Common import Prelude.Unicode -- |The phantom type for conversions between ANSI C's date and time --- string and 'LocalTime'. +-- strings and 'LocalTime'. -- -- >>> convertSuccess (LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37)) -- Tagged "Sun Nov 6 08:49:37 1994" -data Asctime +data C -instance ConvertSuccess LocalTime (Tagged Asctime Ascii) where +-- |The proxy for conversions between ANSI C's date and time strings +-- and 'LocalTime'. +c ∷ Proxy C +{-# INLINE CONLIKE c #-} +c = Proxy + +instance ConvertSuccess LocalTime (Tagged C Ascii) where {-# INLINE convertSuccess #-} convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs -instance ConvertSuccess LocalTime (Tagged Asctime AsciiBuilder) where +instance ConvertSuccess LocalTime (Tagged C AsciiBuilder) where {-# INLINE convertSuccess #-} convertSuccess = Tagged ∘ toAsciiBuilder -instance ConvertAttempt (Tagged Asctime Ascii) LocalTime where +instance ConvertAttempt (Tagged C Ascii) LocalTime where {-# INLINE convertAttempt #-} - convertAttempt = parseAttempt' asctime ∘ untag + convertAttempt = parseAttempt' cDateAndTime ∘ untag -- |Parse an ANSI C's date and time string. -asctime ∷ Parser LocalTime -asctime +cDateAndTime ∷ Parser LocalTime +cDateAndTime = do weekDay ← shortWeekDayNameP _ ← char ' ' month ← shortMonthNameP @@ -101,6 +109,6 @@ toAsciiBuilder localTime ⊕ A.toAsciiBuilder " " ⊕ show4 year -deriveAttempts [ ([t| LocalTime |], [t| Tagged Asctime Ascii |]) - , ([t| LocalTime |], [t| Tagged Asctime AsciiBuilder |]) +deriveAttempts [ ([t| LocalTime |], [t| Tagged C Ascii |]) + , ([t| LocalTime |], [t| Tagged C AsciiBuilder |]) ] diff --git a/Data/Time/Format/HTTP.hs b/Data/Time/Format/HTTP.hs index 2dd3aad..2c44147 100644 --- a/Data/Time/Format/HTTP.hs +++ b/Data/Time/Format/HTTP.hs @@ -46,6 +46,7 @@ -- > | "Sep" | "Oct" | "Nov" | "Dec" module Data.Time.Format.HTTP ( HTTP + , http , httpDateAndTime ) where @@ -57,7 +58,7 @@ import Data.Convertible.Base import Data.Proxy import Data.Tagged import Data.Time -import Data.Time.Format.Asctime +import Data.Time.Format.C import Data.Time.Format.HTTP.Common import Data.Time.Format.RFC733 import Data.Time.Format.RFC822 @@ -71,6 +72,12 @@ import Prelude.Unicode -- Tagged "Sun, 06 Nov 1994 08:49:37 GMT" data HTTP +-- |The proxy for conversions between ANSI HTTP/1.1 date and time +-- strings and 'UTCTime'. +http ∷ Proxy HTTP +{-# INLINE CONLIKE http #-} +http = Proxy + instance ConvertSuccess UTCTime (Tagged HTTP Ascii) where {-# INLINE convertSuccess #-} convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs @@ -96,17 +103,13 @@ httpDateAndTime = choice [ zonedTimeToUTC <$> try rfc1123DateAndTime , zonedTimeToUTC <$> try rfc733DateAndTime , zonedTimeToUTC <$> try rfc822DateAndTime - , localTimeToUTC utc <$> asctime + , localTimeToUTC utc <$> cDateAndTime ] toAsciiBuilder ∷ UTCTime → AsciiBuilder {-# INLINE toAsciiBuilder #-} toAsciiBuilder = flip proxy rfc1123 ∘ cs ∘ ut2zt where - rfc1123 ∷ Proxy RFC1123 - {-# INLINE CONLIKE rfc1123 #-} - rfc1123 = Proxy - ut2zt ∷ UTCTime → ZonedTime {-# INLINE ut2zt #-} ut2zt = utcToZonedTime gmt diff --git a/Data/Time/Format/RFC1123.hs b/Data/Time/Format/RFC1123.hs index 6d81035..1d4f28e 100644 --- a/Data/Time/Format/RFC1123.hs +++ b/Data/Time/Format/RFC1123.hs @@ -18,6 +18,7 @@ -- > year ::= 4DIGIT module Data.Time.Format.RFC1123 ( RFC1123 + , rfc1123 , rfc1123DateAndTime ) where @@ -27,6 +28,7 @@ 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 @@ -41,6 +43,12 @@ import Prelude.Unicode -- Tagged "Sun, 06 Nov 1994 08:49:37 GMT" data RFC1123 +-- |The proxy for conversions between RFC 1123 date and time strings +-- and 'ZonedTime'. +rfc1123 ∷ Proxy RFC1123 +{-# INLINE CONLIKE rfc1123 #-} +rfc1123 = Proxy + instance ConvertSuccess ZonedTime (Tagged RFC1123 Ascii) where {-# INLINE convertSuccess #-} convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs diff --git a/Data/Time/Format/RFC733.hs b/Data/Time/Format/RFC733.hs index e800310..58dec8d 100644 --- a/Data/Time/Format/RFC733.hs +++ b/Data/Time/Format/RFC733.hs @@ -46,6 +46,7 @@ -- > | ("+" | "-") 4DIGIT ; Local diff: HHMM module Data.Time.Format.RFC733 ( RFC733 + , rfc733 , rfc733DateAndTime ) where @@ -55,6 +56,7 @@ 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 @@ -69,6 +71,12 @@ import Prelude.Unicode -- 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 + instance ConvertSuccess ZonedTime (Tagged RFC733 Ascii) where {-# INLINE convertSuccess #-} convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs diff --git a/Data/Time/Format/RFC822.hs b/Data/Time/Format/RFC822.hs index 803d040..0d8fcac 100644 --- a/Data/Time/Format/RFC822.hs +++ b/Data/Time/Format/RFC822.hs @@ -1,3 +1,6 @@ +{-# LANGUAGE + UnicodeSyntax + #-} -- |This module provides functions to parse and format RFC 822 date -- and time strings (). -- @@ -29,7 +32,15 @@ -- > | ("+" | "-") 4DIGIT ; Local diff: HHMM module Data.Time.Format.RFC822 ( RFC822 + , rfc822 , rfc822DateAndTime ) where +import Data.Proxy import Data.Time.Format.RFC822.Internal + +-- |The proxy for conversions between RFC 822 date and time strings +-- and 'ZonedTime'. +rfc822 ∷ Proxy RFC822 +{-# INLINE CONLIKE rfc822 #-} +rfc822 = Proxy diff --git a/Test/Time/Format/HTTP.hs b/Test/Time/Format/HTTP.hs index 6555cdb..b443e86 100644 --- a/Test/Time/Format/HTTP.hs +++ b/Test/Time/Format/HTTP.hs @@ -12,7 +12,7 @@ import Data.Convertible.Base import Data.Proxy import Data.Tagged import Data.Time -import Data.Time.Format.Asctime +import Data.Time.Format.C import Data.Time.Format.HTTP import Data.Time.Format.RFC733 import Data.Time.Format.RFC822 @@ -89,15 +89,15 @@ instance Arbitrary (Tagged Cent20 UTCTime) where tests ∷ [Property] tests = [ -- Asctime - property ( fromAttempt (ca (Tagged "Sun Nov 6 08:49:37 1994" ∷ Tagged Asctime Ascii)) + property ( fromAttempt (ca (Tagged "Sun Nov 6 08:49:37 1994" ∷ Tagged C Ascii)) ≡ Just referenceLocalTime ) - , property ( (Tagged "Sun Nov 6 08:49:37 1994" ∷ Tagged Asctime Ascii) + , property ( (Tagged "Sun Nov 6 08:49:37 1994" ∷ Tagged C Ascii) ≡ cs referenceLocalTime ) - , property $ \lt → Just lt ≡ fromAttempt (ca (cs (lt ∷ LocalTime) ∷ Tagged Asctime Ascii)) + , property $ \lt → Just lt ≡ fromAttempt (ca (cs (lt ∷ LocalTime) ∷ Tagged C Ascii)) -- RFC733 , property ( fromAttempt (ca (Tagged "Sunday, 06-Nov-94 08:49:37 GMT" ∷ Tagged RFC733 Ascii)) @@ -137,7 +137,7 @@ tests = [ -- Asctime ≡ cs referenceUTCTime ) , property $ \ut → Just ut ≡ fromAttempt (ca (cs ut ∷ Tagged HTTP Ascii) ∷ Attempt UTCTime) - , property $ \ut → Just ut ≡ fromAttempt (ca (retagHTTP (cs (ut2lt ut) ∷ Tagged Asctime Ascii))) + , property $ \ut → Just ut ≡ fromAttempt (ca (retagHTTP (cs (ut2lt ut) ∷ Tagged C Ascii))) , property $ \ut → Just ut ≡ fromAttempt (ca (retagHTTP (cs (ut2zt ut) ∷ Tagged RFC733 Ascii))) , property $ \ut → Just (untag ut) ≡ fromAttempt (ca (retagHTTP (cs (ut2zt (untag (ut ∷ Tagged Cent20 UTCTime))) ∷ Tagged RFC822 Ascii))) diff --git a/time-http.cabal b/time-http.cabal index 678a36b..d30a68a 100644 --- a/time-http.cabal +++ b/time-http.cabal @@ -27,7 +27,7 @@ Source-Repository head Library Exposed-modules: - Data.Time.Format.Asctime + Data.Time.Format.C Data.Time.Format.RFC733 Data.Time.Format.RFC822 Data.Time.Format.RFC1123