PTimeInterval Class Reference

This class defines an arbitrary time interval to millisecond accuracy. More...

`#include <timeint.h>`

Inheritance diagram for PTimeInterval:

## Public Member Functions

Construction
| PTimeInterval (PInt64 millisecs=0)
| Create a new time interval object. More...
| 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. More...
virtual Comparison | Compare (const PObject &obj) const
| Rank the two time intervals. More...
virtual void | PrintOn (ostream &strm) const
| Output the time interval to the I/O stream. More...
virtual void | ReadFrom (istream &strm)
| Input the time interval from the I/O stream. More...
Access functions
virtual PInt64 | GetMilliSeconds () const
| Get the number of milliseconds for the time interval. More...
virtual void | SetMilliSeconds (PInt64 msecs)
| Set the number of milliseconds for the time interval. More...
long | GetSeconds () const
| Get the number of whole seconds for the time interval. More...
long | GetMinutes () const
| Get the number of whole minutes for the time interval. More...
int | GetHours () const
| Get the number of whole hours for the time interval. More...
int | GetDays () const
| Get the number of whole days for the time interval. More...
DWORD | GetInterval () const
| Get the number of milliseconds for the time interval. More...
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. More...
Operations
PTimeInterval | operator- () const
| Unary minus, get negative of time interval. More...
PTimeInterval | operator+ (const PTimeInterval &interval) const
| Add the two time intervals yielding a third time interval. More...
PTimeInterval & | operator+= (const PTimeInterval &interval)
| Add the second time interval to the first time interval. More...
PTimeInterval | operator- (const PTimeInterval &interval) const
| Subtract the two time intervals yielding a third time interval. More...
PTimeInterval & | operator-= (const PTimeInterval &interval)
| Subtract the second time interval from the first time interval. More...
PTimeInterval | operator* (int factor) const
| Multiply the time interval by a factor yielding a third time interval. More...
PTimeInterval & | operator*= (int factor)
| Multiply the time interval by a factor. More...
int | operator/ (const PTimeInterval &smaller) const
| Divide the time interval by another interval yielding a count. More...
PTimeInterval | operator/ (int factor) const
| Divide the time interval by a factor yielding a third time interval. More...
PTimeInterval & | operator/= (int factor)
| Divide the time interval by a factor. More...
Comparison functions
bool | operator== (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator== (long msecs) const
bool | operator!= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator!= (long msecs) const
bool | operator> (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator> (long msecs) const
bool | operator>= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator>= (long msecs) const
bool | operator< (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator< (long msecs) const
bool | operator<= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator<= (long msecs) const
Public Member Functions inherited from PObject
virtual | ~PObject ()
virtual PINDEX | HashFunction () const
| This function yields a hash value required by the `PDictionary` class. More...
virtual const char * | GetClass (unsigned ancestor=0) const
| Get the current dynamic type of the object instance. More...
PBoolean | IsClass (const char *cls) const
virtual PBoolean | InternalIsDescendant (const char *clsName) const
| Determine if the dynamic type of the current instance is a descendent of the specified class. More...
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const
| Determine the byte wise comparison of two objects. More...
bool | operator== (const PObject &obj) const
| Compare the two objects. More...
bool | operator!= (const PObject &obj) const
| Compare the two objects. More...
bool | operator< (const PObject &obj) const
| Compare the two objects. More...
bool | operator> (const PObject &obj) const
| Compare the two objects. More...
bool | operator<= (const PObject &obj) const
| Compare the two objects. More...
bool | operator>= (const PObject &obj) const
| Compare the two objects. More...

## Conversion functions

enum | Formats { NormalFormat, IncludeDays, SecondsOnly }
PString | AsString (int decimals=3, Formats format=NormalFormat, int width=1) const

## Additional Inherited Members

Public Types inherited from PObject
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
| Result of the comparison operation performed by the `Compare()` function. More...
Static Public Member Functions inherited from PObject
static const char * | Class ()
| Get the name of the class as a C string. More...
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
| Internal function caled from CompareObjectMemoryDirect() More...
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...

## Detailed Description

This class defines an arbitrary time interval to millisecond accuracy.

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.

## Member Enumeration Documentation

## Formats

enum PTimeInterval::Formats

Enumerator
NormalFormat |
IncludeDays |
SecondsOnly |

## Constructor & Destructor Documentation

## PTimeInterval() [1/3]

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)

Parameters

  millisecs | Number of milliseconds for interval.

## PTimeInterval() [2/3]

PTimeInterval::PTimeInterval | ( | long | millisecs,
|  | long | seconds,
|  | long | minutes = `0`,
|  | long | hours = `0`,
|  | int | days = `0`
| ) |  |

Parameters

  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() [3/3]

PTimeInterval::PTimeInterval | ( | const PString & | str | ) |

Parameters

  str | String representation of time interval.

## Member Function Documentation

## AsString()

PString PTimeInterval::AsString | ( | int | decimals = `3`,
|  | Formats | format = `NormalFormat`,
|  | int | width = `1`
| ) |  | const

## Clone()

PObject* PTimeInterval::Clone | ( |  | ) | const

virtual

Create a new copy of the time interval.

It is the responsibility of the called to delete the object.

Returns
  new time interval on heap.

Reimplemented from PObject.

## Compare()

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.

Returns
  `EqualTo`, `LessThan` or `GreaterThan` depending on their relative rank.

Parameters

  obj | Time interval to compare against.

Reimplemented from PObject.

## GetDays()

int PTimeInterval::GetDays | ( |  | ) | const

Get the number of whole days for the time interval.

Returns
  integer number of days.

## GetHours()

int PTimeInterval::GetHours | ( |  | ) | const

Get the number of whole hours for the time interval.

Returns
  integer number of hours.

## GetInterval()

DWORD PTimeInterval::GetInterval | ( |  | ) | const

Get the number of milliseconds for the time interval.

Returns
  long integer number of milliseconds.

## GetMilliSeconds()

virtual PInt64 PTimeInterval::GetMilliSeconds | ( |  | ) | const

virtual

Get the number of milliseconds for the time interval.

Returns
  very long integer number of milliseconds.

Reimplemented in PTimer.

## GetMinutes()

long PTimeInterval::GetMinutes | ( |  | ) | const

Get the number of whole minutes for the time interval.

Returns
  integer number of minutes.

## GetSeconds()

long PTimeInterval::GetSeconds | ( |  | ) | const

Get the number of whole seconds for the time interval.

Returns
  long integer number of seconds.

## operator!=() [1/2]

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.

Returns
  true if intervals are not equal.

Parameters

  interval | Time interval to compare.

## operator!=() [2/2]

bool PTimeInterval::operator!= | ( | long | msecs | ) | const

Parameters

  msecs | Time interval as integer milliseconds to compare.

## operator*()

PTimeInterval PTimeInterval::operator* | ( | int | factor | ) | const

Multiply the time interval by a factor yielding a third time interval.

Returns
  the time intervals times the factor.

Parameters

  factor | factor to multiply.

## operator*=()

PTimeInterval& PTimeInterval::operator*= | ( | int | factor | ) |

Multiply the time interval by a factor.

Returns
  reference to time interval.

Parameters

  factor | factor to multiply.

## operator+()

PTimeInterval PTimeInterval::operator+ | ( | const PTimeInterval & | interval | ) | const

Add the two time intervals yielding a third time interval.

Returns
  sum of the time intervals.

Parameters

  interval | Time interval to add.

## operator+=()

PTimeInterval& PTimeInterval::operator+= | ( | const PTimeInterval & | interval | ) |

Add the second time interval to the first time interval.

Returns
  reference to first time interval.

Parameters

  interval | Time interval to add.

## operator-() [1/2]

PTimeInterval PTimeInterval::operator- | ( |  | ) | const

Unary minus, get negative of time interval.

Returns
  difference of the time intervals.

## operator-() [2/2]

PTimeInterval PTimeInterval::operator- | ( | const PTimeInterval & | interval | ) | const

Subtract the two time intervals yielding a third time interval.

Returns
  difference of the time intervals.

Parameters

  interval | Time interval to subtract.

## operator-=()

PTimeInterval& PTimeInterval::operator-= | ( | const PTimeInterval & | interval | ) |

Subtract the second time interval from the first time interval.

Returns
  reference to first time interval.

Parameters

  interval | Time interval to subtract.

## operator/() [1/2]

int PTimeInterval::operator/ | ( | const PTimeInterval & | smaller | ) | const

Divide the time interval by another interval yielding a count.

Returns
  the number of times the second interval occurs in the larger.

Parameters

  smaller | factor to divide.

## operator/() [2/2]

PTimeInterval PTimeInterval::operator/ | ( | int | factor | ) | const

Divide the time interval by a factor yielding a third time interval.

Returns
  the time intervals divided by the factor.

Parameters

  factor | factor to divide.

## operator/=()

PTimeInterval& PTimeInterval::operator/= | ( | int | factor | ) |

Divide the time interval by a factor.

Returns
  reference to time interval.

Parameters

  factor | factor to divide.

## operator<() [1/2]

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.

Returns
  true if intervals are less than.

Parameters

  interval | Time interval to compare.

## operator<() [2/2]

bool PTimeInterval::operator< | ( | long | msecs | ) | const

Parameters

  msecs | Time interval as integer milliseconds to compare.

## operator<=() [1/2]

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.

Returns
  true if intervals are less than or equal.

Parameters

  interval | Time interval to compare.

## operator<=() [2/2]

bool PTimeInterval::operator<= | ( | long | msecs | ) | const

Parameters

  msecs | Time interval as integer milliseconds to compare.

## operator==() [1/2]

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.

Returns
  true if intervals are equal.

Parameters

  interval | Time interval to compare.

## operator==() [2/2]

bool PTimeInterval::operator== | ( | long | msecs | ) | const

Parameters

  msecs | Time interval as integer milliseconds to compare.

## operator>() [1/2]

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.

Returns
  true if intervals are greater than.

Parameters

  interval | Time interval to compare.

## operator>() [2/2]

bool PTimeInterval::operator> | ( | long | msecs | ) | const

Parameters

  msecs | Time interval as integer milliseconds to compare.

## operator>=() [1/2]

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.

Returns
  true if intervals are greater than or equal.

Parameters

  interval | Time interval to compare.

## operator>=() [2/2]

bool PTimeInterval::operator>= | ( | long | msecs | ) | const

Parameters

  msecs | Time interval as integer milliseconds to compare.

## PrintOn()

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.

Parameters

  strm | I/O stream to output the time interval.

Reimplemented from PObject.

## ReadFrom()

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.

Parameters

  strm | I/O stream to input the time interval from.

Reimplemented from PObject.

## SetInterval()

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)

Parameters

  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 PTimer, and PSimpleTimer.

## SetMilliSeconds()

virtual void PTimeInterval::SetMilliSeconds | ( | PInt64 | msecs | ) |

virtual

Set the number of milliseconds for the time interval.

The documentation for this class was generated from the following file:

- timeint.h