• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KCal Library

period.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of the kcal 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 <kdebug.h>
00036 #include <klocale.h>
00037 
00038 using namespace KCal;
00039 
00040 //@cond PRIVATE
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;    // period starting date/time
00051     KDateTime mEnd;      // period ending date/time
00052     bool mHasDuration;   // does period have a duration?
00053     bool mDailyDuration; // duration is defined as number of days, not seconds
00054 };
00055 //@endcond
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   d->mStart = d->mStart.toTimeSpec( oldSpec );
00135   d->mStart.setTimeSpec( newSpec );
00136   d->mEnd = d->mEnd.toTimeSpec( oldSpec );
00137   d->mEnd.setTimeSpec( newSpec );
00138 }

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal