libkcal

duration.h
1/*
2 This file is part of libkcal.
3
4 Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21#ifndef KCAL_DURATION_H
22#define KCAL_DURATION_H
23
24#include <tqdatetime.h>
25
26#include "libkcal_export.h"
27
28namespace KCal {
29
33class LIBKCAL_EXPORT Duration
34{
35 public:
39 enum Type {
41 Days
42 };
43
47 Duration();
48
60 Duration( const TQDateTime &start, const TQDateTime &end );
61
73 Duration( const TQDateTime &start, const TQDateTime &end, Type type );
74
81 Duration( int duration, Type type = Seconds ); //krazy:exclude=explicit
82
88 Duration( const Duration &duration );
89
95 Duration &operator=( const Duration &duration );
96
100 operator bool() const;
101
105 bool operator!() const { return !operator bool(); }
106
111 bool operator<( const Duration &other ) const;
112
117 bool operator<=( const Duration &other ) const
118 { return !other.operator<( *this ); }
119
120
125 bool operator>( const Duration &other ) const
126 { return other.operator<( *this ); }
127
132 bool operator>=( const Duration &other ) const
133 { return !operator<( other ); }
134
142 bool operator==( const Duration &other ) const;
143
151 bool operator!=( const Duration &other ) const
152 { return !operator==( other ); }
153
160 Duration &operator+=( const Duration &other );
161
170 Duration operator+( const Duration &other ) const
171 { return Duration( *this ) += other; }
172
176 Duration operator-() const;
177
185 Duration &operator-=( const Duration &other );
186
195 Duration operator-( const Duration &other ) const
196 { return Duration( *this ) += other; }
197
202 Duration &operator*=( int value );
203
210 Duration operator*( int value ) const
211 { return Duration( *this ) *= value; }
212
217 Duration &operator/=( int value );
218
225 Duration operator/( int value ) const
226 { return Duration( *this ) /= value; }
227
235 TQDateTime end( const TQDateTime &start ) const;
236
240 Type type() const;
241
246 bool isDaily() const;
247
251 int asSeconds() const;
252
258 int asDays() const;
259
265 int value() const;
266
267 private:
268 int seconds() const { return mDaily ? mDuration * 86400 : mDuration; }
269 int mDuration;
270 bool mDaily;
271
272 class Private;
273 Private *d;
274};
275
276}
277
278#endif
This class represents a duration.
Definition: duration.h:34
bool operator>(const Duration &other) const
Returns true if this duration is greater than the other.
Definition: duration.h:125
Duration operator*(int value) const
Multiplies a duration by a value.
Definition: duration.h:210
Duration operator-(const Duration &other) const
Returns the difference between another duration and this.
Definition: duration.h:195
Duration operator/(int value) const
Divides a duration by a value.
Definition: duration.h:225
bool operator!() const
Returns true if this duration is zero.
Definition: duration.h:105
bool operator>=(const Duration &other) const
Returns true if this duration is greater than or equal to the other.
Definition: duration.h:132
bool operator<=(const Duration &other) const
Returns true if this duration is smaller than or equal to the other.
Definition: duration.h:117
bool operator!=(const Duration &other) const
Returns true if this duration is not equal to the other.
Definition: duration.h:151
Duration operator+(const Duration &other) const
Adds two durations.
Definition: duration.h:170
Type
The unit of time used to define the duration.
Definition: duration.h:39
@ Seconds
duration is a number of seconds
Definition: duration.h:40
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38