Skip to content

Commit

Permalink
Merge branch 'master' into 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsmith committed Jun 19, 2012
2 parents ecdbc74 + 8cfe75e commit f991193
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 24 deletions.
10 changes: 9 additions & 1 deletion CHANGES
@@ -1,3 +1,12 @@
Version 0.1.4.3: (2012-06-10)
* Fix language extensions for compatibility with GHC 7.0

Version 0.1.4.2: (2012-06-10)
* Fix a wayward dependency on Text.

Version 0.1.4.1: (2012-06-10)
* Added support for timezones with minutes in their UTC offset.

Version 0.1.4: (2012-06-10)
* Removed pcre-light dependency, courtesy of Joey Adams.

Expand Down Expand Up @@ -52,7 +61,6 @@ Version 0.1.1: (2012-05-06)


Version 0.1: (2012-05-04)

* Renamed several modules, typeclasses, and functions:

QueryParams (renderParams) -> ToRow (toRow)
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTORS
@@ -0,0 +1,6 @@
Bryan O'Sullivan <bos@serpentine.com>
Leon P Smith <leon@melding-monads.com>
Felipe Lessa <felipe.lessa@gmail.com>
Ozgun Ataman <ozataman@gmail.com>
Joey Adams <joeyadams3.14159@gmail.com>
Rekado <rekado@elephly.net>
4 changes: 2 additions & 2 deletions postgresql-simple.cabal
@@ -1,5 +1,5 @@
Name: postgresql-simple
Version: 0.1.4
Version: 0.1.4.3
Synopsis: Mid-Level PostgreSQL client library
Description:
Mid-Level PostgreSQL client library, forked from mysql-simple.
Expand Down Expand Up @@ -64,7 +64,7 @@ source-repository head
source-repository this
type: git
location: http://github.com/lpsmith/postgresql-simple
tag: v0.1.4
tag: v0.1.4.3

test-suite test
type: exitcode-stdio-1.0
Expand Down
6 changes: 4 additions & 2 deletions src/Database/PostgreSQL/Simple/FromField.hs
@@ -1,5 +1,7 @@
{-# LANGUAGE CPP, DeriveDataTypeable, DeriveFunctor, FlexibleInstances #-}
{-# LANGUAGE PatternGuards, ScopedTypeVariables #-}
{-# LANGUAGE CPP, DeriveDataTypeable, DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
{-# LANGUAGE PatternGuards, ScopedTypeVariables #-}

------------------------------------------------------------------------------
-- |
-- Module: Database.PostgreSQL.Simple.FromField
Expand Down
46 changes: 33 additions & 13 deletions src/Database/PostgreSQL/Simple/Time.hs
Expand Up @@ -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:
--
-- 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.
--
-- 2. Dates an times surrounding @1582-Feb-24@, the date the Gregorian
-- 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.
-- Thus the @datestyle@ parameter for the connection must be set to @ISO@.
--
-- 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>.
--
------------------------------------------------------------------------------

Expand Down
10 changes: 6 additions & 4 deletions src/Database/PostgreSQL/Simple/Time/Implementation.hs
Expand Up @@ -136,10 +136,12 @@ getLocalTimestamp = getUnbounded getLocalTime

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
Expand Down
3 changes: 2 additions & 1 deletion src/Database/PostgreSQL/Simple/ToField.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, FlexibleInstances #-}
{-# LANGUAGE DeriveDataTypeable, DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}

------------------------------------------------------------------------------
-- |
Expand Down
6 changes: 5 additions & 1 deletion test/Time.hs
Expand Up @@ -39,6 +39,10 @@ testTime env@TestEnv{..} = TestCase $ do
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
Expand All @@ -48,7 +52,7 @@ initializeTable TestEnv{..} = withTransaction conn $ do
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
Expand Down

0 comments on commit f991193

Please sign in to comment.