LibreOffice Module tools (master) 1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
tools::Duration Class Reference

Duration in days and time. More...

#include <duration.hxx>

Collaboration diagram for tools::Duration:
[legend]

Public Member Functions

 Duration ()
 
 Duration (const ::DateTime &rStart, const ::DateTime &rEnd)
 Assumes that DateTime are normalized and there are no Time out-of-range field values. More...
 
 Duration (const Time &rStart, const Time &rEnd)
 Time can be a limited duration as well. More...
 
 Duration (double fTimeInDays)
 Difference in days, like DateTime()-DateTime(). More...
 
 Duration (sal_Int32 nDays, const Time &rTime)
 Time can be a limited duration as well and can have out-of-range values, it will be normalized. More...
 
 Duration (sal_Int32 nDays, sal_uInt32 nHours, sal_uInt32 nMinutes, sal_uInt32 nSeconds, sal_uInt64 nNanoseconds)
 Individual time values can be out-of-range, all will be normalized. More...
 
bool IsNegative () const
 
sal_Int32 GetDays () const
 
const TimeGetTime () const
 
double GetInDays () const
 
 operator bool () const
 Whether a duration is set. More...
 
Duration operator- () const
 Unary minus. More...
 
DurationAdd (const Duration &rDuration, bool &rbOverflow)
 Add a duration to this instance. More...
 
Duration Mult (sal_Int32 nMult, bool &rbOverflow) const
 Get multiple of duration. More...
 

Private Member Functions

 Duration (sal_Int32 nDays, sal_Int64 nTime)
 Internal days and Time values. More...
 
void Normalize (sal_uInt64 nHours, sal_uInt64 nMinutes, sal_uInt64 nSeconds, sal_uInt64 nNanoseconds, bool bNegative)
 Prerequisite: mnDays is already set. More...
 
void ApplyTime (sal_Int64 nNS)
 Prerequisite: mnDays is already correctly set and absolute value of nanoseconds less than one day. More...
 
void SetTimeDiff (const Time &rStart, const Time &rEnd)
 Prerequisite: mnDays is already correctly set and Time hour values are adjusted. More...
 

Private Attributes

Time maTime = Time(0)
 
sal_Int32 mnDays = 0
 

Detailed Description

Duration in days and time.

Can be negative in which case days is 0 and time is negative or both days and time are negative.

Definition at line 21 of file duration.hxx.

Constructor & Destructor Documentation

◆ Duration() [1/7]

tools::Duration::Duration ( )
inline

Definition at line 24 of file duration.hxx.

◆ Duration() [2/7]

tools::Duration::Duration ( const ::DateTime rStart,
const ::DateTime rEnd 
)

Assumes that DateTime are normalized and there are no Time out-of-range field values.

Definition at line 18 of file duration.cxx.

References SetTimeDiff().

◆ Duration() [3/7]

tools::Duration::Duration ( const Time rStart,
const Time rEnd 
)

Time can be a limited duration as well.

We don't cater for out-of-range minutes and seconds values here though.

Definition at line 24 of file duration.cxx.

References tools::Time::GetHour(), tools::Time::GetTime(), mnDays, tools::Time::SetHour(), and SetTimeDiff().

◆ Duration() [4/7]

tools::Duration::Duration ( double  fTimeInDays)
explicit

◆ Duration() [5/7]

tools::Duration::Duration ( sal_Int32  nDays,
const Time rTime 
)

Time can be a limited duration as well and can have out-of-range values, it will be normalized.

Sign of both days and Time must be equal unless one is 0.

Definition at line 89 of file duration.cxx.

References tools::Time::GetHour(), tools::Time::GetMin(), tools::Time::GetNanoSec(), tools::Time::GetSec(), tools::Time::GetTime(), and Normalize().

◆ Duration() [6/7]

tools::Duration::Duration ( sal_Int32  nDays,
sal_uInt32  nHours,
sal_uInt32  nMinutes,
sal_uInt32  nSeconds,
sal_uInt64  nNanoseconds 
)

Individual time values can be out-of-range, all will be normalized.

Additionally, the resulting time overall hour value is not restricted to sal_uInt16 like it is with Time, as values >=24 flow over into days. For a negative duration only a negative nDays can be given, thus a negative duration of less than one day is not possible.

Definition at line 97 of file duration.cxx.

References Normalize().

◆ Duration() [7/7]

tools::Duration::Duration ( sal_Int32  nDays,
sal_Int64  nTime 
)
private

Internal days and Time values.

Definition at line 104 of file duration.cxx.

Member Function Documentation

◆ Add()

Duration & tools::Duration::Add ( const Duration rDuration,
bool &  rbOverflow 
)

Add a duration to this instance.

Definition at line 191 of file duration.cxx.

References ApplyTime(), o3tl::checked_add(), o3tl::checked_sub(), tools::Time::GetNSFromTime(), maTime, mnDays, and tools::Time::nanoSecPerDay.

◆ ApplyTime()

void tools::Duration::ApplyTime ( sal_Int64  nNS)
private

Prerequisite: mnDays is already correctly set and absolute value of nanoseconds less than one day.

Definition at line 163 of file duration.cxx.

References tools::Time::GetTime(), tools::Time::MakeTimeFromNS(), maTime, mnDays, and tools::Time::nanoSecPerDay.

Referenced by Add(), Mult(), and SetTimeDiff().

◆ GetDays()

sal_Int32 tools::Duration::GetDays ( ) const
inline

Definition at line 51 of file duration.hxx.

Referenced by DateTime::operator+=().

◆ GetInDays()

double tools::Duration::GetInDays ( ) const
inline

Definition at line 53 of file duration.hxx.

References GetTime().

Referenced by DateTime::Sub().

◆ GetTime()

const Time & tools::Duration::GetTime ( ) const
inline

Definition at line 52 of file duration.hxx.

Referenced by DateTime::operator+=().

◆ IsNegative()

bool tools::Duration::IsNegative ( ) const
inline

Definition at line 50 of file duration.hxx.

Referenced by Mult().

◆ Mult()

Duration tools::Duration::Mult ( sal_Int32  nMult,
bool &  rbOverflow 
) const

◆ Normalize()

void tools::Duration::Normalize ( sal_uInt64  nHours,
sal_uInt64  nMinutes,
sal_uInt64  nSeconds,
sal_uInt64  nNanoseconds,
bool  bNegative 
)
private

◆ operator bool()

tools::Duration::operator bool ( ) const
inline

Whether a duration is set.

Definition at line 56 of file duration.hxx.

◆ operator-()

Duration tools::Duration::operator- ( void  ) const

Unary minus.

Definition at line 185 of file duration.cxx.

References tools::Time::GetTime(), maTime, and mnDays.

◆ SetTimeDiff()

void tools::Duration::SetTimeDiff ( const Time rStart,
const Time rEnd 
)
private

Prerequisite: mnDays is already correctly set and Time hour values are adjusted.

Definition at line 179 of file duration.cxx.

References ApplyTime(), and tools::Time::GetNSFromTime().

Referenced by Duration().

Member Data Documentation

◆ maTime

Time tools::Duration::maTime = Time(0)
private

Definition at line 84 of file duration.hxx.

Referenced by Add(), ApplyTime(), Duration(), Mult(), Normalize(), and operator-().

◆ mnDays

sal_Int32 tools::Duration::mnDays = 0
private

Definition at line 85 of file duration.hxx.

Referenced by Add(), ApplyTime(), Duration(), Mult(), Normalize(), and operator-().


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