| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtVersitOrganizer module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 2.1 or version 3 as published by the Free |
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 22 | ** following information to ensure the GNU Lesser General Public License |
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 25 | ** |
| 26 | ** As a special exception, The Qt Company gives you certain additional |
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 29 | ** |
| 30 | ** $QT_END_LICENSE$ |
| 31 | ** |
| 32 | ****************************************************************************/ |
| 33 | |
| 34 | #ifndef QTIMEZONES_P_H |
| 35 | #define QTIMEZONES_P_H |
| 36 | |
| 37 | // |
| 38 | // W A R N I N G |
| 39 | // ------------- |
| 40 | // |
| 41 | // This file is not part of the Qt API. It exists purely as an |
| 42 | // implementation detail. This header file may change from version to |
| 43 | // version without notice, or even be removed. |
| 44 | // |
| 45 | // We mean it. |
| 46 | // |
| 47 | |
| 48 | #include <QtCore/qdatetime.h> |
| 49 | #include <QtCore/qlist.h> |
| 50 | #include <QtCore/qhash.h> |
| 51 | |
| 52 | #include <QtOrganizer/qorganizerrecurrencerule.h> |
| 53 | |
| 54 | #include <QtVersitOrganizer/qversitorganizerglobal.h> |
| 55 | |
| 56 | QT_BEGIN_NAMESPACE_ORGANIZER |
| 57 | class QOrganizerManager; |
| 58 | QT_END_NAMESPACE_ORGANIZER |
| 59 | |
| 60 | QTORGANIZER_USE_NAMESPACE |
| 61 | |
| 62 | QT_BEGIN_NAMESPACE_VERSITORGANIZER |
| 63 | |
| 64 | class TimeZonePhase { |
| 65 | public: |
| 66 | TimeZonePhase() : mStandard(true), mUtcOffset(100000) {} // invalid offset |
| 67 | void setStandard(bool standard) { mStandard = standard; } |
| 68 | bool isStandard() const { return mStandard; } |
| 69 | void setUtcOffset(int offset) { mUtcOffset = offset; } |
| 70 | int utcOffset() const { return mUtcOffset; } |
| 71 | void setStartDateTime(const QDateTime& dateTime) { mStartDateTime = dateTime; } |
| 72 | QDateTime startDateTime() const { return mStartDateTime; } |
| 73 | void setRecurrenceRule(const QOrganizerRecurrenceRule& rrule) { mRecurrenceRule = rrule; } |
| 74 | QOrganizerRecurrenceRule recurrenceRule() const { return mRecurrenceRule; } |
| 75 | void setRecurrenceDates(const QSet<QDate>& rdates) { mRecurrenceDates = rdates; } |
| 76 | QSet<QDate> recurrenceDates() const { return mRecurrenceDates; } |
| 77 | bool isValid() const { |
| 78 | // offset must be within -24 hours to +24 hours |
| 79 | return mStartDateTime.isValid() && mUtcOffset < 86400 && mUtcOffset > -86400; |
| 80 | } |
| 81 | private: |
| 82 | bool mStandard; // true for STANDARD, false for DAYLIGHT |
| 83 | int mUtcOffset; // in seconds, the offset to apply after mStartDateTime |
| 84 | QDateTime mStartDateTime; // local time, when the phase comes into effect |
| 85 | QOrganizerRecurrenceRule mRecurrenceRule; |
| 86 | QSet<QDate> mRecurrenceDates; |
| 87 | }; |
| 88 | |
| 89 | class TimeZone { |
| 90 | public: |
| 91 | QDateTime convert(const QDateTime& dateTime) const; |
| 92 | void setTzid(const QString& tzid) { mTzid = tzid; } |
| 93 | QString tzid() const { return mTzid; } |
| 94 | void addPhase(const TimeZonePhase& phase) { mPhases.append(t: phase); } |
| 95 | bool isValid() const { |
| 96 | foreach (const TimeZonePhase& phase, mPhases) { |
| 97 | if (!phase.isValid()) return false; |
| 98 | } |
| 99 | return !mPhases.isEmpty(); |
| 100 | } |
| 101 | |
| 102 | private: |
| 103 | static QOrganizerManager* getManager(); |
| 104 | QString mTzid; |
| 105 | QList<TimeZonePhase> mPhases; |
| 106 | }; |
| 107 | |
| 108 | class TimeZones { |
| 109 | public: |
| 110 | QDateTime convert(const QDateTime& dateTime, const QString& tzid) const; |
| 111 | void addTimeZone(const TimeZone& timezone) { |
| 112 | if (!timezone.tzid().isEmpty()) |
| 113 | mTimeZones.insert(akey: timezone.tzid(), avalue: timezone); |
| 114 | } |
| 115 | private: |
| 116 | QHash<QString, TimeZone> mTimeZones; |
| 117 | }; |
| 118 | |
| 119 | QT_END_NAMESPACE_VERSITORGANIZER |
| 120 | |
| 121 | #endif // QTIMEZONES_P_H |
| 122 | |