TimeDuration
class TimeDuration
This class represents the time duration (length) between two time points The value is hold in form of two unsigned 64bit values. The first expresses the total number of seconds, and the seconds the fractional of a second.
The default constructor create a time duration of length zero, i.e. empty.
Variables
| Name | Description |
|---|---|
| m_oneSecondInAtto | One second expressed in attoseconds |
Operators
| Name | Description |
|---|---|
| operator== | Relational operations between time duration objects other : TimeDuration Return : bool |
| operator+ | Arithmetic operations over time durations other : TimeDuration Return : TimeDuration |
| operator* | Create a multiple of the TimeDuration by multiplication with an unsigned, i.e. non-negative number. factor : that the time duration should be multiplied with Return : the new TimeDuration |
| operator*= | Multiply by an unsigned, i.e. non-negative number. factor : that the time duration should be multiplied with Return : reference to *this after multiplication |
| operator* | These multiplications with a signed value create a linker error: TimeDuration cannot be negative. |
| operator/ | Division, i.e. how many times one time duration is bigger/smaller than another one other : TimeDuration Return : long double |
Functions
| Name | Description |
|---|---|
| TimeDuration | Default constructor creates an empty time duration |
| TimeDuration | Constructs a time duration from Hash. |
| TimeDuration | Construct a time duration from separate seconds and fractions of seconds. |
| TimeDuration | Construct a time duration that expand over days, hours, ... days : hours : minutes : seconds : fractions : |
| set | Set new length of, expand, or shrink a time duration days : hours : minutes : seconds : fractions : |
| isNull | Check if the time duration is empty, i.e. of zero length. Return : bool |
| getDays | In the standard mixed format DD::HH::MM::SS::FF, How many days, hours, minutes, and seconds are in the time duration. Return : unsigned int 64bits |
| getTotalHours | Express the total length of a time duration in hours, minutes, or seconds. |
| getFractions | Number of fractions of a second, default resolution is Nano seconds Return : unsigned int 64bits |
| format | Serialize time duration to string/std::ostream format : Return : string/ostream object holding the string representation of the time period |
| setDefaultFormat | Set the output format. |
| fromHash | Serialize time duration to and from Hash Hash : |
| sanitize | Sanitize, i.e. take care that 'frac' is below 1 second and adjust 'sec' accordingly. |
Variable Details
m_oneSecondInAtto
static const TimeValue m_oneSecondInAtto
One second expressed in attoseconds
Operator Details
operator*
TimeDuration operator*(TimeValue factor) const
Create a multiple of the TimeDuration by multiplication with an unsigned, i.e. non-negative number.
factor
: that the time duration should be multiplied with
Return : the new TimeDuration
TimeDuration operator*(long long illegalSignedFactor) const
These multiplications with a signed value create a linker error: TimeDuration cannot be negative.
operator*=
TimeDuration& operator*=(TimeValue factor)
Multiply by an unsigned, i.e. non-negative number.
factor
: that the time duration should be multiplied with
Return : reference to *this after multiplication
operator+
TimeDuration operator+(const TimeDuration& other) const
Arithmetic operations over time durations
other
: TimeDuration
Return : TimeDuration
operator/
long double operator/(const TimeDuration& other) const
Division, i.e. how many times one time duration is bigger/smaller than another one
other
: TimeDuration
Return : long double
operator==
bool operator==(const TimeDuration& other) const
Relational operations between time duration objects
other
: TimeDuration
Return : bool
Function Details
TimeDuration
TimeDuration()
Default constructor creates an empty time duration
TimeDuration(const karabo::data::Hash& hash)
Constructs a time duration from Hash. Seconds and fractions are stored as unsigned integer 64bits under the keys "seconds" and "fractions", respectively.
hash
: Hash object ("seconds", unsigned int 64bits, "fractions", unsigned int 64bits)
TimeDuration(const TimeValue seconds, const TimeValue fractions)
Construct a time duration from separate seconds and fractions of seconds.
seconds
:
fractions
: in Atto seconds
TimeDuration(const int days, const int hours, const int minutes, const TimeValue seconds, const TimeValue fractions)
Construct a time duration that expand over days, hours, ...
days
:
hours
:
minutes
:
seconds
:
fractions
:
format
std::string format(const std::string& fmt) const
Serialize time duration to string/std::ostream
format
:
Return : string/ostream object holding the string representation of the time period
fromHash
void fromHash(const karabo::data::Hash& hash)
Serialize time duration to and from Hash
Hash
:
getDays
uint64_t getDays() const
In the standard mixed format DD::HH::MM::SS::FF, How many days, hours, minutes, and seconds are in the time duration.
Return : unsigned int 64bits
getFractions
TimeValue getFractions(const TIME_UNITS unit = NANOSEC) const
Number of fractions of a second, default resolution is Nano seconds
Return : unsigned int 64bits
getTotalHours
TimeValue getTotalHours() const
Express the total length of a time duration in hours, minutes, or seconds.
Return : unsigned int 64bits
isNull
bool isNull() const
Check if the time duration is empty, i.e. of zero length.
Return : bool
sanitize
static inline void sanitize(TimeValue& sec, TimeValue& frac)
Sanitize, i.e. take care that 'frac' is below 1 second and adjust 'sec' accordingly.
set
TimeDuration& set(const TimeValue seconds, const TimeValue fractions)
Set new length of, expand, or shrink a time duration
days
:
hours
:
minutes
:
seconds
:
fractions
:
setDefaultFormat
static void setDefaultFormat(const std::string& fmt)
Set the output format. This parameter is class variable, thus, having a global effect on future output. The default format is seconds[dot]fractions, with nanoseconds resolution. CAVEAT: 'seconds' is the total number of seconds modulo 60, i.e. anything that goes beyond a full minute is ignored!
format
: string object