summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorJanne Anttila <janne.anttila@digia.com>2009-10-08 05:06:02 (GMT)
committerJanne Anttila <janne.anttila@digia.com>2009-10-08 09:40:23 (GMT)
commit2f7d1318d2dc63322a468d8c301ae718eaba0d03 (patch)
treed072691ed9fe53bad51cb9b12b1e10f93c948f03 /src/corelib
parent6612377889c6bff3dfb154dca268c8e6ea48ca8b (diff)
downloadQt-2f7d1318d2dc63322a468d8c301ae718eaba0d03.zip
Qt-2f7d1318d2dc63322a468d8c301ae718eaba0d03.tar.gz
Qt-2f7d1318d2dc63322a468d8c301ae718eaba0d03.tar.bz2
Workaround for OpenC daylight saving cache issue when using localtime_r.
OpenC incorrectly caches DST information between localtime_r calls, i.e. if previous call to localtime_r has been called for DST affected date, also the second call will be affected by DST even the date is such that DST should not be applied. The workaround is to call mktime with non-DST affected date before calling localtime_r. mktime call resets the OpenC internal DST cache to right value and localtime_r will return correct values. This commit can be reverted once Open C bug 9525 has been reverted. AutoTest: Fixes tst_QDateTime::totime_t Reviewed-by: Aleksandar Sasha Babic
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qdatetime.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 1b559cf..1277623 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -54,7 +54,6 @@
#ifndef Q_WS_WIN
#include <locale.h>
#endif
-
#include <time.h>
#if defined(Q_OS_WINCE)
#include "qfunctions_wince.h"
@@ -69,6 +68,31 @@
# define QDTPDEBUGN if (false) qDebug
#endif
+#if defined(Q_OS_SYMBIAN)
+ // Workaround for OpenC bug.
+
+ // OpenC incorrectly caches DST information between localtime_r
+ // calls, i.e. if previous call to localtime_r has been called for DST
+ // affected date, also the second call will be affected by DST even
+ // the date is such that DST should not be applied.
+
+ // The workaround is to call mktime with non-DST affected date before
+ // calling localtime_r. mktime call resets the OpenC internal DST cache
+ // to right value and localtime_r will return correct values.
+#define FIX_OPENC_DSTCACHE \
+ tm localTM; \
+ localTM.tm_sec = 0; \
+ localTM.tm_min = 0; \
+ localTM.tm_hour = 12; \
+ localTM.tm_mday = 1; \
+ localTM.tm_mon = 1; \
+ localTM.tm_year = 2002 - 1900; \
+ localTM.tm_isdst = -1; \
+ time_t temp = mktime(&localTM);
+#else
+#define FIX_OPENC_DSTCACHE
+#endif
+
#if defined(Q_WS_MAC)
#include <private/qcore_mac_p.h>
#endif
@@ -1138,6 +1162,7 @@ QDate QDate::currentDate()
// use the reentrant version of localtime() where available
tzset();
tm res;
+ FIX_OPENC_DSTCACHE
t = localtime_r(&ltime, &res);
#else
t = localtime(&ltime);
@@ -1834,12 +1859,13 @@ QTime QTime::currentTime()
// use the reentrant version of localtime() where available
tzset();
tm res;
+ FIX_OPENC_DSTCACHE
t = localtime_r(&ltime, &res);
#else
t = localtime(&ltime);
#endif
Q_CHECK_PTR(t);
-
+
ct.mds = MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + 1000 * t->tm_sec
+ tv.tv_usec / 1000;
#else
@@ -2887,6 +2913,7 @@ QDateTime QDateTime::currentDateTime()
// use the reentrant version of localtime() where available
tzset();
tm res;
+ FIX_OPENC_DSTCACHE
t = localtime_r(&ltime, &res);
#else
t = localtime(&ltime);
@@ -3704,6 +3731,7 @@ static QDateTimePrivate::Spec utcToLocal(QDate &date, QTime &time)
// use the reentrant version of localtime() where available
tzset();
tm res;
+ FIX_OPENC_DSTCACHE
brokenDown = localtime_r(&secsSince1Jan1970UTC, &res);
#elif defined(_MSC_VER) && _MSC_VER >= 1400
tm res;