LibreOffice Module tools (master) 1
|
Duration in days and time. More...
#include <duration.hxx>
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 Time & | GetTime () const |
double | GetInDays () const |
operator bool () const | |
Whether a duration is set. More... | |
Duration | operator- () const |
Unary minus. More... | |
Duration & | Add (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 |
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.
|
inline |
Definition at line 24 of file duration.hxx.
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().
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().
|
explicit |
Difference in days, like DateTime()-DateTime().
Definition at line 50 of file duration.cxx.
References abs(), tools::Time::GetTime(), tools::Time::MakeTimeFromNS(), maTime, mnDays, tools::Time::nanoSecPerDay, and tools::Time::nanoSecPerSec.
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().
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().
|
private |
Internal days and Time values.
Definition at line 104 of file duration.cxx.
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.
|
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().
|
inline |
Definition at line 51 of file duration.hxx.
Referenced by DateTime::operator+=().
|
inline |
|
inline |
Definition at line 52 of file duration.hxx.
Referenced by DateTime::operator+=().
|
inline |
Definition at line 50 of file duration.hxx.
Referenced by Mult().
Duration tools::Duration::Mult | ( | sal_Int32 | nMult, |
bool & | rbOverflow | ||
) | const |
Get multiple of duration.
Definition at line 210 of file duration.cxx.
References ApplyTime(), o3tl::checked_add(), o3tl::checked_multiply(), tools::Time::GetHour(), tools::Time::GetMin(), tools::Time::GetNanoSec(), tools::Time::GetNSFromTime(), tools::Time::GetSec(), tools::Time::GetTime(), tools::Time::hourPerDay, IsNegative(), maTime, tools::Time::minutePerHour, mnDays, tools::Time::nanoSecPerDay, tools::Time::nanoSecPerSec, SAL_MAX_INT32, SAL_MIN_INT32, and tools::Time::secondPerMinute.
|
private |
Prerequisite: mnDays is already set.
Definition at line 110 of file duration.cxx.
References o3tl::checked_add(), tools::Time::GetTime(), tools::Time::hourPerDay, maTime, tools::Time::minutePerHour, mnDays, tools::Time::nanoSecPerSec, SAL_MAX_INT32, SAL_MIN_INT32, and tools::Time::secondPerMinute.
Referenced by Duration().
|
inline |
Whether a duration is set.
Definition at line 56 of file duration.hxx.
Duration tools::Duration::operator- | ( | void | ) | const |
Unary minus.
Definition at line 185 of file duration.cxx.
References tools::Time::GetTime(), maTime, and mnDays.
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().
Definition at line 84 of file duration.hxx.
Referenced by Add(), ApplyTime(), Duration(), Mult(), Normalize(), and operator-().
|
private |
Definition at line 85 of file duration.hxx.
Referenced by Add(), ApplyTime(), Duration(), Mult(), Normalize(), and operator-().