postgresql-simple 0.1.4 → 0.1.4.1
raw patch · 5 files changed
+48/−30 lines, 5 filesdep ~basedep ~textPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, text
API changes (from Hackage documentation)
Files
- postgresql-simple.cabal +4/−3
- src/Database/PostgreSQL/Simple/FromField.hs +2/−11
- src/Database/PostgreSQL/Simple/Time.hs +31/−11
- src/Database/PostgreSQL/Simple/Time/Implementation.hs +6/−4
- test/Time.hs +5/−1
postgresql-simple.cabal view
@@ -1,5 +1,5 @@ Name: postgresql-simple-Version: 0.1.4+Version: 0.1.4.1 Synopsis: Mid-Level PostgreSQL client library Description: Mid-Level PostgreSQL client library, forked from mysql-simple.@@ -47,7 +47,8 @@ postgresql-libpq >= 0.6.2, old-locale, template-haskell,- text >= 0.11.1,+-- text >= 0.11.1,+ text == 0.11.1.13, time, transformers, vector@@ -64,7 +65,7 @@ source-repository this type: git location: http://github.com/lpsmith/postgresql-simple- tag: v0.1.4+ tag: v0.1.4.1 test-suite test type: exitcode-stdio-1.0
src/Database/PostgreSQL/Simple/FromField.hs view
@@ -194,16 +194,7 @@ fromField f dat = ST.unpack <$> fromField f dat instance FromField UTCTime where- fromField f =- case oid2builtin (typeOid f) of- Just TimestampWithTimeZone -> doIt id parseUTCTime- Just Timestamp -> doIt (localTimeToUTC utc) parseLocalTime -- deprecated- _ -> const $ returnError Incompatible f ""- where- doIt _finish _parse Nothing- = returnError UnexpectedNull f ""- doIt finish parse (Just bs)- = either (returnError ConversionFailed f) (pure . finish) (parse bs)+ fromField = ff TimestampWithTimeZone "UTCTime" parseUTCTime instance FromField ZonedTime where fromField = ff TimestampWithTimeZone "ZonedTime" parseZonedTime@@ -238,7 +229,7 @@ = left (UnexpectedNull (B8.unpack (typename f)) hsType "") | Just str <- mstr = case parse str of- Left msg -> left (ConversionFailed (B8.unpack (typename f)) hsType msg)+ Left _ -> left (ConversionFailed (B8.unpack (typename f)) hsType (B8.unpack str)) Right val -> return val {-# INLINE ff #-}
src/Database/PostgreSQL/Simple/Time.hs view
@@ -7,25 +7,45 @@ -- Stability: experimental -- -- Time types that supports positive and negative infinity. Also includes--- new time parsers and printers with better performance than GHC's time package.--- The parsers only understand the specific variant of ISO 8601 that PostgreSQL--- emits, and the printers attempt to duplicate this syntax. These likely have--- problems and shortcomings. Some that I know of:+-- new time parsers and printers with better performance than GHC's time+-- package. ----- 1. Timestamps with time zones before @1883-Nov-18 12:00:00-05@, the moment--- Standard Railway Time went live, cannot be parsed. This is because--- PostgreSQL will emit @1883-11-18 12:03:57-04:56:02@ instead of--- @1883-11-18 11:59:59-05@, and the timezone parser is incomplete.--- Timestamps without time zones do not have this problem.+-- The parsers only understand the specific variant of ISO 8601 that+-- PostgreSQL emits, and the printers attempt to duplicate this syntax.+-- Thus the @datestyle@ parameter for the connection must be set to @ISO@. ----- 2. Dates an times surrounding @1582-Feb-24@, the date the Gregorian+-- These parsers and printers likely have problems and shortcomings. Some+-- that I know of:+--+-- 1 @TimestampTZ@s before a timezone-dependent point in time cannot be+-- parsed, because the parsers can only handle timezone offsets of a+-- integer number of minutes. However, PostgreSQL will include seconds+-- in the offset, depending on the historical time standards for the city+-- identifying the time zone.+--+-- This boundary point often marks an event of some interest. In the US+-- for example, @timestamptz@s before @1883-Nov-18 12:00:00@ local time+-- cannot be parsed. This is the moment Standard Railway Time went live.+-- Concretely, PostgreSQL will emit @1883-11-18 12:03:57-04:56:02@+-- instead of @1883-11-18 11:59:59-05@ when the @timezone@ parameter+-- for the connection is set to @America/New_York@.+--+-- 2. Dates and times surrounding @1582-Feb-24@, the date the Gregorian -- Calendar was introduced, should be investigated for conversion errors. -- -- 3. Points in time Before Christ are not also not supported. For example, -- PostgreSQL will emit @0045-01-01 BC@ for a value of a @date@ type. -- This is the year that the Julian Calendar was adopted. ----- However, it should be noted that the old parsers also had these issues.+-- However, it should be noted that the old parsers also had issues 1 and 3.+-- Also, the new parsers now correctly handle time zones that include minutes+-- in their offset. Most notably, this includes all of India and parts of+-- Canada and Australia.+--+-- PostgreSQL uses the zoneinfo database for its time zone information.+-- You can read more about PostgreSQL's date and time types at+-- <http://www.postgresql.org/docs/9.1/static/datatype-datetime.html>,+-- and zoneinfo at <http://en.wikipedia.org/wiki/Tz_database>. -- ------------------------------------------------------------------------------
src/Database/PostgreSQL/Simple/Time/Implementation.hs view
@@ -136,10 +136,12 @@ getTimeZone :: A.Parser TimeZone getTimeZone = do- sign <- A.satisfy (\c -> c == '+' || c == '-')- offset <- digits "timezone"- let !minutes = 60 * if sign == '+' then offset else -offset- return $! minutesToTimeZone minutes+ sign <- A.satisfy (\c -> c == '+' || c == '-')+ hours <- digits "timezone"+ mins <- (A.char ':' *> digits "timezone minutes") <|> pure 0+ let !absset = 60 * hours + mins+ !offset = if sign == '+' then absset else -absset+ return $! minutesToTimeZone offset getZonedTime :: A.Parser ZonedTime getZonedTime = ZonedTime <$> getLocalTime <*> getTimeZone
test/Time.hs view
@@ -39,6 +39,10 @@ checkRoundTrips env execute_ conn "SET timezone TO 'Asia/Tokyo'" checkRoundTrips env+ execute_ conn "SET timezone TO 'Asia/Kathmandu'"+ checkRoundTrips env+ execute_ conn "SET timezone TO 'America/St_Johns'"+ checkRoundTrips env initializeTable :: TestEnv -> IO () initializeTable TestEnv{..} = withTransaction conn $ do@@ -48,7 +52,7 @@ let pop :: ByteString -> Double -> IO () = \x y -> replicateM_ numTests $ execute conn [sql| INSERT INTO testtime (y) VALUES- ('1900-01-01 00:00:00+00'::timestamptz+ ('1936-01-01 00:00:00+00'::timestamptz + ?::interval * ROUND(RANDOM() * ?)) |] (x,y) pop "1 microsecond" 6.3113904e15 pop "10 microseconds" 6.3113904e14