KContacts

timezone.cpp
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
36 : d(new Private)
37{
38}
39
41 : d(new Private(offset, true))
42{
43}
44
46 : d(other.d)
47{
48}
49
53
54void TimeZone::setOffset(int offset)
55{
56 d->mOffset = offset;
57 d->mValid = true;
58}
59
61{
62 return d->mOffset;
63}
64
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
102{
103 QString str = QLatin1String("TimeZone {\n");
104 str += QStringLiteral(" Offset: %1\n").arg(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}
Time zone information.
Definition timezone.h:23
void setOffset(int offset)
Set time zone offset relative to UTC.
Definition timezone.cpp:54
int offset() const
Return offset in minutes relative to UTC.
Definition timezone.cpp:60
TimeZone()
Construct invalid time zone.
Definition timezone.cpp:35
QString toString() const
Return string representation of time zone offset.
Definition timezone.cpp:101
~TimeZone()
Destroys the time zone.
Definition timezone.cpp:50
bool isValid() const
Return, if this time zone object is valid.
Definition timezone.cpp:65
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.