]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Add test for timestamptz timezone load behaviour
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 14 May 2021 17:42:29 +0000 (19:42 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 14 May 2021 17:43:40 +0000 (19:43 +0200)
tests/types/test_date.py

index 607eb45d9577558d7df34c6d15e05be4127173b4..e38651aa6d1d855de3bfe6bf7f16d406d9363710 100644 (file)
@@ -280,6 +280,25 @@ def test_load_datetimetz_tzname(conn, val, expr, datestyle_in, datestyle_out):
     assert cur.fetchone()[0] == as_dt(val)
 
 
+@pytest.mark.parametrize(
+    "tzname, expr, tzoff",
+    [
+        ("UTC", "2000-1-1", 0),
+        ("UTC", "2000-7-1", 0),
+        ("Europe/Rome", "2000-1-1", 3600),
+        ("Europe/Rome", "2000-7-1", 7200),
+        ("Europe/Rome", "1000-1-1", 2996),
+        ("NOSUCH0", "2000-1-1", 0),
+    ],
+)
+@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+def test_load_datetimetz_tz(conn, fmt_out, tzname, expr, tzoff):
+    conn.execute("select set_config('TimeZone', %s, true)", [tzname])
+    cur = conn.cursor(binary=fmt_out)
+    ts = cur.execute("select %s::timestamptz", [expr]).fetchone()[0]
+    assert ts.utcoffset().total_seconds() == tzoff
+
+
 @pytest.mark.parametrize(
     "val, type",
     [