KContacts

timezone.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2001 Cornelius Schumacher <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "timezone.h"
9 
10 #include <QDataStream>
11 #include <QSharedData>
12 
13 using namespace KContacts;
14 
15 class Q_DECL_HIDDEN TimeZone::Private : public QSharedData
16 {
17 public:
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 
51 {
52 }
53 
55 {
56  d->mOffset = offset;
57  d->mValid = true;
58 }
59 
60 int TimeZone::offset() const
61 {
62  return d->mOffset;
63 }
64 
65 bool TimeZone::isValid() const
66 {
67  return d->mValid;
68 }
69 
70 bool 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 
87 bool TimeZone::operator!=(const TimeZone &t) const
88 {
89  return !(*this == t);
90 }
91 
92 TimeZone &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 
110 QDataStream &KContacts::operator<<(QDataStream &s, const TimeZone &zone)
111 {
112  return s << zone.d->mOffset << zone.d->mValid;
113 }
114 
115 QDataStream &KContacts::operator>>(QDataStream &s, TimeZone &zone)
116 {
117  s >> zone.d->mOffset >> zone.d->mValid;
118 
119  return s;
120 }
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()
Destroys the time zone.
Definition: timezone.cpp:50
QString toString() const
Return string representation of time zone offset.
Definition: timezone.cpp:101
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isValid() const
Return, if this time zone object is valid.
Definition: timezone.cpp:65
Time zone information.
Definition: timezone.h:21
TimeZone()
Construct invalid time zone.
Definition: timezone.cpp:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Aug 6 2020 22:54:05 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.