diff --git a/persistent-mongoDB/Database/Persist/MongoDB.hs b/persistent-mongoDB/Database/Persist/MongoDB.hs index ea6d92ab4..8976dc606 100644 --- a/persistent-mongoDB/Database/Persist/MongoDB.hs +++ b/persistent-mongoDB/Database/Persist/MongoDB.hs @@ -57,7 +57,6 @@ import Control.Monad.IO.Class (liftIO) import Data.Aeson (Value (Object), (.:), (.:?), (.!=)) import Control.Monad (mzero) import Control.Monad.Trans.Control (MonadBaseControl) -import Data.Time (zonedTimeToUTC) #ifdef DEBUG import FileLocation (debug) @@ -503,7 +502,7 @@ instance DB.Val PersistValue where val (PersistDouble x) = DB.Float x val (PersistBool x) = DB.Bool x val (PersistUTCTime x) = DB.UTC x - val (PersistZonedTime (ZT x)) = DB.UTC (zonedTimeToUTC x) + val (PersistZonedTime (ZT x)) = DB.String $ T.pack $ show x val (PersistNull) = DB.Null val (PersistList l) = DB.Array $ map DB.val l val (PersistMap m) = DB.Doc $ map (\(k, v)-> (DB.=:) k v) m diff --git a/persistent-mysql/Database/Persist/MySQL.hs b/persistent-mysql/Database/Persist/MySQL.hs index 44346c32f..5e05287ee 100644 --- a/persistent-mysql/Database/Persist/MySQL.hs +++ b/persistent-mysql/Database/Persist/MySQL.hs @@ -28,7 +28,6 @@ import Data.Function (on) import Data.IORef import Data.List (find, intercalate, sort, groupBy) import Data.Text (Text, pack) -import Data.Time.LocalTime (zonedTimeToUTC) import System.Environment (getEnvironment) import Data.Conduit @@ -196,7 +195,7 @@ instance MySQL.Param P where render (P (PersistDay d)) = MySQL.render d render (P (PersistTimeOfDay t)) = MySQL.render t render (P (PersistUTCTime t)) = MySQL.render t - render (P (PersistZonedTime (ZT t))) = MySQL.render $ zonedTimeToUTC t + render (P (PersistZonedTime (ZT t))) = MySQL.render $ show t render (P PersistNull) = MySQL.render MySQL.Null render (P (PersistList l)) = MySQL.render $ listToJSON l render (P (PersistMap m)) = MySQL.render $ mapToJSON m diff --git a/persistent-sqlite/Database/Sqlite.hs b/persistent-sqlite/Database/Sqlite.hs index e3d8e8fd0..7f01c44ab 100644 --- a/persistent-sqlite/Database/Sqlite.hs +++ b/persistent-sqlite/Database/Sqlite.hs @@ -34,7 +34,6 @@ import qualified Data.ByteString.Internal as BSI import Foreign import Foreign.C import Database.Persist.Store (PersistValue (..), listToJSON, mapToJSON, ZT (ZT)) -import Data.Time (zonedTimeToUTC) import Data.Text (Text, pack, unpack) import Data.Text.Encoding (encodeUtf8, decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) @@ -342,7 +341,7 @@ bind statement sqlData = do PersistDay d -> bindText statement parameterIndex $ pack $ show d PersistTimeOfDay d -> bindText statement parameterIndex $ pack $ show d PersistUTCTime d -> bindText statement parameterIndex $ pack $ show d - PersistZonedTime (ZT d) -> bindText statement parameterIndex $ pack $ show $ zonedTimeToUTC d + PersistZonedTime (ZT d) -> bindText statement parameterIndex $ pack $ show d PersistList l -> bindText statement parameterIndex $ listToJSON l PersistMap m -> bindText statement parameterIndex $ mapToJSON m PersistObjectId _ -> P.error "Refusing to serialize a PersistObjectId to a SQLite value" diff --git a/persistent-test/DataTypeTest.hs b/persistent-test/DataTypeTest.hs index 9237c4f41..b54a669d7 100644 --- a/persistent-test/DataTypeTest.hs +++ b/persistent-test/DataTypeTest.hs @@ -21,7 +21,7 @@ import Data.Text (Text) import qualified Data.Text as T import Data.ByteString (ByteString) import qualified Data.ByteString as S -import Data.Time (Day, TimeOfDay (..), UTCTime (..), fromGregorian) +import Data.Time (Day, TimeOfDay (..), UTCTime (..), fromGregorian, ZonedTime (..), LocalTime (..), TimeZone (..)) import System.Random (randomIO, randomRIO, Random) import Control.Applicative ((<$>), (<*>)) import Control.Monad (when) @@ -46,6 +46,7 @@ DataTypeTable no-json time TimeOfDay #endif utc UTCTime + zonedTime ZonedTime |] cleanDB :: PersistQuery b m => b m () @@ -77,6 +78,7 @@ specs = describe "data type specs" $ do check "time" dataTypeTableTime #endif check "utc" dataTypeTableUtc + check "zoned" dataTypeTableZonedTime -- Do a special check for Double since it may -- lose precision when serialized. @@ -99,6 +101,7 @@ randomValue = DataTypeTable <*> randomTime #endif <*> randomUTC + <*> randomZonedTime where forbidden = [NotAssigned, PrivateUse] asIO :: IO a -> IO a @@ -118,6 +121,12 @@ randomDay = fromGregorian <$> randomRIO (1900, 9400) <*> randomIO <*> randomIO randomUTC :: IO UTCTime randomUTC = UTCTime <$> randomDay <*> return 0 -- precision issues +randomZonedTime :: IO ZonedTime +randomZonedTime = ZonedTime <$> (LocalTime <$> randomDay <*> randomTime) <*> (TimeZone <$> randomRIO (-600, 600) <*> randomIO <*> return "") + +instance Eq ZonedTime where + a == b = show a == show b + randomTime :: IO TimeOfDay randomTime = TimeOfDay <$> randomRIO (0, 23) <*> randomRIO (0, 59)