summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetime.cpp
diff options
context:
space:
mode:
authorRaphael Kubo da Costa <rakuco@FreeBSD.org>2014-02-02 23:42:12 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-07 18:58:02 +0100
commitcd681c45de5db2f8ca7cca913ec8615c2c7a950a (patch)
treee938f97c80530c172a336ad89c943540f8363361 /src/corelib/tools/qdatetime.cpp
parentb3fcac3e0cf9377645981d4ca9880a0849132bed (diff)
Correctly manipulate tm_gmtoff the way qt_timezone() needs.
Follow-up to 91d3298: qt_timezone() expects the number of seconds west of UTC, whereas tm_gmtoff returns the number of seconds east of UTC, and contrary to the timezone variable it is not oblivious to DST. We have to account for those two facts and make sure we return a value compatible with what timezone would have. Change-Id: Iacb9077f50d4c847ac09e5a7e952d0e4cd22da1b Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qdatetime.cpp')
-rw-r--r--src/corelib/tools/qdatetime.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 6d2cba7703..e38a5f569a 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -2208,7 +2208,17 @@ static int qt_timezone()
time_t clock = time(NULL);
struct tm t;
localtime_r(&clock, &t);
- return t.tm_gmtoff;
+ // QTBUG-36080 Workaround for systems without the POSIX timezone
+ // variable. This solution is not very efficient but fixing it is up to
+ // the libc implementations.
+ //
+ // tm_gmtoff has some important differences compared to the timezone
+ // variable:
+ // - It returns the number of seconds east of UTC, and we want the
+ // number of seconds west of UTC.
+ // - It also takes DST into account, so we need to adjust it to always
+ // get the Standard Time offset.
+ return -t.tm_gmtoff + (t.tm_isdst ? SECS_PER_HOUR : 0L);
#else
return timezone;
#endif // Q_OS_WIN