diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-09-01 00:37:02 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-09-01 00:37:02 +0000 |
commit | cc29364f06178f8f6b457384f2ec37a042bd9d43 (patch) | |
tree | 7c77a3184c698bbf9d98cef09fb1ba8124daceba /libkcal/duration.cpp | |
parent | 4f6c584bacc8c3c694228f36ada3de77a76614a6 (diff) | |
download | tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.tar.gz tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.zip |
* Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch
* Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed
* Added journal read support to the CalDAV resource
* Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkcal/duration.cpp')
-rw-r--r-- | libkcal/duration.cpp | 140 |
1 files changed, 129 insertions, 11 deletions
diff --git a/libkcal/duration.cpp b/libkcal/duration.cpp index 0dfd8781c..fdb5a3701 100644 --- a/libkcal/duration.cpp +++ b/libkcal/duration.cpp @@ -19,42 +19,160 @@ Boston, MA 02110-1301, USA. */ -#include <kdebug.h> -#include <klocale.h> - #include "duration.h" using namespace KCal; Duration::Duration() { - mSeconds = 0; + mDuration = 0; } Duration::Duration( const TQDateTime &start, const TQDateTime &end ) { - mSeconds = start.secsTo( end ); + if ( start.time() == end.time() ) { + mDuration = start.daysTo( end ); + mDaily = true; + } else { + mDuration = start.secsTo( end ); + mDaily = false; + } +} + +Duration::Duration( const TQDateTime &start, const TQDateTime &end, Type type ) +{ + if ( type == Days ) { + mDuration = start.daysTo( end ); + if ( mDuration ) { + // Round down to whole number of days if necessary + if ( start < end ) { + if ( end.time() < start.time() ) { + --mDuration; + } + } else { + if ( end.time() > start.time() ) { + ++mDuration; + } + } + } + mDaily = true; + } else { + mDuration = start.secsTo( end ); + mDaily = false; + } +} + +Duration::Duration( int duration, Type type ) +{ + mDuration = duration; + mDaily = ( type == Days ); +} + +Duration::Duration( const Duration &duration ) +{ + mDuration = duration.mDuration; + mDaily = duration.mDaily; +} + +Duration &Duration::operator=( const Duration &duration ) +{ + // check for self assignment + if ( &duration == this ) { + return *this; + } + + mDuration = duration.mDuration; + mDaily = duration.mDaily; + + return *this; +} + +Duration::operator bool() const +{ + return mDuration; +} + +bool Duration::operator<( const Duration &other ) const +{ + if ( mDaily == other.mDaily ) { + // guard against integer overflow for two daily durations + return mDuration < other.mDuration; + } + return seconds() < other.seconds(); } -Duration::Duration( int seconds ) +bool Duration::operator==( const Duration &other ) const { - mSeconds = seconds; + // Note: daily and non-daily durations are always unequal, since a day's + // duration may differ from 24 hours if it happens to span a daylight saving + // time change. + return + mDuration == other.mDuration && + mDaily == other.mDaily; } -bool KCal::operator==( const Duration& d1, const Duration& d2 ) +Duration &Duration::operator+=( const Duration &other ) { - return ( d1.asSeconds() == d2.asSeconds() ); + if ( mDaily == other.mDaily ) { + mDuration += other.mDuration; + } else if ( mDaily ) { + mDuration = mDuration * 86400 + other.mDuration; + mDaily = false; + } else { + mDuration += other.mDuration + 86400; + } + return *this; } +Duration Duration::operator-() const +{ + return Duration( -mDuration, ( mDaily ? Days : Seconds ) ); +} +Duration &Duration::operator-=( const Duration &duration ) +{ + return operator+=( -duration ); +} + +Duration &Duration::operator*=( int value ) +{ + mDuration *= value; + return *this; +} + +Duration &Duration::operator/=( int value ) +{ + mDuration /= value; + return *this; +} TQDateTime Duration::end( const TQDateTime &start ) const { - return start.addSecs( mSeconds ); + return mDaily ? start.addDays( mDuration ) + : start.addSecs( mDuration ); +} +Duration::Type Duration::type() const +{ + return mDaily ? Days : Seconds; +} + +bool Duration::isDaily() const +{ + return mDaily; } int Duration::asSeconds() const { - return mSeconds; + return seconds(); +} + +int Duration::asDays() const +{ + return mDaily ? mDuration : mDuration / 86400; +} + +int Duration::value() const +{ + return mDuration; } |