libkcal

KCal::Duration Class Reference

#include <duration.h>

Public Types

enum  Type { Seconds , Days }
 

Public Member Functions

 Duration ()
 
 Duration (const TQDateTime &start, const TQDateTime &end)
 
 Duration (const TQDateTime &start, const TQDateTime &end, Type type)
 
 Duration (int duration, Type type=Seconds)
 
 Duration (const Duration &duration)
 
Durationoperator= (const Duration &duration)
 
 operator bool () const
 
bool operator! () const
 
bool operator< (const Duration &other) const
 
bool operator<= (const Duration &other) const
 
bool operator> (const Duration &other) const
 
bool operator>= (const Duration &other) const
 
bool operator== (const Duration &other) const
 
bool operator!= (const Duration &other) const
 
Durationoperator+= (const Duration &other)
 
Duration operator+ (const Duration &other) const
 
Duration operator- () const
 
Durationoperator-= (const Duration &other)
 
Duration operator- (const Duration &other) const
 
Durationoperator*= (int value)
 
Duration operator* (int value) const
 
Durationoperator/= (int value)
 
Duration operator/ (int value) const
 
TQDateTime end (const TQDateTime &start) const
 
Type type () const
 
bool isDaily () const
 
int asSeconds () const
 
int asDays () const
 
int value () const
 

Detailed Description

This class represents a duration.

Definition at line 33 of file duration.h.

Member Enumeration Documentation

◆ Type

The unit of time used to define the duration.

Enumerator
Seconds 

duration is a number of seconds

Days 

duration is a number of days

Definition at line 39 of file duration.h.

Constructor & Destructor Documentation

◆ Duration() [1/5]

Duration::Duration ( )

Constructs a duration of 0 seconds.

Definition at line 26 of file duration.cpp.

◆ Duration() [2/5]

Duration::Duration ( const TQDateTime &  start,
const TQDateTime &  end 
)

Constructs a duration from start to end.

If the time of day in start and end is equal, and their time specifications (i.e. time zone etc.) are the same, the duration will be set in terms of days. Otherwise, the duration will be set in terms of seconds.

Parameters
startis the time the duration begins.
endis the time the duration ends.

Definition at line 31 of file duration.cpp.

◆ Duration() [3/5]

Duration::Duration ( const TQDateTime &  start,
const TQDateTime &  end,
Type  type 
)

Constructs a duration from start to end.

If type is Days, and the time of day in start's time zone differs between start and end, the duration will be rounded down to the nearest whole number of days.

Parameters
startis the time the duration begins.
endis the time the duration ends.
typethe unit of time to use (seconds or days)

Definition at line 42 of file duration.cpp.

◆ Duration() [4/5]

Duration::Duration ( int  duration,
Type  type = Seconds 
)

Constructs a duration with a number of seconds or days.

Parameters
durationthe number of seconds or days in the duration
typethe unit of time to use (seconds or days)

Definition at line 65 of file duration.cpp.

◆ Duration() [5/5]

Duration::Duration ( const Duration duration)

Constructs a duration by copying another duration object.

Parameters
durationis the duration to copy.

Definition at line 71 of file duration.cpp.

Member Function Documentation

◆ asDays()

int Duration::asDays ( ) const

Returns the length of the duration in days.

If the duration is not an exact number of days, it is rounded down to return the number of whole days.

Definition at line 170 of file duration.cpp.

◆ asSeconds()

int Duration::asSeconds ( ) const

Returns the length of the duration in seconds.

Definition at line 165 of file duration.cpp.

◆ end()

TQDateTime Duration::end ( const TQDateTime &  start) const

Computes a duration end time by adding the number of seconds or days in the duration to the specified start time.

Parameters
startis the start time.
Returns
end time.

Definition at line 150 of file duration.cpp.

◆ isDaily()

bool Duration::isDaily ( ) const

Returns whether the duration is specified in terms of days rather than seconds.

Definition at line 160 of file duration.cpp.

◆ operator bool()

Duration::operator bool ( ) const

Returns true if this duration is non-zero.

Definition at line 90 of file duration.cpp.

◆ operator!()

bool KCal::Duration::operator! ( ) const
inline

Returns true if this duration is zero.

Definition at line 105 of file duration.h.

