Skip to content

Commit b7bd88a

Browse files
authored
Test roundtripping date from first century (#60)
* Allow time 1.10, 1.11, 1.12, 1.13 series * Test that date from first century can roundtrip
1 parent 761bd59 commit b7bd88a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

HDBC-postgresql.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Library
4545
Build-Depends: base >= 3 && < 5, mtl, HDBC>=2.2.0, parsec, utf8-string,
4646
bytestring, old-time, convertible
4747
if flag(minTime15)
48-
Build-Depends: time >= 1.5 && < 1.10
48+
Build-Depends: time >= 1.5 && < 1.14
4949
CPP-Options: -DMIN_TIME_15
5050
else
5151
Build-Depends: time < 1.5, old-locale
@@ -63,7 +63,7 @@ Executable runtests
6363
convertible, parsec, utf8-string,
6464
bytestring, old-time, base >= 4.6 && < 5.0, HDBC>=2.2.6
6565
if flag(minTime15)
66-
Build-Depends: time >= 1.5 && < 1.9
66+
Build-Depends: time >= 1.5 && < 1.14
6767
CPP-Options: -DMIN_TIME_15
6868
else
6969
Build-Depends: time < 1.5, old-locale

testsrc/TestSbasics.hs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module TestSbasics(tests) where
22
import Test.HUnit
3+
import Data.Convertible (convert)
34
import Data.List
5+
import Data.Time (UTCTime(UTCTime), fromGregorian)
46
import Database.HDBC
57
import TestUtils
68
import System.IO
@@ -153,6 +155,16 @@ testWithTransaction = dbTestCase (\dbh ->
153155
)
154156
where rows = map (\x -> [Just . show $ x]) [1..9]
155157

158+
testFirstCentury = dbTestCase $ \dbh ->
159+
do -- we use UTC to avoid Local Mean Time which the 'time' library can't handle
160+
runRaw dbh "SET TIMEZONE TO 'UTC';"
161+
select <- prepare dbh "SELECT ? :: timestamptz;"
162+
let time = UTCTime (fromGregorian 99 12 25) 0
163+
execute select [toSql (convert time :: SqlValue)]
164+
result <- fetchAllRows select
165+
assertEqual "first century year can roundtrip"
166+
time (fromSql $ head $ head result)
167+
156168
tests = TestList
157169
[
158170
TestLabel "openClosedb" openClosedb,
@@ -167,5 +179,6 @@ tests = TestList
167179
TestLabel "sFetchAllRows" testsFetchAllRows,
168180
TestLabel "basicTransactions" basicTransactions,
169181
TestLabel "withTransaction" testWithTransaction,
170-
TestLabel "dropTable" dropTable
182+
TestLabel "dropTable" dropTable,
183+
TestLabel "firstCentury" testFirstCentury
171184
]

0 commit comments

Comments
 (0)