summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendanHay <>2016-06-10 05:14:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2016-06-10 05:14:00 (GMT)
commit0cc51c2ee3761b1904098cd524177a368eaf9d6d (patch)
tree59ee2e646380531d0dc980aaf7118ea9da4e9965
parented067ec1c0a09567518f6e7412c313c7721c3cc5 (diff)
version 1.4.31.4.3
-rw-r--r--amazonka-core.cabal2
-rw-r--r--src/Network/AWS/Data/Time.hs28
-rw-r--r--test/Test/AWS/Data/Time.hs28
3 files changed, 18 insertions, 40 deletions
diff --git a/amazonka-core.cabal b/amazonka-core.cabal
index bc4aa2f..4bee585 100644
--- a/amazonka-core.cabal
+++ b/amazonka-core.cabal
@@ -1,5 +1,5 @@
name: amazonka-core
-version: 1.4.2
+version: 1.4.3
synopsis: Core data types and functionality for Amazonka libraries.
homepage: https://github.com/brendanhay/amazonka
bug-reports: https://github.com/brendanhay/amazonka/issues
diff --git a/src/Network/AWS/Data/Time.hs b/src/Network/AWS/Data/Time.hs
index 2b1805a..f8a3fac 100644
--- a/src/Network/AWS/Data/Time.hs
+++ b/src/Network/AWS/Data/Time.hs
@@ -37,6 +37,7 @@ module Network.AWS.Data.Time
import Control.Applicative
import Control.DeepSeq
import Data.Aeson
+import qualified Data.Aeson.Types as Aeson
import Data.Attoparsec.Text (Parser)
import qualified Data.Attoparsec.Text as AText
import qualified Data.ByteString.Char8 as BS
@@ -122,10 +123,6 @@ instance FromText ISO8601 where
-- Deprecated, but ensure compatibility with examples until further investigation can be done
<|> parseFormattedTime' (Tagged $ iso8601DateFormat (Just "%X%Q%Z"))
-instance FromText POSIX where
- parser = Time . posixSecondsToUTCTime . realToFrac
- <$> (parser :: Parser Scientific)
-
parseFormattedTime :: forall a. TimeFormat (Time a) => Parser (Time a)
parseFormattedTime = parseFormattedTime' format
@@ -162,19 +159,29 @@ instance FromXML RFC822 where parseXML = parseXMLText "RFC822"
instance FromXML ISO8601 where parseXML = parseXMLText "ISO8601"
instance FromXML AWSTime where parseXML = parseXMLText "AWSTime"
instance FromXML BasicTime where parseXML = parseXMLText "BasicTime"
-instance FromXML POSIX where parseXML = parseXMLText "POSIX"
instance FromJSON RFC822 where parseJSON = parseJSONText "RFC822"
instance FromJSON ISO8601 where parseJSON = parseJSONText "ISO8601"
instance FromJSON AWSTime where parseJSON = parseJSONText "AWSTime"
instance FromJSON BasicTime where parseJSON = parseJSONText "BasicTime"
+-- This is a somewhat unfortunate hack to support the bizzare apigateway
+-- occurence of returning ISO8601 or POSIX timestamps in unknown scenarios.
+--
+-- See: https://github.com/brendanhay/amazonka/issues/291
instance FromJSON POSIX where
- parseJSON = withScientific "POSIX"
- $ pure
- . Time
- . posixSecondsToUTCTime
- . realToFrac
+ parseJSON o = fmap convert (str o) <|> num o
+ where
+ str :: Value -> Aeson.Parser ISO8601
+ str = parseJSON
+
+ num :: Value -> Aeson.Parser POSIX
+ num = withScientific "POSIX"
+ ( pure
+ . Time
+ . posixSecondsToUTCTime
+ . realToFrac
+ )
instance ToByteString RFC822 where toBS = BS.pack . renderFormattedTime
instance ToByteString ISO8601 where toBS = BS.pack . renderFormattedTime
@@ -190,7 +197,6 @@ instance ToXML RFC822 where toXML = toXMLText
instance ToXML ISO8601 where toXML = toXMLText
instance ToXML AWSTime where toXML = toXMLText
instance ToXML BasicTime where toXML = toXMLText
-instance ToXML POSIX where toXML = toXMLText
instance ToJSON RFC822 where toJSON = toJSONText
instance ToJSON ISO8601 where toJSON = toJSONText
diff --git a/test/Test/AWS/Data/Time.hs b/test/Test/AWS/Data/Time.hs
index c3a56cc..3653a02 100644
--- a/test/Test/AWS/Data/Time.hs
+++ b/test/Test/AWS/Data/Time.hs
@@ -30,17 +30,6 @@ tests = testGroup "time"
, testFromText "aws"
"20141107T044213Z" (time :: AWSTime)
-
- , testGroup "posix"
- [ testFromText "integer"
- "1415335333" (time :: POSIX)
-
- , testFromText "double"
- "1415335333.000" (time :: POSIX)
-
- , testFromText "scientific"
- "1.415335333E9" (time :: POSIX)
- ]
]
, testGroup "serialise"
@@ -52,9 +41,6 @@ tests = testGroup "time"
, testToText "aws"
"20141107T044213Z" (time :: AWSTime)
-
- , testToText "posix"
- "1415335333" (time :: POSIX)
]
]
@@ -81,17 +67,6 @@ tests = testGroup "time"
, testFromXML "aws"
"20141107T044213Z" (time :: AWSTime)
-
- , testGroup "posix"
- [ testFromXML "integer"
- "1415335333" (time :: POSIX)
-
- , testFromXML "double"
- "1415335333.000" (time :: POSIX)
-
- , testFromXML "scientific"
- "1.415335333E9" (time :: POSIX)
- ]
]
, testGroup "serialise"
@@ -103,9 +78,6 @@ tests = testGroup "time"
, testToXML "aws"
"20141107T044213Z" (time :: AWSTime)
-
- , testToXML "posix"
- "1415335333" (time :: POSIX)
]
]