◆ operator!=()

bool KCal::Duration::operator!= ( const Duration other) const
inline

Returns true if this duration is not equal to the other.

Daily and non-daily durations are always considered unequal, since a day's duration may differ from 24 hours if it happens to span a daylight saving time change.

Parameters
otheris the other duration to compare.

Definition at line 151 of file duration.h.

◆ operator*()

Duration KCal::Duration::operator* ( int  value) const
inline

Multiplies a duration by a value.

Parameters
valuevalue to multiply by
Returns
resultant duration

Definition at line 210 of file duration.h.

◆ operator*=()

Duration & Duration::operator*= ( int  value)

Multiplies this duration by a value.

Parameters
valuevalue to multiply by

Definition at line 138 of file duration.cpp.

◆ operator+()

Duration KCal::Duration::operator+ ( const Duration other) const
inline

Adds two durations.

If one is in terms of days and the other in terms of seconds, the result is in terms of seconds.

Parameters
otherthe other duration to add
Returns
combined duration

Definition at line 170 of file duration.h.

◆ operator+=()

Duration & Duration::operator+= ( const Duration other)

Adds another duration to this one.

If one is in terms of days and the other in terms of seconds, the result is in terms of seconds.

Parameters
otherthe other duration to add

Definition at line 115 of file duration.cpp.

◆ operator-() [1/2]

Duration Duration::operator- ( ) const

Returns the negative of this duration.

Definition at line 128 of file duration.cpp.

◆ operator-() [2/2]

Duration KCal::Duration::operator- ( const Duration other) const
inline

Returns the difference between another duration and this.

If one is in terms of days and the other in terms of seconds, the result is in terms of seconds.

Parameters
otherthe other duration to subtract
Returns
difference in durations

Definition at line 195 of file duration.h.

◆ operator-=()

Duration & Duration::operator-= ( const Duration other)

Subtracts another duration from this one.

If one is in terms of days and the other in terms of seconds, the result is in terms of seconds.

Parameters
otherthe other duration to subtract

Definition at line 133 of file duration.cpp.

◆ operator/()

Duration KCal::Duration::operator/ ( int  value) const
inline

Divides a duration by a value.

Parameters
valuevalue to divide by
Returns
resultant duration

Definition at line 225 of file duration.h.

◆ operator/=()

Duration & Duration::operator/= ( int  value)

Divides this duration by a value.

Parameters
valuevalue to divide by

Definition at line 144 of file duration.cpp.

◆ operator<()

bool Duration::operator< ( const Duration other) const

Returns true if this duration is smaller than the other.

Parameters
otheris the other duration to compare.

Definition at line 95 of file duration.cpp.

◆ operator<=()

bool KCal::Duration::operator<= ( const Duration other) const
inline

Returns true if this duration is smaller than or equal to the other.

Parameters
otheris the other duration to compare.

Definition at line 117 of file duration.h.

◆ operator=()

Duration & Duration::operator= ( const Duration duration)

Sets this duration equal to duration.

Parameters
durationis the duration to copy.

Definition at line 77 of file duration.cpp.

◆ operator==()

bool Duration::operator== ( const Duration other) const

Returns true if this duration is equal to the other.

Daily and non-daily durations are always considered unequal, since a day's duration may differ from 24 hours if it happens to span a daylight saving time change.

Parameters
otherthe other duration to compare

Definition at line 104 of file duration.cpp.

◆ operator>()

bool KCal::Duration::operator> ( const Duration other) const
inline

Returns true if this duration is greater than the other.

Parameters
otheris the other duration to compare.

Definition at line 125 of file duration.h.

◆ operator>=()

bool KCal::Duration::operator>= ( const Duration other) const
inline

Returns true if this duration is greater than or equal to the other.

Parameters
otheris the other duration to compare.

Definition at line 132 of file duration.h.

◆ type()

Duration::Type Duration::type ( ) const

Returns the time units (seconds or days) used to specify the duration.

Definition at line 155 of file duration.cpp.

◆ value()

int Duration::value ( ) const

Returns the length of the duration in seconds or days.

Returns
if isDaily(), duration in days, else duration in seconds

Definition at line 175 of file duration.cpp.


The documentation for this class was generated from the following files: