Detailed Description
The PTime class provides clock time functions; PTime instances are immutable (thread-safe).
A PTime object contains a clock time, i.e. the number of hours, minutes, seconds, and milliseconds since midnight.
It can read the current time from the system clock and measure a span of elapsed time.
#include <PTime.h>
Constructor & Destructor Documentation
◆ PTime() [1/3]
|
explicit |
◆ PTime() [2/3]
PTime::PTime | ( | const PTime & | other | ) |
Constructs a shared copy of other.
◆ PTime() [3/3]
Constructs a PTime represented by the string, using the specified format, or an invalid time if the string cannot be parsed.
Default format is "hh:mm:ss,zzz" (e.g. "23:59:59,999").
These expressions may be used for the format:
- h: the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- hh: the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- m: the minute without a leading zero (0 to 59)
- mm: the minute with a leading zero (00 to 59)
- s: the second without a leading zero (0 to 59)
- ss: the second with a leading zero (00 to 59)
- z: the milliseconds without leading zeroes (0 to 999)
- zzz: the milliseconds with leading zeroes (000 to 999)
- AP: interpret as an AM/PM time. AP must be either "AM" or "PM".
- ap: interpret as an AM/PM time. ap must be either "am" or "pm".
- See also
- IsValid()
◆ ~PTime()
PTime::~PTime | ( | ) |
Destroys this object.
Member Function Documentation
◆ AddMillisecond()
PTime PTime::AddMillisecond | ( | papillon::int32 | n | ) | const |
Returns a PTime object containing a time ms milliseconds later than the time of this object (or earlier if ms is negative).
Returns an invalid time if the current time is invalid or the new time is out of range.
◆ Compare()
papillon::int32 PTime::Compare | ( | const PTime & | other | ) | const |
Compares this time with another one, then returns 0 if equal, a negative number if this time is earlier than other, a positive number if this time is later than other.
◆ Current()
|
static |
Returns the current time as reported by the system clock.
◆ GetHour()
papillon::int32 PTime::GetHour | ( | ) | const |
Returns the hour part (0 to 23) of this time or returns -1 if the time is invalid.
◆ GetMillisecond()
papillon::int32 PTime::GetMillisecond | ( | ) | const |
Returns the millisecond part (0 to 59) of this time or returns -1 if the time is invalid.
◆ GetMillisecondsTo()
papillon::int32 PTime::GetMillisecondsTo | ( | const PTime & | t | ) | const |
Returns the number of milliseconds from this time to t.
If t is earlier than this time, the number of milliseconds returned is negative. Because PTime measures time within a day and there are 86400 seconds in a day, the result is always between -86400000 and 86400000 ms. Returns 0 if either this time or t is invalid.
◆ GetMinute()
papillon::int32 PTime::GetMinute | ( | ) | const |
Returns the minute part (0 to 59) of this time or returns -1 if the time is invalid.
◆ GetSecond()
papillon::int32 PTime::GetSecond | ( | ) | const |
Returns the second part (0 to 59) of this time or returns -1 if the time is invalid.
◆ IsValid()
bool PTime::IsValid | ( | ) | const |
Returns true if this time is valid; otherwise returns false.
◆ operator!=()
bool PTime::operator!= | ( | const PTime & | t | ) | const |
Returns true if this time is different from t; otherwise returns false.
◆ operator<()
bool PTime::operator< | ( | const PTime & | d | ) | const |
Returns true if this time is earlier than t; otherwise returns false.
◆ operator<=()
bool PTime::operator<= | ( | const PTime & | d | ) | const |
Returns true if this time is earlier than or equal to t; otherwise returns false.
◆ operator=()
◆ operator==()
bool PTime::operator== | ( | const PTime & | d | ) | const |
Returns true if this time is equal to t; otherwise returns false.
◆ operator>()
bool PTime::operator> | ( | const PTime & | d | ) | const |
Returns true if this time is later than t; otherwise returns false.
◆ operator>=()
bool PTime::operator>= | ( | const PTime & | d | ) | const |
Returns true if this time is later than or equal to t; otherwise returns false.
◆ ToString()
Returns the time as a string.
The format parameter determines the format of the result string; use "hh:mm:ss,zzz" by default.
These expressions may be used to build format:
- h: the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- hh: the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- m: the minute without a leading zero (0 to 59)
- mm: the minute with a leading zero (00 to 59)
- s: the second without a leading zero (0 to 59)
- ss: the second with a leading zero (00 to 59)
- z: the milliseconds without leading zeroes (0 to 999)
- zzz: the milliseconds with leading zeroes (000 to 999)
- AP: interpret as an AM/PM time. AP must be either "AM" or "PM".
- ap: interpret as an AM/PM time. ap must be either "am" or "pm".
If the time is invalid, an empty string will be returned.