Timespan Class Reference

#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 &timespan)
 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).
 
Timespanoperator+= (const Timespan &d)
 Assignment by sum operator.
 
Timespanoperator-= (const Timespan &d)
 Assignment by difference operator.
 
Timespanoperator= (const Timespan &timespan)
 Assignment operator.
 
int seconds () const
 Returns the number of seconds (0 to 59).
 
Timespanset (int days, int hours, int minutes, int seconds, int microseconds)
 Sets the time span.
 
Timespanset (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.
 

Detailed Description

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:

#include <Pt/Timespan.h>
#include <iostream>
Pt::Timespan ts1(10000);
Pt::Timespan ts2(1000);
Pt::Timespan d = ts2 - ts1;
std::cout << "The difference is " << d.toSecs() << " secs" << std::endl;

Constructor & Destructor Documentation

Timespan ( long  secs,
long  microsecs 
)

Useful for assigning from a POSIX timeval struct.

Member Function Documentation

Timespan & set ( long  seconds,
long  microseconds 
)

Useful for assigning from a POSIX timeval struct.