/[gentoo-x86]/dev-haskell/hdbc-sqlite/files/TestTime.hs
Gentoo

Contents of /dev-haskell/hdbc-sqlite/files/TestTime.hs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download) (as text)
Sat Jun 2 05:56:43 2012 UTC (2 years, 1 month ago) by gienah
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-haskell
Bump hdbc-sqlite to 2.3.3.0

(Portage version: 2.1.10.63/cvs/Linux x86_64)

1 module TestTime(tests) where
2 import Test.HUnit
3 import Database.HDBC
4 import TestUtils
5 import Control.Exception
6 import Data.Time
7 import Data.Time.LocalTime
8 import Data.Time.Clock.POSIX
9 import Data.Maybe
10 import Data.Convertible
11 import SpecificDB
12 import System.Locale(defaultTimeLocale)
13 import Database.HDBC.Locale (iso8601DateFormat)
14 import qualified System.Time as ST
15
16 instance Eq ZonedTime where
17 a == b = zonedTimeToUTC a == zonedTimeToUTC b &&
18 zonedTimeZone a == zonedTimeZone b
19
20 testZonedTime :: ZonedTime
21 testZonedTime = fromJust $ parseTime defaultTimeLocale (iso8601DateFormat (Just "%T %z"))
22 "1989-08-01 15:33:01 -0500"
23
24 testZonedTimeFrac :: ZonedTime
25 testZonedTimeFrac = fromJust $ parseTime defaultTimeLocale (iso8601DateFormat (Just "%T%Q %z"))
26 "1989-08-01 15:33:01.536 -0500"
27
28
29 rowdata t = [[SqlInt32 100, toSql t, SqlNull]]
30
31 testDTType inputdata convToSqlValue = dbTestCase $ \dbh ->
32 do run dbh ("CREATE TABLE hdbctesttime (testid INTEGER PRIMARY KEY NOT NULL, \
33 \testvalue " ++ dateTimeTypeOfSqlValue value ++ ")") []
34 finally (testIt dbh) (do commit dbh
35 run dbh "DROP TABLE hdbctesttime" []
36 commit dbh
37 )
38 where testIt dbh =
39 do run dbh "INSERT INTO hdbctesttime (testid, testvalue) VALUES (?, ?)"
40 [iToSql 5, value]
41 commit dbh
42 r <- quickQuery' dbh "SELECT testid, testvalue FROM hdbctesttime" []
43 case r of
44 [[testidsv, testvaluesv]] ->
45 do assertEqual "testid" (5::Int) (fromSql testidsv)
46 assertEqual "testvalue" inputdata (fromSql testvaluesv)
47 value = convToSqlValue inputdata
48
49 mkTest label inputdata convfunc =
50 TestLabel label (testDTType inputdata convfunc)
51
52 tests = TestList $
53 ((TestLabel "Non-frac" $ testIt testZonedTime) :
54 if supportsFracTime then [TestLabel "Frac" $ testIt testZonedTimeFrac] else [])
55
56 testIt baseZonedTime =
57 TestList [mkTest "Day" baseDay toSql,
58 mkTest "TimeOfDay" baseTimeOfDay toSql,
59 mkTest "ZonedTimeOfDay" baseZonedTimeOfDay toSql,
60 mkTest "LocalTime" baseLocalTime toSql,
61 mkTest "ZonedTime" baseZonedTime toSql,
62 mkTest "UTCTime" baseUTCTime toSql,
63 mkTest "DiffTime" baseDiffTime toSql,
64 mkTest "POSIXTime" basePOSIXTime posixToSql,
65 mkTest "ClockTime" baseClockTime toSql,
66 mkTest "CalendarTime" baseCalendarTime toSql,
67 mkTest "TimeDiff" baseTimeDiff toSql
68 ]
69 where
70 baseDay :: Day
71 baseDay = localDay baseLocalTime
72
73 baseTimeOfDay :: TimeOfDay
74 baseTimeOfDay = localTimeOfDay baseLocalTime
75
76 baseZonedTimeOfDay :: (TimeOfDay, TimeZone)
77 baseZonedTimeOfDay = fromSql (SqlZonedTime baseZonedTime)
78
79 baseLocalTime :: LocalTime
80 baseLocalTime = zonedTimeToLocalTime baseZonedTime
81
82 baseUTCTime :: UTCTime
83 baseUTCTime = convert baseZonedTime
84
85 baseDiffTime :: NominalDiffTime
86 baseDiffTime = basePOSIXTime
87
88 basePOSIXTime :: POSIXTime
89 basePOSIXTime = convert baseZonedTime
90
91 baseTimeDiff :: ST.TimeDiff
92 baseTimeDiff = convert baseDiffTime
93
94 -- No fractional parts for these two
95
96 baseClockTime :: ST.ClockTime
97 baseClockTime = convert testZonedTime
98
99 baseCalendarTime :: ST.CalendarTime
100 baseCalendarTime = convert testZonedTime

  ViewVC Help
Powered by ViewVC 1.1.20