set time zone to GMT for time zone tests
[postmodern.git] / cl-postgres / simple-date-tests.lisp
blobe0c48492c81a6361b569cb295661c9af36ddc5d0
2 (defpackage :cl-postgres-simple-date-tests
3 (:use :common-lisp :fiveam :cl-postgres :cl-postgres-error :simple-date)
4 (:export #:prompt-connection #:*test-connection*))
6 (in-package :cl-postgres-simple-date-tests)
8 (defparameter *test-connection* '("test" "test" "" "localhost"))
10 (defun prompt-connection (&optional (list *test-connection*))
11 (flet ((ask (name pos)
12 (format *query-io* "~a (enter to keep '~a'): " name (nth pos list))
13 (finish-output *query-io*)
14 (let ((answer (read-line *query-io*)))
15 (unless (string= answer "") (setf (nth pos list) answer)))))
16 (format *query-io* "~%To run this test, you must configure a database connection.~%")
17 (ask "Database name" 0)
18 (ask "User" 1)
19 (ask "Password" 2)
20 (ask "Hostname" 3)))
22 (defmacro with-test-connection (&body body)
23 `(let ((connection (apply 'open-database *test-connection*)))
24 (unwind-protect (progn ,@body)
25 (close-database connection))))
26 (def-suite :cl-postgres-simple-date)
27 (in-suite :cl-postgres-simple-date)
29 (test row-timestamp-without-time-zone-binary
30 (with-test-connection
31 (with-binary-row-values
32 (is (time= (caaar (exec-query connection "select row('2010-04-05 14:42:21.500'::timestamp without time zone)"
33 'list-row-reader))
34 (encode-timestamp 2010 4 5 14 42 21 500))))))
36 (test row-timestamp-with-time-zone-binary
37 (with-test-connection
38 (exec-query connection "set time zone 'GMT'")
39 (with-binary-row-values
40 (destructuring-bind (gmt pdt)
41 (caar
42 (exec-query
43 connection
44 (concatenate 'string
45 "select row('2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'GMT', "
46 " '2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'PST')")
47 'list-row-reader))
48 (is (time= gmt (encode-timestamp 2010 4 5 14 42 21 500)))
49 (is (time= pdt (encode-timestamp 2010 4 5 6 42 21 500)))))))
51 (test row-timestamp-without-time-zone-array-binary
52 (with-test-connection
53 (with-binary-row-values
54 (is (time= (elt (caaar (exec-query connection "select row(ARRAY['2010-04-05 14:42:21.500'::timestamp without time zone])"
55 'list-row-reader)) 0)
56 (encode-timestamp 2010 4 5 14 42 21 500))))))
58 (test row-time-binary
59 (with-test-connection
60 (with-binary-row-values
61 (is (time= (caaar (exec-query connection "select row('05:00'::time)"
62 'list-row-reader))
63 (encode-time-of-day 5 0))))))
65 (test row-timestamp-binary
66 (with-test-connection
67 (with-binary-row-values
68 (is (time= (caaar (exec-query connection "select row('2010-04-05 14:42:21.500'::timestamp)"
69 'list-row-reader))
70 (encode-timestamp 2010 4 5 14 42 21 500))))))