KCalCore Library
period.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the kcalcore library. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 Copyright (c) 2007 David Jarvie <software@astrojar.org.uk> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00033 #include "period.h" 00034 00035 #include <KDateTime> 00036 #include <KSystemTimeZone> 00037 00038 #include <QtCore/QHash> 00039 00040 using namespace KCalCore; 00041 00042 //@cond PRIVATE 00043 class KCalCore::Period::Private 00044 { 00045 public: 00046 Private() : mHasDuration( false ), mDailyDuration( false ) {} 00047 Private( const KDateTime &start, const KDateTime &end, bool hasDuration ) 00048 : mStart( start ), 00049 mEnd( end ), 00050 mHasDuration( hasDuration ), 00051 mDailyDuration( false ) 00052 {} 00053 KDateTime mStart; // period starting date/time 00054 KDateTime mEnd; // period ending date/time 00055 bool mHasDuration; // does period have a duration? 00056 bool mDailyDuration; // duration is defined as number of days, not seconds 00057 }; 00058 //@endcond 00059 00060 Period::Period() : d( new KCalCore::Period::Private() ) 00061 { 00062 } 00063 00064 Period::Period( const KDateTime &start, const KDateTime &end ) 00065 : d( new KCalCore::Period::Private( start, end, false ) ) 00066 { 00067 } 00068 00069 Period::Period( const KDateTime &start, const Duration &duration ) 00070 : d( new KCalCore::Period::Private( start, duration.end( start ), true ) ) 00071 { 00072 d->mDailyDuration = duration.isDaily(); 00073 } 00074 00075 Period::Period( const Period &period ) 00076 : d( new KCalCore::Period::Private( *period.d ) ) 00077 { 00078 } 00079 00080 Period::~Period() 00081 { 00082 delete d; 00083 } 00084 00085 bool Period::operator<( const Period &other ) const 00086 { 00087 return d->mStart < other.d->mStart; 00088 } 00089 00090 bool Period::operator==( const Period &other ) const 00091 { 00092 return 00093 ( ( d->mStart == other.d->mStart ) || 00094 ( !d->mStart.isValid() && !other.d->mStart.isValid() ) ) && 00095 ( ( d->mEnd == other.d->mEnd ) || 00096 ( !d->mEnd.isValid() && !other.d->mEnd.isValid() ) ) && 00097 d->mHasDuration == other.d->mHasDuration; 00098 } 00099 00100 Period &Period::operator=( const Period &other ) 00101 { 00102 // check for self assignment 00103 if ( &other == this ) { 00104 return *this; 00105 } 00106 00107 *d = *other.d; 00108 return *this; 00109 } 00110 00111 KDateTime Period::start() const 00112 { 00113 return d->mStart; 00114 } 00115 00116 KDateTime Period::end() const 00117 { 00118 return d->mEnd; 00119 } 00120 00121 Duration Period::duration() const 00122 { 00123 if ( d->mHasDuration ) { 00124 return Duration( d->mStart, d->mEnd, 00125 d->mDailyDuration ? Duration::Days : Duration::Seconds ); 00126 } else { 00127 return Duration( d->mStart, d->mEnd ); 00128 } 00129 } 00130 00131 Duration Period::duration( Duration::Type type ) const 00132 { 00133 return Duration( d->mStart, d->mEnd, type ); 00134 } 00135 00136 bool Period::hasDuration() const 00137 { 00138 return d->mHasDuration; 00139 } 00140 00141 void Period::shiftTimes( const KDateTime::Spec &oldSpec, 00142 const KDateTime::Spec &newSpec ) 00143 { 00144 if ( oldSpec.isValid() && newSpec.isValid() && oldSpec != newSpec ) { 00145 d->mStart = d->mStart.toTimeSpec( oldSpec ); 00146 d->mStart.setTimeSpec( newSpec ); 00147 d->mEnd = d->mEnd.toTimeSpec( oldSpec ); 00148 d->mEnd.setTimeSpec( newSpec ); 00149 } 00150 } 00151 00152 QDataStream &KCalCore::operator<<( QDataStream &stream, const KCalCore::Period &period ) 00153 { 00154 return stream << period.d->mStart 00155 << period.d->mEnd 00156 << period.d->mDailyDuration 00157 << period.d->mHasDuration; 00158 } 00159 00160 QDataStream &KCalCore::operator>>( QDataStream &stream, KCalCore::Period &period ) 00161 { 00162 stream >> period.d->mStart 00163 >> period.d->mEnd 00164 >> period.d->mDailyDuration 00165 >> period.d->mHasDuration; 00166 return stream; 00167 } 00168 00169 uint qHash( const KCalCore::Period &key ) 00170 { 00171 QString strToHash = key.start().toString(); 00172 if( key.hasDuration() ) { 00173 strToHash += key.duration(); 00174 } else { 00175 strToHash += key.end().toString(); 00176 } 00177 return qHash( strToHash ); 00178 } 00179
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:16:56 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:16:56 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.