• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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
40using namespace KCalCore;
41
42//@cond PRIVATE
43class KCalCore::Period::Private
44{
45public:
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
60Period::Period() : d(new KCalCore::Period::Private())
61{
62}
63
64Period::Period(const KDateTime &start, const KDateTime &end)
65 : d(new KCalCore::Period::Private(start, end, false))
66{
67}
68
69Period::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
75Period::Period(const Period &period)
76 : d(new KCalCore::Period::Private(*period.d))
77{
78}
79
80Period::~Period()
81{
82 delete d;
83}
84
85bool Period::operator<(const Period &other) const
86{
87 return d->mStart < other.d->mStart;
88}
89
90bool 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
100Period &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
111KDateTime Period::start() const
112{
113 return d->mStart;
114}
115
116KDateTime Period::end() const
117{
118 return d->mEnd;
119}
120
121Duration 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
131Duration Period::duration(Duration::Type type) const
132{
133 return Duration(d->mStart, d->mEnd, type);
134}
135
136bool Period::hasDuration() const
137{
138 return d->mHasDuration;
139}
140
141void 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
152QDataStream &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
160QDataStream &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
169uint 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
KCalCore::Duration
Represents a span of time measured in seconds or days.
Definition: duration.h:56
KCalCore::Duration::isDaily
bool isDaily() const
Returns whether the duration is specified in terms of days rather than seconds.
Definition: duration.cpp:195
KCalCore::Duration::Type
Type
The unit of time used to define the duration.
Definition: duration.h:61
KCalCore::Duration::Days
@ Days
duration is a number of days
Definition: duration.h:63
KCalCore::Duration::Seconds
@ Seconds
duration is a number of seconds
Definition: duration.h:62
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:50
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::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::end
KDateTime end() const
Returns when this period ends.
Definition: period.cpp:116
KCalCore::Period::operator=
Period & operator=(const Period &other)
Sets this period equal to the other one.
Definition: period.cpp:100
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
KCalCore::Period::~Period
~Period()
Destroys a period.
Definition: period.cpp:80
KCalCore::Period::start
KDateTime start() const
Returns when this period starts.
Definition: period.cpp:111
KCalCore::Period::duration
Duration duration() const
Returns the duration of the period.
Definition: period.cpp:121
KCalCore::Period::Period
Period()
Constructs a period without a duration.
Definition: period.cpp:60
KCalCore
TODO: KDE5:
Definition: alarm.h:47
KCalCore::operator>>
KCALCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalCore::Alarm::Ptr &)
Alarm deserializer.
Definition: alarm.cpp:863
KCalCore::operator<<
KCALCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:853
qHash
static uint qHash(const KDateTime &dt)
Private class that helps to provide binary compatibility between releases.
Definition: occurrenceiterator.cpp:157
period.h
This file is part of the API for handling calendar data and defines the Period class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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