KCal Library
period.cpp
Go 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 *d = *other.d;
00098 return *this;
00099 }
00100
00101 KDateTime Period::start() const
00102 {
00103 return d->mStart;
00104 }
00105
00106 KDateTime Period::end() const
00107 {
00108 return d->mEnd;
00109 }
00110
00111 Duration Period::duration() const
00112 {
00113 if ( d->mHasDuration ) {
00114 return Duration( d->mStart, d->mEnd,
00115 d->mDailyDuration ? Duration::Days : Duration::Seconds );
00116 } else {
00117 return Duration( d->mStart, d->mEnd );
00118 }
00119 }
00120
00121 Duration Period::duration( Duration::Type type ) const
00122 {
00123 return Duration( d->mStart, d->mEnd, type );
00124 }
00125
00126 bool Period::hasDuration() const
00127 {
00128 return d->mHasDuration;
00129 }
00130
00131 void Period::shiftTimes( const KDateTime::Spec &oldSpec,
00132 const KDateTime::Spec &newSpec )
00133 {
00134 if ( oldSpec.isValid() && newSpec.isValid() && oldSpec != newSpec ) {
00135 d->mStart = d->mStart.toTimeSpec( oldSpec );
00136 d->mStart.setTimeSpec( newSpec );
00137 d->mEnd = d->mEnd.toTimeSpec( oldSpec );
00138 d->mEnd.setTimeSpec( newSpec );
00139 }
00140 }