#include <Pt/Timespan.h>
Represents time spans in microsecond resolution. More...
Public Member Functions | |
Timespan () | |
Constructs a zero Timespan. | |
Timespan (Pt::int64_t microseconds) | |
Constructs a Timespan. | |
Timespan (long secs, long microsecs) | |
Constructs a Timespan. More... | |
Timespan (int days, int hours, int minutes, int secs, int microseconds) | |
Constructs a Timespan. | |
Timespan (const Timespan ×pan) | |
Copy Constructor. | |
~Timespan () | |
Destructor. | |
int | days () const |
Returns the number of days. | |
int | hours () const |
Returns the number of hours (0 to 23). | |
bool | isNull () const |
Returns true if null. | |
int | minutes () const |
Returns the number of minutes (0 to 59). | |
int | msecs () const |
Returns the number of milliseconds (0 to 999). | |
Timespan & | operator+= (const Timespan &d) |
Assignment by sum operator. | |
Timespan & | operator-= (const Timespan &d) |
Assignment by difference operator. | |
Timespan & | operator= (const Timespan ×pan) |
Assignment operator. | |
int | seconds () const |
Returns the number of seconds (0 to 59). | |
Timespan & | set (int days, int hours, int minutes, int seconds, int microseconds) |
Sets the time span. | |
Timespan & | set (long seconds, long microseconds) |
Sets the time span. More... | |
void | setNull () |
Sets to null. | |
int | toHours () const |
Returns the total number of hours. | |
int | toMinutes () const |
Returns the total number of minutes. | |
Pt::int64_t | toMSecs () const |
Returns the total number of milliseconds. | |
int | toSeconds () const |
Returns the total number of seconds. | |
Pt::int64_t | toUSecs () const |
Returns the total number of microseconds. | |
int | usecs () const |
Returns the fractions of a millisecond in microseconds (0 to 999). | |
Related Functions | |
bool | operator!= (const Timespan &a, const Timespan &b) |
Inequal comparison operator. | |
Timespan | operator+ (const Timespan &a, const Timespan &b) |
Addition operator. | |
Timespan | operator- (const Timespan &a, const Timespan &b) |
Substraction operator. | |
bool | operator< (const Timespan &a, const Timespan &b) |
Less-than comparison operator. | |
bool | operator<= (const Timespan &a, const Timespan &b) |
Less-than-or-equal comparison operator. | |
bool | operator== (const Timespan &a, const Timespan &b) |
Equal comparison operator. | |
bool | operator> (const Timespan &a, const Timespan &b) |
Greater-than comparison operator. | |
bool | operator>= (const Timespan &a, const Timespan &b) |
Greater-than-or-equal comparison operator. | |
Time intervals can be represented by Pt::Timespan objects with microsecond accuracy. It is often the result of the calculations involving Pt::Date, Pt::Time ot Pt::DateTime. A Pt::Timespan can be constructed from the number of microseconds and then be converted to other time units with toHours(), toSeconds(), toMSecs() and toUSecs(). When two Pt::Timespans are compared, the shorter one is considered less. Addition and subtraction is supported as shown in the next example:
Timespan | ( | long | secs, |
long | microsecs | ||
) |
Useful for assigning from a POSIX timeval struct.
Timespan & set | ( | long | seconds, |
long | microseconds | ||
) |
Useful for assigning from a POSIX timeval struct.