From 9d4f3f8ce124023f704d5ca1a9e7a87029b43073 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Fri, 3 Sep 2021 20:24:54 +0200
Subject: Ensure that database timezone matches IRIS time zone

All travelynx and IRIS timestamps are Europe/Berlin. And the DateTime objects
know that they are Europe/Berlin. However, when inserting into a timestamp with
time zone column, Mojo::Pg or one of the backend DBI/DBD libraries does not
respect the time zone. So, UTC+1 or UTC+2 timestamps are treated as UTC+0,
resulting in major mayhem.
---
 lib/Travelynx.pm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 2618191..8ef5fbf 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -369,6 +369,15 @@ sub startup {
 			state $pg
 			  = Mojo::Pg->new("postgresql://${user}\@${host}:${port}/${dbname}")
 			  ->password($pw);
+
+			$pg->on(
+				connection => sub {
+					my ( $pg, $dbh ) = @_;
+					$dbh->do("set time zone 'Europe/Berlin'");
+				}
+			);
+
+			return $pg;
 		}
 	);
 
-- 
cgit v1.2.3