1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "timezone.h"
9
10#include <QDataStream>
11#include <QSharedData>
12
13using namespace KContacts;
14
15class Q_DECL_HIDDEN TimeZone::Private : public QSharedData
16{
17public:
18 Private(int offset = 0, bool valid = false)
19 : mOffset(offset)
20 , mValid(valid)
21 {
22 }
23
24 Private(const Private &other)
25 : QSharedData(other)
26 {
27 mOffset = other.mOffset;
28 mValid = other.mValid;
29 }
30
31 int mOffset;
32 bool mValid;
33};
34
35TimeZone::TimeZone()
36 : d(new Private)
37{
38}
39
40TimeZone::TimeZone(int offset)
41 : d(new Private(offset, true))
42{
43}
44
45TimeZone::TimeZone(const TimeZone &other)
46 : d(other.d)
47{
48}
49
50TimeZone::~TimeZone() = default;
51
52void TimeZone::setOffset(int offset)
53{
54 d->mOffset = offset;
55 d->mValid = true;
56}
57
58int TimeZone::offset() const
59{
60 return d->mOffset;
61}
62
63bool TimeZone::isValid() const
64{
65 return d->mValid;
66}
67
68bool TimeZone::operator==(const TimeZone &t) const
69{
70 if (!t.isValid() && !isValid()) {
71 return true;
72 }
73
74 if (!t.isValid() || !isValid()) {
75 return false;
76 }
77
78 if (t.d->mOffset == d->mOffset) {
79 return true;
80 }
81
82 return false;
83}
84
85bool TimeZone::operator!=(const TimeZone &t) const
86{
87 return !(*this == t);
88}
89
90TimeZone &TimeZone::operator=(const TimeZone &other)
91{
92 if (this != &other) {
93 d = other.d;
94 }
95
96 return *this;
97}
98
99QString TimeZone::toString() const
100{
101 QString str = QLatin1String("TimeZone {\n");
102 str += QStringLiteral(" Offset: %1\n").arg(a: d->mOffset);
103 str += QLatin1String("}\n");
104
105 return str;
106}
107
108QDataStream &KContacts::operator<<(QDataStream &s, const TimeZone &zone)
109{
110 return s << zone.d->mOffset << zone.d->mValid;
111}
112
113QDataStream &KContacts::operator>>(QDataStream &s, TimeZone &zone)
114{
115 s >> zone.d->mOffset >> zone.d->mValid;
116
117 return s;
118}
119

source code of kcontacts/src/timezone.cpp