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()
51{
52}
53
54void TimeZone::setOffset(int offset)
55{
56 d->mOffset = offset;
57 d->mValid = true;
58}
59
60int TimeZone::offset() const
61{
62 return d->mOffset;
63}
64
65bool TimeZone::isValid() const
66{
67 return d->mValid;
68}
69
70bool TimeZone::operator==(const TimeZone &t) const
71{
72 if (!t.isValid() && !isValid()) {
73 return true;
74 }
75
76 if (!t.isValid() || !isValid()) {
77 return false;
78 }
79
80 if (t.d->mOffset == d->mOffset) {
81 return true;
82 }
83
84 return false;
85}
86
87bool TimeZone::operator!=(const TimeZone &t) const
88{
89 return !(*this == t);
90}
91
92TimeZone &TimeZone::operator=(const TimeZone &other)
93{
94 if (this != &other) {
95 d = other.d;
96 }
97
98 return *this;
99}
100
101QString TimeZone::toString() const
102{
103 QString str = QLatin1String("TimeZone {\n");
104 str += QStringLiteral(" Offset: %1\n").arg(a: d->mOffset);
105 str += QLatin1String("}\n");
106
107 return str;
108}
109
110QDataStream &KContacts::operator<<(QDataStream &s, const TimeZone &zone)
111{
112 return s << zone.d->mOffset << zone.d->mValid;
113}
114
115QDataStream &KContacts::operator>>(QDataStream &s, TimeZone &zone)
116{
117 s >> zone.d->mOffset >> zone.d->mValid;
118
119 return s;
120}
121

source code of kcontacts/src/timezone.cpp