#include <ptime.h>
Public Member Functions | |
Overrides from class PObject | |
PObject * | Clone () const |
virtual Comparison | Compare (const PObject &obj) const |
virtual void | PrintOn (ostream &strm) const |
virtual void | ReadFrom (istream &strm) |
Operations | |
PTime | operator+ (const PTimeInterval &time) const |
PTime & | operator+= (const PTimeInterval &time) |
PTimeInterval | operator- (const PTime &time) const |
PTime | operator- (const PTimeInterval &time) const |
PTime & | operator-= (const PTimeInterval &time) |
Static Public Member Functions | |
static struct tm * | os_localtime (const time_t *clock, struct tm *t) |
static struct tm * | os_gmtime (const time_t *clock, struct tm *t) |
Protected Attributes | |
time_t | theTime |
Number of seconds since 1 January 1970. | |
long | microseconds |
Construction | |
| |
enum | { UTC = 0, GMT = UTC, Local = 9999 } |
PTime () | |
PTime (time_t tsecs, long usecs=0) | |
PTime (const PString &str) | |
PTime (int second, int minute, int hour, int day, int month, int year, int tz=Local) | |
Access functions | |
| |
enum | Months { January = 1, February, March, April, May, June, July, August, September, October, November, December } |
Month codes. More... | |
enum | Weekdays { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } |
Days of the week. More... | |
PBoolean | IsValid () const |
PInt64 | GetTimestamp () const |
time_t | GetTimeInSeconds () const |
long | GetMicrosecond () const |
int | GetSecond () const |
int | GetMinute () const |
int | GetHour () const |
int | GetDay () const |
Months | GetMonth () const |
int | GetYear () const |
Weekdays | GetDayOfWeek () const |
int | GetDayOfYear () const |
PBoolean | IsPast () const |
PBoolean | IsFuture () const |
Time Zone configuration functions | |
| |
enum | TimeZoneType { StandardTime, DaylightSavings } |
Flag for time zone adjustment on daylight savings. More... | |
static PBoolean | IsDaylightSavings () |
static int | GetTimeZone () |
Get the time zone offset in minutes. | |
static int | GetTimeZone (TimeZoneType type) |
static PString | GetTimeZoneString (TimeZoneType type=StandardTime) |
String conversion functions | |
| |
enum | TimeFormat { RFC1123, ShortISO8601, LongISO8601, LongDateTime, LongDate, LongTime, MediumDateTime, MediumDate, ShortDateTime, ShortDate, ShortTime, NumTimeStrings } |
Standard time formats for string representations of a time and date. More... | |
PString | AsString (TimeFormat formatCode=RFC1123, int zone=Local) const |
PString | AsString (const PString &formatStr, int zone=Local) const |
PString | AsString (const char *formatPtr, int zone=Local) const |
Internationalisation functions | |
| |
enum | NameType { FullName, Abbreviated } |
Flag for returning language dependent string names. More... | |
enum | DateOrder { MonthDayYear, DayMonthYear, YearMonthDay } |
Possible orders for date components. More... | |
static PString | GetTimeSeparator () |
static PBoolean | GetTimeAMPM () |
static PString | GetTimeAM () |
static PString | GetTimePM () |
static PString | GetDayName (Weekdays dayOfWeek, NameType type=FullName) |
static PString | GetDateSeparator () |
static PString | GetMonthName (Months month, NameType type=FullName) |
static DateOrder | GetDateOrder () |
This class defines an absolute time and date. It has a number of time and date rendering and manipulation functions. It is based on the standard C library functions for time. Thus it is based on a number of seconds since 1 January 1970.
anonymous enum |
enum PTime::DateOrder |
enum PTime::Months |
enum PTime::NameType |
enum PTime::TimeFormat |
Standard time formats for string representations of a time and date.
enum PTime::TimeZoneType |
enum PTime::Weekdays |
PTime::PTime | ( | ) |
Create a time object instance. This initialises the time with the current time in the current time zone.
Referenced by Clone().
PTime::PTime | ( | time_t | tsecs, | |
long | usecs = 0 | |||
) | [inline] |
Create a time object instance. This initialises the time to the specified time.
tsecs | Time in seconds since 00:00:00 1/1/70 UTC |
References microseconds, and theTime.
PTime::PTime | ( | const PString & | str | ) |
Create a time object instance. This initialises the time to the specified time, parsed from the string. The string may be in many different formats, for example: "5/03/1999 12:34:56" "15/06/1999 12:34:56" "15/06/01 12:34:56 PST" "5/06/02 12:34:56" "5/23/1999 12:34am" "5/23/00 12:34am" "1999/23/04 12:34:56" "Mar 3, 1999 12:34pm" "3 Jul 2004 12:34pm" "12:34:56 5 December 1999" "10 minutes ago" "2 weeks"
str | Time and data as a string |
PTime::PTime | ( | int | second, | |
int | minute, | |||
int | hour, | |||
int | day, | |||
int | month, | |||
int | year, | |||
int | tz = Local | |||
) |
Create a time object instance. This initialises the time to the specified time.
second | Second from 0 to 59. | |
minute | Minute from 0 to 59. | |
hour | Hour from 0 to 23. | |
day | Day of month from 1 to 31. | |
month | Month from 1 to 12. | |
year | Year from 1970 to 2038 | |
tz | local time or UTC |
PString PTime::AsString | ( | const char * | formatPtr, | |
int | zone = Local | |||
) | const |
formatPtr | Arbitrary format C string pointer for time. | |
zone | Time zone for the time. |
Convert the time to a string representation.
formatStr | Arbitrary format string for time. | |
zone | Time zone for the time. |
References AsString().
PString PTime::AsString | ( | TimeFormat | formatCode = RFC1123 , |
|
int | zone = Local | |||
) | const |
Convert the time to a string representation.
formatCode | Standard format for time. | |
zone | Time zone for the time. |
Referenced by AsString(), and PrintOn().
PINLINE PObject * PTime::Clone | ( | ) | const [virtual] |
Create a copy of the time on the heap. It is the responsibility of the caller to delete the created object.
Reimplemented from PObject.
References microseconds, PNEW, PTime(), and theTime.
virtual Comparison PTime::Compare | ( | const PObject & | obj | ) | const [virtual] |
Determine the relative rank of the specified times. This ranks the times as you would expect.
obj | Other time to compare against. |
Reimplemented from PObject.
static DateOrder PTime::GetDateOrder | ( | ) | [static] |
Return the internationalised date order.
static PString PTime::GetDateSeparator | ( | ) | [static] |
Get the internationalised date separator.
PINLINE int PTime::GetDay | ( | ) | const |
Get the day of the month of the date.
References os_localtime(), and theTime.
Get the internationalised day of week day name (0=Sun etc).
dayOfWeek | Code for day of week. | |
type | Flag for abbreviated or full name. |
PINLINE PTime::Weekdays PTime::GetDayOfWeek | ( | ) | const |
Get the day of the week of the date.
References os_localtime(), and theTime.
PINLINE int PTime::GetDayOfYear | ( | ) | const |
Get the day in the year of the date.
References os_localtime(), and theTime.
PINLINE int PTime::GetHour | ( | ) | const |
PINLINE long PTime::GetMicrosecond | ( | ) | const |
PINLINE int PTime::GetMinute | ( | ) | const |
PINLINE PTime::Months PTime::GetMonth | ( | ) | const |
Get the internationalised month name string (1=Jan etc).
month | Code for month in year. | |
type | Flag for abbreviated or full name. |
PINLINE int PTime::GetSecond | ( | ) | const |
static PString PTime::GetTimeAM | ( | ) | [static] |
Get the internationalised time AM string.
static PBoolean PTime::GetTimeAMPM | ( | ) | [static] |
Get the internationalised time format: AM/PM or 24 hour.
PINLINE time_t PTime::GetTimeInSeconds | ( | ) | const |
Get the total seconds since the epoch. The epoch is the 1st January 1970.
References theTime.
static PString PTime::GetTimePM | ( | ) | [static] |
Get the internationalised time PM string.
static PString PTime::GetTimeSeparator | ( | ) | [static] |
Get the internationalised time separator.
PINLINE PInt64 PTime::GetTimestamp | ( | ) | const |
Get the total microseconds since the epoch. The epoch is the 1st January 1970.
References microseconds, and theTime.
static int PTime::GetTimeZone | ( | TimeZoneType | type | ) | [static] |
Get the time zone offset in minutes. This is the number of minutes to add to UTC (previously known as GMT) to get the local time. The first form automatically adjusts for daylight savings time, whilst the second form returns the specified time.
type | Daylight saving or standard time. |
PINLINE int PTime::GetTimeZone | ( | ) | [static] |
Get the time zone offset in minutes.
References DaylightSavings, IsDaylightSavings(), and StandardTime.
static PString PTime::GetTimeZoneString | ( | TimeZoneType | type = StandardTime |
) | [static] |
Get the text identifier for the local time zone .
type | Daylight saving or standard time. |
PINLINE int PTime::GetYear | ( | ) | const |
Get the year of the date.
References os_localtime(), and theTime.
static PBoolean PTime::IsDaylightSavings | ( | ) | [static] |
Get flag indicating daylight savings is current.
Referenced by GetTimeZone().
PINLINE PBoolean PTime::IsFuture | ( | ) | const |
Determine if the time is in the past or in the future.
References theTime.
PINLINE PBoolean PTime::IsPast | ( | ) | const |
Determine if the time is in the past or in the future.
References theTime.
PINLINE PBoolean PTime::IsValid | ( | ) | const |
Determine if the timestamp is valid. This will return PTrue if the timestamp can be represented as a time in the epoch. The epoch is the 1st January 1970.
In practice this means the time is > 13 hours to allow for time zones.
References theTime.
PTime PTime::operator+ | ( | const PTimeInterval & | time | ) | const |
Add the interval to the time to yield a new time.
time | Time interval to add to the time. |
PTime& PTime::operator+= | ( | const PTimeInterval & | time | ) |
Add the interval to the time changing the instance.
time | Time interval to add to the time. |
PTime PTime::operator- | ( | const PTimeInterval & | time | ) | const |
Subtract the interval from the time to yield a new time.
time | Time interval to subtract from the time. |
PTimeInterval PTime::operator- | ( | const PTime & | time | ) | const |
Calculate the difference between two times to get a time interval.
time | Time to subtract from the time. |
PTime& PTime::operator-= | ( | const PTimeInterval & | time | ) |
Subtract the interval from the time changing the instance.
time | Time interval to subtract from the time. |
static struct tm* PTime::os_gmtime | ( | const time_t * | clock, | |
struct tm * | t | |||
) | [static, read] |
static struct tm* PTime::os_localtime | ( | const time_t * | clock, | |
struct tm * | t | |||
) | [static, read] |
Referenced by GetDay(), GetDayOfWeek(), GetDayOfYear(), GetHour(), GetMinute(), GetMonth(), GetSecond(), and GetYear().
PINLINE void PTime::PrintOn | ( | ostream & | strm | ) | const [virtual] |
Output the time to the stream. This uses the AsString()# function with the ShortDateTime# parameter.
strm | Stream to output the time to. |
Reimplemented from PObject.
References AsString().
virtual void PTime::ReadFrom | ( | istream & | strm | ) | [virtual] |
Input the time from the specified stream. If a parse error occurs the time is set to the current time. The string may be in many different formats, for example: "5/03/1999 12:34:56" "15/06/1999 12:34:56" "15/06/01 12:34:56 PST" "5/06/02 12:34:56" "5/23/1999 12:34am" "5/23/00 12:34am" "1999/23/04 12:34:56" "Mar 3, 1999 12:34pm" "3 Jul 2004 12:34pm" "12:34:56 5 December 1999" "10 minutes ago" "2 weeks"
strm | Stream to input the time from. |
Reimplemented from PObject.
long PTime::microseconds [protected] |
Referenced by Clone(), GetMicrosecond(), GetTimestamp(), and PTime().
time_t PTime::theTime [protected] |
Number of seconds since 1 January 1970.
Referenced by Clone(), GetDay(), GetDayOfWeek(), GetDayOfYear(), GetHour(), GetMinute(), GetMonth(), GetSecond(), GetTimeInSeconds(), GetTimestamp(), GetYear(), IsFuture(), IsPast(), IsValid(), and PTime().