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

KCalCore Library

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 
period.h
This file is part of the API for handling calendar data and defines the Period class.
KCalCore::Duration
Represents a span of time measured in seconds or days.
Definition: duration.h:55
KCalCore::Duration::isDaily
bool isDaily() const
Returns whether the duration is specified in terms of days rather than seconds.
Definition: duration.cpp:195
KCalCore::Period::operator=
Period & operator=(const Period &other)
Sets this period equal to the other one.
Definition: period.cpp:100
KCalCore::Period
The period can be defined by either a start time and an end time or by a start time and a duration...
Definition: period.h:49
KCalCore::Period::duration
Duration duration() const
Returns the duration of the period.
Definition: period.cpp:121
KCalCore::Duration::Seconds
duration is a number of seconds
Definition: duration.h:62
KCalCore::Duration::Type
Type
The unit of time used to define the duration.
Definition: duration.h:61
KCalCore::Duration::Days
duration is a number of days
Definition: duration.h:63
KCalCore::Period::end
KDateTime end() const
Returns when this period ends.
Definition: period.cpp:116
KCalCore::operator>>
KCALCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalCore::Alarm::Ptr &)
Alarm deserializer.
Definition: alarm.cpp:863
KCalCore::Period::start
KDateTime start() const
Returns when this period starts.
Definition: period.cpp:111
KCalCore::Period::hasDuration
bool hasDuration() const
Returns true if this period has a set duration, false if it just has a start and an end...
Definition: period.cpp:136
KCalCore::Period::shiftTimes
void shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec)
Shift the times of the period so that they appear at the same clock time as before but in a new time ...
Definition: period.cpp:141
qHash
uint qHash(const KCalCore::Period &key)
Return a hash value for a Period argument.
Definition: period.cpp:169
KCalCore::Period::operator==
bool operator==(const Period &other) const
Returns true if this period is equal to the other one.
Definition: period.cpp:90
KCalCore::Period::operator<
bool operator<(const Period &other) const
Returns true if the start of this period is earlier than the start of the other one.
Definition: period.cpp:85
KCalCore::Period::~Period
~Period()
Destroys a period.
Definition: period.cpp:80
KCalCore::Period::Period
Period()
Constructs a period without a duration.
Definition: period.cpp:60
KCalCore::operator<<
KCALCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:853
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:57 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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