• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KCalCore Library

  • kcalcore
period.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (c) 2007 David Jarvie <software@astrojar.org.uk>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
33 #include "period.h"
34 
35 #include <KDateTime>
36 #include <KSystemTimeZone>
37 
38 #include <QtCore/QHash>
39 
40 using namespace KCalCore;
41 
42 //@cond PRIVATE
43 class KCalCore::Period::Private
44 {
45  public:
46  Private() : mHasDuration( false ), mDailyDuration( false ) {}
47  Private( const KDateTime &start, const KDateTime &end, bool hasDuration )
48  : mStart( start ),
49  mEnd( end ),
50  mHasDuration( hasDuration ),
51  mDailyDuration( false )
52  {}
53  KDateTime mStart; // period starting date/time
54  KDateTime mEnd; // period ending date/time
55  bool mHasDuration; // does period have a duration?
56  bool mDailyDuration; // duration is defined as number of days, not seconds
57 };
58 //@endcond
59 
60 Period::Period() : d( new KCalCore::Period::Private() )
61 {
62 }
63 
64 Period::Period( const KDateTime &start, const KDateTime &end )
65  : d( new KCalCore::Period::Private( start, end, false ) )
66 {
67 }
68 
69 Period::Period( const KDateTime &start, const Duration &duration )
70  : d( new KCalCore::Period::Private( start, duration.end( start ), true ) )
71 {
72  d->mDailyDuration = duration.isDaily();
73 }
74 
75 Period::Period( const Period &period )
76  : d( new KCalCore::Period::Private( *period.d ) )
77 {
78 }
79 
80 Period::~Period()
81 {
82  delete d;
83 }
84 
85 bool Period::operator<( const Period &other ) const
86 {
87  return d->mStart < other.d->mStart;
88 }
89 
90 bool Period::operator==( const Period &other ) const
91 {
92  return
93  ( ( d->mStart == other.d->mStart ) ||
94  ( !d->mStart.isValid() && !other.d->mStart.isValid() ) ) &&
95  ( ( d->mEnd == other.d->mEnd ) ||
96  ( !d->mEnd.isValid() && !other.d->mEnd.isValid() ) ) &&
97  d->mHasDuration == other.d->mHasDuration;
98 }
99 
100 Period &Period::operator=( const Period &other )
101 {
102  // check for self assignment
103  if ( &other == this ) {
104  return *this;
105  }
106 
107  *d = *other.d;
108  return *this;
109 }
110 
111 KDateTime Period::start() const
112 {
113  return d->mStart;
114 }
115 
116 KDateTime Period::end() const
117 {
118  return d->mEnd;
119 }
120 
121 Duration Period::duration() const
122 {
123  if ( d->mHasDuration ) {
124  return Duration( d->mStart, d->mEnd,
125  d->mDailyDuration ? Duration::Days : Duration::Seconds );
126  } else {
127  return Duration( d->mStart, d->mEnd );
128  }
129 }
130 
131 Duration Period::duration( Duration::Type type ) const
132 {
133  return Duration( d->mStart, d->mEnd, type );
134 }
135 
136 bool Period::hasDuration() const
137 {
138  return d->mHasDuration;
139 }
140 
141 void Period::shiftTimes( const KDateTime::Spec &oldSpec,
142  const KDateTime::Spec &newSpec )
143 {
144  if ( oldSpec.isValid() && newSpec.isValid() && oldSpec != newSpec ) {
145  d->mStart = d->mStart.toTimeSpec( oldSpec );
146  d->mStart.setTimeSpec( newSpec );
147  d->mEnd = d->mEnd.toTimeSpec( oldSpec );
148  d->mEnd.setTimeSpec( newSpec );
149  }
150 }
151 
152 QDataStream &KCalCore::operator<<( QDataStream &stream, const KCalCore::Period &period )
153 {
154  return stream << period.d->mStart
155  << period.d->mEnd
156  << period.d->mDailyDuration
157  << period.d->mHasDuration;
158 }
159 
160 QDataStream &KCalCore::operator>>( QDataStream &stream, KCalCore::Period &period )
161 {
162  stream >> period.d->mStart
163  >> period.d->mEnd
164  >> period.d->mDailyDuration
165  >> period.d->mHasDuration;
166  return stream;
167 }
168 
169 uint qHash( const KCalCore::Period &key )
170 {
171  QString strToHash = key.start().toString();
172  if ( key.hasDuration() ) {
173  strToHash += key.duration();
174  } else {
175  strToHash += key.end().toString();
176  }
177  return qHash( strToHash );
178 }
179 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:24:52 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalCore Library

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

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal