period.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00033 #include "period.h"
00034
00035 #include <kdebug.h>
00036 #include <klocale.h>
00037
00038 using namespace KCal;
00039
00040
00041 class KCal::Period::Private
00042 {
00043 public:
00044 Private() : mHasDuration( false ) {}
00045 Private( const KDateTime &start, const KDateTime &end, bool hasDuration )
00046 : mStart( start ),
00047 mEnd( end ),
00048 mHasDuration( hasDuration )
00049 {}
00050 KDateTime mStart;
00051 KDateTime mEnd;
00052 bool mHasDuration;
00053 bool mDailyDuration;
00054 };
00055
00056
00057 Period::Period() : d( new KCal::Period::Private() )
00058 {
00059 }
00060
00061 Period::Period( const KDateTime &start, const KDateTime &end )
00062 : d( new KCal::Period::Private( start, end, false ) )
00063 {
00064 }
00065
00066 Period::Period( const KDateTime &start, const Duration &duration )
00067 : d( new KCal::Period::Private( start, duration.end( start ), true ) )
00068 {
00069 d->mDailyDuration = duration.isDaily();
00070 }
00071
00072 Period::Period( const Period &period )
00073 : d( new KCal::Period::Private( *period.d ) )
00074 {
00075 }
00076
00077 Period::~Period()
00078 {
00079 delete d;
00080 }
00081
00082 bool Period::operator<( const Period &other ) const
00083 {
00084 return d->mStart < other.d->mStart;
00085 }
00086
00087 bool Period::operator==( const Period &other ) const
00088 {
00089 return
00090 d->mStart == other.d->mStart &&
00091 d->mEnd == other.d->mEnd &&
00092 d->mHasDuration == other.d->mHasDuration;
00093 }
00094
00095 Period &Period::operator=( const Period &other )
00096 {
00097
00098 if ( &other == this ) {
00099 return *this;
00100 }
00101
00102 *d = *other.d;
00103 return *this;
00104 }
00105
00106 KDateTime Period::start() const
00107 {
00108 return d->mStart;
00109 }
00110
00111 KDateTime Period::end() const
00112 {
00113 return d->mEnd;
00114 }
00115
00116 Duration Period::duration() const
00117 {
00118 if ( d->mHasDuration ) {
00119 return Duration( d->mStart, d->mEnd,
00120 d->mDailyDuration ? Duration::Days : Duration::Seconds );
00121 } else {
00122 return Duration( d->mStart, d->mEnd );
00123 }
00124 }
00125
00126 Duration Period::duration( Duration::Type type ) const
00127 {
00128 return Duration( d->mStart, d->mEnd, type );
00129 }
00130
00131 bool Period::hasDuration() const
00132 {
00133 return d->mHasDuration;
00134 }
00135
00136 void Period::shiftTimes( const KDateTime::Spec &oldSpec,
00137 const KDateTime::Spec &newSpec )
00138 {
00139 if ( oldSpec.isValid() && newSpec.isValid() && oldSpec != newSpec ) {
00140 d->mStart = d->mStart.toTimeSpec( oldSpec );
00141 d->mStart.setTimeSpec( newSpec );
00142 d->mEnd = d->mEnd.toTimeSpec( oldSpec );
00143 d->mEnd.setTimeSpec( newSpec );
00144 }
00145 }
|