time-http 0.3 → 0.4
raw patch · 3 files changed
+49/−31 lines, 3 filesdep +failuredep ~attoparsec
Dependencies added: failure
Dependency ranges changed: attoparsec
Files
- ChangeLog +2/−0
- Data/Time/Format/RFC822/Internal.hs +42/−28
- time-http.cabal +5/−3
ChangeLog view
@@ -1,3 +1,5 @@+== time-http-0.4 / unreleased+* bugfix: Don't forget that conversion from ZonedTime to RFC-822 date and time can fail, due to its Y2K problem. == time-http-0.3 / 2011-12-15 * Use tagged and convertible == time-http-0.2 / 2011-10-03
Data/Time/Format/RFC822/Internal.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE- FlexibleInstances+ FlexibleContexts+ , FlexibleInstances , MultiParamTypeClasses , OverloadedStrings , TemplateHaskell@@ -12,10 +13,12 @@ ) where import Control.Applicative+import Control.Failure import Data.Ascii (Ascii, AsciiBuilder) import qualified Data.Ascii as A import Data.Attoparsec.Char8 import Data.Convertible.Base+import Data.Convertible.Utils import Data.Monoid.Unicode import Data.Tagged import Data.Time@@ -26,17 +29,21 @@ -- |The phantom type for conversions between RFC 822 date and time -- strings and 'ZonedTime'. ----- >>> convertSuccess (ZonedTime (LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37)) utc)--- Tagged "Sun, 06 Nov 94 08:49:37 GMT"+-- >>> convertAttempt (ZonedTime (LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37)) utc)+-- Success (Tagged "Sun, 06 Nov 94 08:49:37 GMT")+--+-- Note that RFC 822 has a Y2K problem so converting 'ZonedTime' whose+-- gregorian year is earlier than 1900 or from 2000 onward results in+-- @'ConvertBoundsException' 'Day' 'ZonedTime'@. data RFC822 -instance ConvertSuccess ZonedTime (Tagged RFC822 Ascii) where- {-# INLINE convertSuccess #-}- convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs+instance ConvertAttempt ZonedTime (Tagged RFC822 Ascii) where+ {-# INLINE convertAttempt #-}+ convertAttempt = ((A.fromAsciiBuilder <$>) <$>) ∘ ca -instance ConvertSuccess ZonedTime (Tagged RFC822 AsciiBuilder) where- {-# INLINE convertSuccess #-}- convertSuccess = Tagged ∘ toAsciiBuilder+instance ConvertAttempt ZonedTime (Tagged RFC822 AsciiBuilder) where+ {-# INLINE convertAttempt #-}+ convertAttempt = (Tagged <$>) ∘ toAsciiBuilder instance ConvertSuccess TimeZone (Tagged RFC822 Ascii) where {-# INLINE convertSuccess #-}@@ -120,7 +127,9 @@ , read4digitsTZ ] -toAsciiBuilder ∷ ZonedTime → AsciiBuilder+toAsciiBuilder ∷ Failure (ConvertBoundsException Day ZonedTime) f+ ⇒ ZonedTime+ → f AsciiBuilder toAsciiBuilder zonedTime = let localTime = zonedTimeToLocalTime zonedTime timeZone = zonedTimeZone zonedTime@@ -128,24 +137,29 @@ (_, _, week) = toWeekDate (localDay localTime) timeOfDay = localTimeOfDay localTime in- shortWeekDayName week- ⊕ A.toAsciiBuilder ", "- ⊕ show2 day- ⊕ A.toAsciiBuilder " "- ⊕ shortMonthName month- ⊕ A.toAsciiBuilder " "- ⊕ show2 (year `mod` 100)- ⊕ A.toAsciiBuilder " "- ⊕ show2 (todHour timeOfDay)- ⊕ A.toAsciiBuilder ":"- ⊕ show2 (todMin timeOfDay)- ⊕ A.toAsciiBuilder ":"- ⊕ show2 (floor (todSec timeOfDay) ∷ Int)- ⊕ A.toAsciiBuilder " "- ⊕ untag (cs timeZone ∷ Tagged RFC822 AsciiBuilder)+ if year < 1900 ∨ year ≥ 2000 then+ let minDay = fromGregorian 1900 1 1+ maxDay = fromGregorian 1999 12 31+ in+ failure $ ConvertBoundsException minDay maxDay zonedTime+ else+ return $+ shortWeekDayName week+ ⊕ A.toAsciiBuilder ", "+ ⊕ show2 day+ ⊕ A.toAsciiBuilder " "+ ⊕ shortMonthName month+ ⊕ A.toAsciiBuilder " "+ ⊕ show2 (year `mod` 100)+ ⊕ A.toAsciiBuilder " "+ ⊕ show2 (todHour timeOfDay)+ ⊕ A.toAsciiBuilder ":"+ ⊕ show2 (todMin timeOfDay)+ ⊕ A.toAsciiBuilder ":"+ ⊕ show2 (floor (todSec timeOfDay) ∷ Int)+ ⊕ A.toAsciiBuilder " "+ ⊕ untag (cs timeZone ∷ Tagged RFC822 AsciiBuilder) -deriveAttempts [ ([t| ZonedTime |], [t| Tagged RFC822 Ascii |])- , ([t| ZonedTime |], [t| Tagged RFC822 AsciiBuilder |])- , ([t| TimeZone |], [t| Tagged RFC822 Ascii |])+deriveAttempts [ ([t| TimeZone |], [t| Tagged RFC822 Ascii |]) , ([t| TimeZone |], [t| Tagged RFC822 AsciiBuilder |]) ]
time-http.cabal view
@@ -1,5 +1,5 @@ Name: time-http-Version: 0.3+Version: 0.4 Synopsis: Parse and format HTTP/1.1 Date and Time strings Description: This package provides functionalities to parse and format@@ -40,13 +40,14 @@ Build-depends: ascii == 0.0.*, attempt == 0.3.*,- attoparsec == 0.9.*,+ attoparsec == 0.10.*, base == 4.*, base-unicode-symbols == 0.2.*, blaze-builder == 0.3.*, blaze-textual == 0.2.*, bytestring == 0.9.*, convertible-text == 0.4.*,+ failure == 0.1.*, tagged == 0.2.*, time == 1.2.* @@ -64,13 +65,14 @@ QuickCheck == 2.4.*, ascii == 0.0.*, attempt == 0.3.*,- attoparsec == 0.9.*,+ attoparsec == 0.10.*, base == 4.*, base-unicode-symbols == 0.2.*, blaze-builder == 0.3.*, blaze-textual == 0.2.*, bytestring == 0.9.*, convertible-text == 0.4.*,+ failure == 0.1.*, tagged == 0.2.*, time == 1.2.* GHC-Options: