From: Michael Marley Date: Mon, 20 Apr 2015 16:43:53 +0000 (-0400) Subject: Set the PostgreSQL session timezone to 'UTC' X-Git-Tag: travis-deploy-test~570^2 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=9a440b6a972595bc556f34504cdbb3ea56ca53fd;hp=585ef1dab1790c7edb7c73df801560ba6b7842d1;ds=sidebyside Set the PostgreSQL session timezone to 'UTC' With Qt5, the PostgreSQL driver will transparently convert times to the database's timezone before inserting. Because the default is 'localtime', this causes the local time to be stored in the DB instead of the UTC time. This in turn causes the time displayed in the client to be wrong by the same offset as that timezone's offset. To fix the issue, just make sure the PostgreSQL is in the 'UTC' timezone, so the passed UTC time will not be converted. --- diff --git a/src/core/postgresqlstorage.cpp b/src/core/postgresqlstorage.cpp index ca865704..68cf2544 100644 --- a/src/core/postgresqlstorage.cpp +++ b/src/core/postgresqlstorage.cpp @@ -136,6 +136,14 @@ bool PostgreSqlStorage::initDbSession(QSqlDatabase &db) return false; break; } + + // Set the PostgreSQL session timezone to UTC, since we want timestamps stored in UTC + QSqlQuery tzQuery = db.exec("SET timezone = 'UTC'"); + if (tzQuery.lastError().isValid()) { + quError() << "Failed to set timezone to UTC!"; + return false; + } + return true; }