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

KCal Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kcal
period.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcal 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 <kdebug.h>
36 #include <klocalizedstring.h>
37 
38 using namespace KCal;
39 
40 //@cond PRIVATE
41 class KCal::Period::Private
42 {
43  public:
44  Private() : mHasDuration( false ) {}
45  Private( const KDateTime &start, const KDateTime &end, bool hasDuration )
46  : mStart( start ),
47  mEnd( end ),
48  mHasDuration( hasDuration )
49  {}
50  KDateTime mStart; // period starting date/time
51  KDateTime mEnd; // period ending date/time
52  bool mHasDuration; // does period have a duration?
53  bool mDailyDuration; // duration is defined as number of days, not seconds
54 };
55 //@endcond
56 
57 Period::Period() : d( new KCal::Period::Private() )
58 {
59 }
60 
61 Period::Period( const KDateTime &start, const KDateTime &end )
62  : d( new KCal::Period::Private( start, end, false ) )
63 {
64 }
65 
66 Period::Period( const KDateTime &start, const Duration &duration )
67  : d( new KCal::Period::Private( start, duration.end( start ), true ) )
68 {
69  d->mDailyDuration = duration.isDaily();
70 }
71 
72 Period::Period( const Period &period )
73  : d( new KCal::Period::Private( *period.d ) )
74 {
75 }
76 
77 Period::~Period()
78 {
79  delete d;
80 }
81 
82 bool Period::operator<( const Period &other ) const
83 {
84  return d->mStart < other.d->mStart;
85 }
86 
87 bool Period::operator==( const Period &other ) const
88 {
89  return
90  d->mStart == other.d->mStart &&
91  d->mEnd == other.d->mEnd &&
92  d->mHasDuration == other.d->mHasDuration;
93 }
94 
95 Period &Period::operator=( const Period &other )
96 {
97  // check for self assignment
98  if ( &other == this ) {
99  return *this;
100  }
101 
102  *d = *other.d;
103  return *this;
104 }
105 
106 KDateTime Period::start() const
107 {
108  return d->mStart;
109 }
110 
111 KDateTime Period::end() const
112 {
113  return d->mEnd;
114 }
115 
116 Duration Period::duration() const
117 {
118  if ( d->mHasDuration ) {
119  return Duration( d->mStart, d->mEnd,
120  d->mDailyDuration ? Duration::Days : Duration::Seconds );
121  } else {
122  return Duration( d->mStart, d->mEnd );
123  }
124 }
125 
126 Duration Period::duration( Duration::Type type ) const
127 {
128  return Duration( d->mStart, d->mEnd, type );
129 }
130 
131 bool Period::hasDuration() const
132 {
133  return d->mHasDuration;
134 }
135 
136 void Period::shiftTimes( const KDateTime::Spec &oldSpec,
137  const KDateTime::Spec &newSpec )
138 {
139  if ( oldSpec.isValid() && newSpec.isValid() && oldSpec != newSpec ) {
140  d->mStart = d->mStart.toTimeSpec( oldSpec );
141  d->mStart.setTimeSpec( newSpec );
142  d->mEnd = d->mEnd.toTimeSpec( oldSpec );
143  d->mEnd.setTimeSpec( newSpec );
144  }
145 }
period.h
This file is part of the API for handling calendar data and defines the Period class.
KCal::Period::end
KDateTime end() const
Returns when this period ends.
Definition: period.cpp:111
KCal::Period::~Period
~Period()
Destroys a period.
Definition: period.cpp:77
KCal::Period::operator=
Period & operator=(const Period &other)
Sets this period equal to the other one.
Definition: period.cpp:95
KCal::Duration::Days
duration is a number of days
Definition: duration.h:60
KCal::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:136
KCal::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:82
KCal::Period::start
KDateTime start() const
Returns when this period starts.
Definition: period.cpp:106
KCal::Period::duration
Duration duration() const
Returns the duration of the period.
Definition: period.cpp:116
KCal::Duration::isDaily
bool isDaily() const
Returns whether the duration is specified in terms of days rather than seconds.
Definition: duration.cpp:194
KCal::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:131
KCal::Period::Period
Period()
Constructs a period without a duration.
Definition: period.cpp:57
KCal::Duration::Seconds
duration is a number of seconds
Definition: duration.h:59
KCal::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:47
KCal::Period::operator==
bool operator==(const Period &other) const
Returns true if this period is equal to the other one.
Definition: period.cpp:87
KCal::Duration::Type
Type
The unit of time used to define the duration.
Definition: duration.h:58
KCal::Duration
Represents a span of time measured in seconds or days.
Definition: duration.h:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

Skip menu "KCal 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