duration.h
00001 /* 00002 This file is part of libkcal. 00003 00004 Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 #ifndef KCAL_DURATION_H 00022 #define KCAL_DURATION_H 00023 00024 #include <tqdatetime.h> 00025 00026 #include "libkcal_export.h" 00027 00028 namespace KCal { 00029 00033 class LIBKCAL_EXPORT Duration 00034 { 00035 public: 00039 enum Type { 00040 Seconds, 00041 Days 00042 }; 00043 00047 Duration(); 00048 00060 Duration( const TQDateTime &start, const TQDateTime &end ); 00061 00073 Duration( const TQDateTime &start, const TQDateTime &end, Type type ); 00074 00081 Duration( int duration, Type type = Seconds ); //krazy:exclude=explicit 00082 00088 Duration( const Duration &duration ); 00089 00095 Duration &operator=( const Duration &duration ); 00096 00100 operator bool() const; 00101 00105 bool operator!() const { return !operator bool(); } 00106 00111 bool operator<( const Duration &other ) const; 00112 00117 bool operator<=( const Duration &other ) const 00118 { return !other.operator<( *this ); } 00119 00120 00125 bool operator>( const Duration &other ) const 00126 { return other.operator<( *this ); } 00127 00132 bool operator>=( const Duration &other ) const 00133 { return !operator<( other ); } 00134 00142 bool operator==( const Duration &other ) const; 00143 00151 bool operator!=( const Duration &other ) const 00152 { return !operator==( other ); } 00153 00160 Duration &operator+=( const Duration &other ); 00161 00170 Duration operator+( const Duration &other ) const 00171 { return Duration( *this ) += other; } 00172 00176 Duration operator-() const; 00177 00185 Duration &operator-=( const Duration &other ); 00186 00195 Duration operator-( const Duration &other ) const 00196 { return Duration( *this ) += other; } 00197 00202 Duration &operator*=( int value ); 00203 00210 Duration operator*( int value ) const 00211 { return Duration( *this ) *= value; } 00212 00217 Duration &operator/=( int value ); 00218 00225 Duration operator/( int value ) const 00226 { return Duration( *this ) /= value; } 00227 00235 TQDateTime end( const TQDateTime &start ) const; 00236 00240 Type type() const; 00241 00246 bool isDaily() const; 00247 00251 int asSeconds() const; 00252 00258 int asDays() const; 00259 00265 int value() const; 00266 00267 private: 00268 int seconds() const { return mDaily ? mDuration * 86400 : mDuration; } 00269 int mDuration; 00270 bool mDaily; 00271 00272 class Private; 00273 Private *d; 00274 }; 00275 00276 } 00277 00278 #endif