1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "timezone.h"
22
23#include <QtCore/QDataStream>
24#include <QtCore/QSharedData>
25
26using namespace KABC;
27
28class TimeZone::Private : public QSharedData
29{
30 public:
31 Private( int offset = 0, bool valid = false )
32 : mOffset( offset ), mValid( valid )
33 {
34 }
35
36 Private( const Private &other )
37 : QSharedData( other )
38 {
39 mOffset = other.mOffset;
40 mValid = other.mValid;
41 }
42
43 int mOffset;
44 bool mValid;
45};
46
47TimeZone::TimeZone()
48 : d( new Private )
49{
50}
51
52TimeZone::TimeZone( int offset )
53 : d( new Private( offset, true ) )
54{
55}
56
57TimeZone::TimeZone( const TimeZone &other )
58 : d( other.d )
59{
60}
61
62TimeZone::~TimeZone()
63{
64}
65
66void TimeZone::setOffset( int offset )
67{
68 d->mOffset = offset;
69 d->mValid = true;
70}
71
72int TimeZone::offset() const
73{
74 return d->mOffset;
75}
76
77bool TimeZone::isValid() const
78{
79 return d->mValid;
80}
81
82bool TimeZone::operator==( const TimeZone &t ) const
83{
84 if ( !t.isValid() && !isValid() ) {
85 return true;
86 }
87
88 if ( !t.isValid() || !isValid() ) {
89 return false;
90 }
91
92 if ( t.d->mOffset == d->mOffset ) {
93 return true;
94 }
95
96 return false;
97}
98
99bool TimeZone::operator!=( const TimeZone &t ) const
100{
101 return !( *this == t );
102}
103
104TimeZone &TimeZone::operator=( const TimeZone &other )
105{
106 if ( this != &other ) {
107 d = other.d;
108 }
109
110 return *this;
111}
112
113QString TimeZone::toString() const
114{
115 QString str;
116
117 str += QString::fromLatin1( "TimeZone {\n" );
118 str += QString::fromLatin1( " Offset: %1\n" ).arg( d->mOffset );
119 str += QString::fromLatin1( "}\n" );
120
121 return str;
122}
123
124QDataStream &KABC::operator<<( QDataStream &s, const TimeZone &zone )
125{
126 return s << zone.d->mOffset << zone.d->mValid;
127}
128
129QDataStream &KABC::operator>>( QDataStream &s, TimeZone &zone )
130{
131 s >> zone.d->mOffset >> zone.d->mValid;
132
133 return s;
134}
135