#include <timeint.h>
Inheritance diagram for PTimeInterval:
Conversion functions | |
enum | Formats { NormalFormat, IncludeDays, SecondsOnly } |
PString | AsString (int decimals=3, Formats format=NormalFormat, int width=1) const |
Public Member Functions | |
Construction | |
PTimeInterval (PInt64 millisecs=0) | |
Create a new time interval object. | |
PTimeInterval (long millisecs, long seconds, long minutes=0, long hours=0, int days=0) | |
PTimeInterval (const PString &str) | |
Overrides from class PObject | |
PObject * | Clone () const |
Create a new copy of the time interval. | |
virtual Comparison | Compare (const PObject &obj) const |
Rank the two time intervals. | |
virtual void | PrintOn (ostream &strm) const |
Output the time interval to the I/O stream. | |
virtual void | ReadFrom (istream &strm) |
Input the time interval from the I/O stream. | |
Access functions | |
virtual PInt64 | GetMilliSeconds () const |
Get the number of milliseconds for the time interval. | |
virtual void | SetMilliSeconds (PInt64 msecs) |
Set the number of milliseconds for the time interval. | |
long | GetSeconds () const |
Get the number of whole seconds for the time interval. | |
long | GetMinutes () const |
Get the number of whole minutes for the time interval. | |
int | GetHours () const |
Get the number of whole hours for the time interval. | |
int | GetDays () const |
Get the number of whole days for the time interval. | |
DWORD | GetInterval () const |
Get the number of milliseconds for the time interval. | |
virtual void | SetInterval (PInt64 milliseconds=0, long seconds=0, long minutes=0, long hours=0, int days=0) |
Set the value of the time interval. | |
Operations | |
PTimeInterval | operator- () const |
Unary minus, get negative of time interval. | |
PTimeInterval | operator+ (const PTimeInterval &interval) const |
Add the two time intervals yielding a third time interval. | |
PTimeInterval & | operator+= (const PTimeInterval &interval) |
Add the second time interval to the first time interval. | |
PTimeInterval | operator- (const PTimeInterval &interval) const |
Subtract the two time intervals yielding a third time interval. | |
PTimeInterval & | operator-= (const PTimeInterval &interval) |
Subtract the second time interval from the first time interval. | |
PTimeInterval | operator * (int factor) const |
Multiply the time interval by a factor yielding a third time interval. | |
PTimeInterval & | operator *= (int factor) |
Multiply the time interval by a factor. | |
int | operator/ (const PTimeInterval &smaller) const |
Divide the time interval by another interval yielding a count. | |
PTimeInterval | operator/ (int factor) const |
Divide the time interval by a factor yielding a third time interval. | |
PTimeInterval & | operator/= (int factor) |
Divide the time interval by a factor. | |
Comparison functions | |
bool | operator== (const PTimeInterval &interval) const |
Compare to the two time intervals. | |
bool | operator== (long msecs) const |
bool | operator!= (const PTimeInterval &interval) const |
Compare to the two time intervals. | |
bool | operator!= (long msecs) const |
bool | operator> (const PTimeInterval &interval) const |
Compare to the two time intervals. | |
bool | operator> (long msecs) const |
bool | operator>= (const PTimeInterval &interval) const |
Compare to the two time intervals. | |
bool | operator>= (long msecs) const |
bool | operator< (const PTimeInterval &interval) const |
Compare to the two time intervals. | |
bool | operator< (long msecs) const |
bool | operator<= (const PTimeInterval &interval) const |
Compare to the two time intervals. | |
bool | operator<= (long msecs) const |
The interval can be both positive and negative.
A long int is used to store the time interval so it is limited to LONG_MAX (found in the standard C header file limits.h) milliseconds. This is approximately 596 hours for 32 bit integers.
There is a constant, PMaxTimeInterval
which defines the maximum number of milliseconds that a time interval may be.
PTimeInterval::PTimeInterval | ( | PInt64 | millisecs = 0 |
) |
Create a new time interval object.
The time interval, in milliseconds, is the sum of all of the parameters. For example all of the following are equivalent:
PTimeInterval(120000)
PTimeInterval(60000, 60)
PTimeInterval(60000, 0, 1)
PTimeInterval(0, 60, 1)
PTimeInterval(0, 0, 2)
millisecs | Number of milliseconds for interval. |
PTimeInterval::PTimeInterval | ( | long | millisecs, | |
long | seconds, | |||
long | minutes = 0 , |
|||
long | hours = 0 , |
|||
int | days = 0 | |||
) |
millisecs | Number of milliseconds for interval. |
seconds | Number of seconds for interval. |
minutes | Number of minutes for interval. |
hours | Number of hours for interval. |
days | Number of days for interval. |
PTimeInterval::PTimeInterval | ( | const PString & | str | ) |
str | String representation of time interval. |
PString PTimeInterval::AsString | ( | int | decimals = 3 , |
|
Formats | format = NormalFormat , |
|||
int | width = 1 | |||
) | const |
PObject* PTimeInterval::Clone | ( | ) | const [virtual] |
Create a new copy of the time interval.
It is the responsibility of the called to delete the object.
Reimplemented from PObject.
virtual Comparison PTimeInterval::Compare | ( | const PObject & | obj | ) | const [virtual] |
Rank the two time intervals.
This ranks the intervals as you would expect for two integers.
EqualTo
, LessThan
or GreaterThan
depending on their relative rank. obj | Time interval to compare against. |
Reimplemented from PObject.
int PTimeInterval::GetDays | ( | ) | const |
Get the number of whole days for the time interval.
int PTimeInterval::GetHours | ( | ) | const |
Get the number of whole hours for the time interval.
DWORD PTimeInterval::GetInterval | ( | ) | const |
Get the number of milliseconds for the time interval.
virtual PInt64 PTimeInterval::GetMilliSeconds | ( | ) | const [virtual] |
Get the number of milliseconds for the time interval.
Reimplemented in PTimer.
long PTimeInterval::GetMinutes | ( | ) | const |
Get the number of whole minutes for the time interval.
long PTimeInterval::GetSeconds | ( | ) | const |
Get the number of whole seconds for the time interval.
PTimeInterval PTimeInterval::operator * | ( | int | factor | ) | const |
Multiply the time interval by a factor yielding a third time interval.
factor | factor to multiply. |
PTimeInterval& PTimeInterval::operator *= | ( | int | factor | ) |
Multiply the time interval by a factor.
factor | factor to multiply. |
bool PTimeInterval::operator!= | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator!= | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
PTimeInterval PTimeInterval::operator+ | ( | const PTimeInterval & | interval | ) | const |
Add the two time intervals yielding a third time interval.
interval | Time interval to add. |
PTimeInterval& PTimeInterval::operator+= | ( | const PTimeInterval & | interval | ) |
Add the second time interval to the first time interval.
interval | Time interval to add. |
PTimeInterval PTimeInterval::operator- | ( | const PTimeInterval & | interval | ) | const |
Subtract the two time intervals yielding a third time interval.
interval | Time interval to subtract. |
PTimeInterval PTimeInterval::operator- | ( | ) | const |
Unary minus, get negative of time interval.
PTimeInterval& PTimeInterval::operator-= | ( | const PTimeInterval & | interval | ) |
Subtract the second time interval from the first time interval.
interval | Time interval to subtract. |
PTimeInterval PTimeInterval::operator/ | ( | int | factor | ) | const |
Divide the time interval by a factor yielding a third time interval.
factor | factor to divide. |
int PTimeInterval::operator/ | ( | const PTimeInterval & | smaller | ) | const |
Divide the time interval by another interval yielding a count.
smaller | factor to divide. |
PTimeInterval& PTimeInterval::operator/= | ( | int | factor | ) |
Divide the time interval by a factor.
factor | factor to divide. |
bool PTimeInterval::operator< | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator< | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator<= | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator<= | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator== | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator== | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator> | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator> | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator>= | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator>= | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
virtual void PTimeInterval::PrintOn | ( | ostream & | strm | ) | const [virtual] |
Output the time interval to the I/O stream.
This outputs the number of milliseconds as a signed decimal integer number.
strm | I/O stream to output the time interval. |
Reimplemented from PObject.
virtual void PTimeInterval::ReadFrom | ( | istream & | strm | ) | [virtual] |
Input the time interval from the I/O stream.
This expects the input to be a signed decimal integer number.
strm | I/O stream to input the time interval from. |
Reimplemented from PObject.
virtual void PTimeInterval::SetInterval | ( | PInt64 | milliseconds = 0 , |
|
long | seconds = 0 , |
|||
long | minutes = 0 , |
|||
long | hours = 0 , |
|||
int | days = 0 | |||
) | [virtual] |
Set the value of the time interval.
The time interval, in milliseconds, is the sum of all of the parameters. For example all of the following are equivalent:
SetInterval(120000)
SetInterval(60000, 60)
SetInterval(60000, 0, 1)
SetInterval(0, 60, 1)
SetInterval(0, 0, 2)
milliseconds | Number of milliseconds for interval. |
seconds | Number of seconds for interval. |
minutes | Number of minutes for interval. |
hours | Number of hours for interval. |
days | Number of days for interval. |
Reimplemented in PSimpleTimer, and PTimer.
virtual void PTimeInterval::SetMilliSeconds | ( | PInt64 | msecs | ) | [virtual] |
Set the number of milliseconds for the time interval.