summaryrefslogtreecommitdiffstats
path: root/src/versitorganizer/qtimezones_p.cpp
diff options
context:
space:
mode:
authorXizhi Zhu <xizhi.zhu@nokia.com>2011-09-06 08:06:04 +0300
committerQt by Nokia <qt-info@nokia.com>2011-09-06 10:20:21 +0200
commit166881722a78523569c3e15f990451f87371ae7a (patch)
tree27cd07d75465ffe67020602214647eeeec09f6f4 /src/versitorganizer/qtimezones_p.cpp
parent2201bae3a9e57652a46f2d798bfefb0da67df1f3 (diff)
Fix header files.
1) Private headers should not be included in public headers. 2) Use <> for public headers, and "" for private headers. Change-Id: I229ff85c1665dd95a3b16e82b397703035f4e198 Reviewed-on: http://codereview.qt.nokia.com/4239 Reviewed-by: Xizhi Zhu <xizhi.zhu@nokia.com> Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src/versitorganizer/qtimezones_p.cpp')
-rw-r--r--src/versitorganizer/qtimezones_p.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/versitorganizer/qtimezones_p.cpp b/src/versitorganizer/qtimezones_p.cpp
new file mode 100644
index 000000000..f441089dc
--- /dev/null
+++ b/src/versitorganizer/qtimezones_p.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtimezones_p.h"
+#include <qorganizer.h>
+#include <QDateTime>
+
+QOrganizerManager* TimeZone::getManager()
+{
+ // We use the memory engine to do time zone recurrence calculations
+ static QOrganizerManager* manager(new QOrganizerManager(QString::fromAscii("memory")));
+ return manager;
+}
+
+QDateTime TimeZone::convert(const QDateTime& dateTime) const
+{
+ Q_ASSERT(isValid());
+ QOrganizerManager* manager = getManager();
+ int offset = 100000; // impossible value
+ QDateTime latestPhase;
+ foreach(const TimeZonePhase& phase, mPhases) {
+ QOrganizerEvent event;
+ event.setStartDateTime(phase.startDateTime());
+ event.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << phase.recurrenceRule());
+ event.setRecurrenceDates(phase.recurrenceDates());
+ QList<QOrganizerItem> occurrences =
+ manager->itemOccurrences(event, phase.startDateTime(), dateTime, 500);
+ if (!occurrences.isEmpty()) {
+ QDateTime phaseStart(static_cast<QOrganizerEventOccurrence>(occurrences.last()).startDateTime());
+ if (phaseStart > latestPhase) {
+ latestPhase = phaseStart;
+ offset = phase.utcOffset();
+ }
+ }
+ }
+ QDateTime retn(dateTime);
+ retn.setTimeSpec(Qt::UTC);
+ if (offset >= -86400 && offset <= 86400) // offset must be within -24hours to +24hours
+ return retn.addSecs(-offset);
+ else
+ return retn;
+}
+
+QDateTime TimeZones::convert(const QDateTime& dateTime, const QString& tzid) const
+{
+ if (!mTimeZones.contains(tzid))
+ return QDateTime();
+ TimeZone tz = mTimeZones.value(tzid);
+ if (!tz.isValid())
+ return QDateTime();
+ return tz.convert(dateTime);
+}