summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorJanne Koskinen <janne.p.koskinen@digia.com>2009-12-22 08:56:22 (GMT)
committerJanne Koskinen <janne.p.koskinen@digia.com>2009-12-22 08:56:22 (GMT)
commit2a20705f874ddad55282f22fabfe30927729ae50 (patch)
tree113719b815f3dc295e3b10e313ef686c1d944a34 /src/corelib
parent2c6749c38a2538639de86355856414b0d21317cf (diff)
downloadQt-2a20705f874ddad55282f22fabfe30927729ae50.zip
Qt-2a20705f874ddad55282f22fabfe30927729ae50.tar.gz
Qt-2a20705f874ddad55282f22fabfe30927729ae50.tar.bz2
Daylight savings time for Symbian.
Ask DST from Symbian's timezone server. This commit makes datetime functions slower. Small room for optimisation with keeping the server connection always open. Task-number: QTBUG-6859 Reviewed-by: Aleksandar Sasha Babic
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/corelib.pro2
-rw-r--r--src/corelib/tools/qdatetime.cpp60
2 files changed, 39 insertions, 23 deletions
diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro
index 9a15bf1..7f33791 100644
--- a/src/corelib/corelib.pro
+++ b/src/corelib/corelib.pro
@@ -35,4 +35,6 @@ symbian: {
# Workaroud for problems with paging this dll
MMP_RULES -= PAGED
MMP_RULES *= UNPAGED
+ # Timezone server
+ LIBS += -ltzclient
}
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index db6435e..240f0cf 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -75,6 +75,7 @@
#if defined(Q_OS_SYMBIAN)
#include <e32std.h>
+#include <tz.h>
#endif
QT_BEGIN_NAMESPACE
@@ -3721,23 +3722,32 @@ static QDateTimePrivate::Spec utcToLocal(QDate &date, QTime &time)
#elif defined(Q_OS_SYMBIAN)
// months and days are zero index based
_LIT(KUnixEpoch, "19700000:000000.000000");
- TTimeIntervalSeconds utcOffset = User::UTCOffset();
TTimeIntervalSeconds tTimeIntervalSecsSince1Jan1970UTC(secsSince1Jan1970UTC);
TTime epochTTime;
TInt err = epochTTime.Set(KUnixEpoch);
tm res;
if(err == KErrNone) {
TTime utcTTime = epochTTime + tTimeIntervalSecsSince1Jan1970UTC;
- utcTTime = utcTTime + utcOffset;
- TDateTime utcDateTime = utcTTime.DateTime();
- res.tm_sec = utcDateTime.Second();
- res.tm_min = utcDateTime.Minute();
- res.tm_hour = utcDateTime.Hour();
- res.tm_mday = utcDateTime.Day() + 1; // non-zero based index for tm struct
- res.tm_mon = utcDateTime.Month();
- res.tm_year = utcDateTime.Year() - 1900;
- res.tm_isdst = 0;
- brokenDown = &res;
+ TRAP(err,
+ RTz tz;
+ User::LeaveIfError(tz.Connect());
+ CleanupClosePushL(tz);
+ res.tm_isdst = tz.IsDaylightSavingOnL(*tz.GetTimeZoneIdL(),utcTTime);
+ User::LeaveIfError(tz.ConvertToLocalTime(utcTTime));
+ CleanupStack::PopAndDestroy(&tz));
+ if (KErrNone == err) {
+ TDateTime localDateTime = utcTTime.DateTime();
+ res.tm_sec = localDateTime.Second();
+ res.tm_min = localDateTime.Minute();
+ res.tm_hour = localDateTime.Hour();
+ res.tm_mday = localDateTime.Day() + 1; // non-zero based index for tm struct
+ res.tm_mon = localDateTime.Month();
+ res.tm_year = localDateTime.Year() - 1900;
+ // Symbian's timezone server doesn't know how to handle DST before year 1997
+ if (res.tm_year < 97)
+ res.tm_isdst = -1;
+ brokenDown = &res;
+ }
}
#elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
// use the reentrant version of localtime() where available
@@ -3812,23 +3822,27 @@ static void localToUtc(QDate &date, QTime &time, int isdst)
#elif defined(Q_OS_SYMBIAN)
// months and days are zero index based
_LIT(KUnixEpoch, "19700000:000000.000000");
- TTimeIntervalSeconds utcOffset = TTimeIntervalSeconds(0 - User::UTCOffset().Int());
TTimeIntervalSeconds tTimeIntervalSecsSince1Jan1970UTC(secsSince1Jan1970UTC);
TTime epochTTime;
TInt err = epochTTime.Set(KUnixEpoch);
tm res;
if(err == KErrNone) {
- TTime utcTTime = epochTTime + tTimeIntervalSecsSince1Jan1970UTC;
- utcTTime = utcTTime + utcOffset;
- TDateTime utcDateTime = utcTTime.DateTime();
- res.tm_sec = utcDateTime.Second();
- res.tm_min = utcDateTime.Minute();
- res.tm_hour = utcDateTime.Hour();
- res.tm_mday = utcDateTime.Day() + 1; // non-zero based index for tm struct
- res.tm_mon = utcDateTime.Month();
- res.tm_year = utcDateTime.Year() - 1900;
- res.tm_isdst = (int)isdst;
- brokenDown = &res;
+ TTime localTTime = epochTTime + tTimeIntervalSecsSince1Jan1970UTC;
+ RTz tz;
+ if (KErrNone == tz.Connect()) {
+ if (KErrNone == tz.ConvertToUniversalTime(localTTime)) {
+ TDateTime utcDateTime = localTTime.DateTime();
+ res.tm_sec = utcDateTime.Second();
+ res.tm_min = utcDateTime.Minute();
+ res.tm_hour = utcDateTime.Hour();
+ res.tm_mday = utcDateTime.Day() + 1; // non-zero based index for tm struct
+ res.tm_mon = utcDateTime.Month();
+ res.tm_year = utcDateTime.Year() - 1900;
+ res.tm_isdst = (int)isdst;
+ brokenDown = &res;
+ }
+ tz.Close();
+ }
}
#elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
// use the reentrant version of gmtime() where available