EpcTools
An event based multi-threaded C++ development framework.
Public Member Functions | Static Public Member Functions | List of all members
ETime Class Reference

Class for manipulating date and time of day values. More...

#include <etime.h>

Public Member Functions

 ETime ()
 Default constructor. Initializes to current time. More...
 
 ETime (const ETime &a)
 Copy constructor. More...
 
 ETime (Int sec, Int usec)
 Class constructor. More...
 
 ETime (LongLong ms)
 Class constructor. More...
 
 ETime (Int year, Int mon, Int day, Int hour, Int min, Int sec, Bool isLocal)
 Class constructor. More...
 
 ~ETime ()
 Class destructor. More...
 
ETimeoperator= (const ETime &a)
 Assignment operator. More...
 
ETimeoperator= (const timeval &a)
 Assignment operator. More...
 
ETimeoperator= (LongLong ms)
 Assignment operator. More...
 
Bool operator== (const ETime &a)
 Equality operator. More...
 
Bool operator!= (const ETime &a)
 Inequality operator. More...
 
Bool operator< (const ETime &a)
 Less than operator. More...
 
Bool operator> (const ETime &a)
 Greater than operator. More...
 
Bool operator>= (const ETime &a)
 Greater than or equal to operator. More...
 
Bool operator<= (const ETime &a)
 Less than or equal to operator. More...
 
ETime operator+ (const ETime &a)
 Addition operator. More...
 
ETime operator+ (const timeval &t)
 Addition operator. More...
 
ETime operator- (const ETime &a)
 Subtraction operator. More...
 
ETime operator- (const timeval &t)
 Subtraction operator. More...
 
ETime add (Int days, Int hrs, Int mins, Int secs, Int usecs)
 Adds the specified days, hours minutes seconds and microseconds to the current value. More...
 
ETime add (const timeval &t)
 Adds the timeval amount to the current value. More...
 
ETime subtract (Int days, Int hrs, Int mins, Int secs, Int usecs)
 Subtracts the specified days, hours minutes seconds and microseconds to the current value. More...
 
ETime subtract (const timeval &t)
 Subtracts the timeval amount to the current value. More...
 
const timeval & getTimeVal ()
 Retrieves a reference to the timeval structure. More...
 
ETimeset (const timeval &a)
 Assigns the specified timeval value to this ETime object. More...
 
ETimeset (LongLong ms)
 Assigns the specified millisecond value to this ETime object. More...
 
LongLong getCassandraTimestmap ()
 Converts this ETime value to one compatible with a Cassandra timestamp. More...
 
Void getNTPTime (ntp_time_t &ntp) const
 Retrieves the NTP time representation of this ETime object. More...
 
Void setNTPTime (const ntp_time_t &ntp)
 Assigns the time represented by the NTP time to this ETime object. More...
 
Bool isValid ()
 Indicates whether this ETime object is valid or not. More...
 
Int year ()
 Retrieves the year. More...
 
Int month ()
 Retrieves the month. More...
 
Int day ()
 Retrieves the day. More...
 
Int hour ()
 Retrieves the hour. More...
 
Int minute ()
 Retrieves the minute. More...
 
Int second ()
 Retrieves the second. More...
 
Void Format (EString &dest, cpStr fmt, Bool local)
 Formats the date/time value as specified by the format string. More...
 
Void Format (pStr dest, Int maxsize, cpStr fmt, Bool local)
 Formats the date/time value as specified by the format string. More...
 
EString Format (cpStr fmt, Bool local)
 Formats the date/time value as specified by the format string. More...
 
Bool ParseDateTime (cpStr pszDate, Bool isLocal=True)
 Parses the string containing the time and date. More...
 

Static Public Member Functions

static ETime Now ()
 Retrieves the current time. More...
 

Detailed Description

Class for manipulating date and time of day values.

The format functions use printf like format specifiers. Here are the possible values:

Specifier Output
A Full day of week name
a Day of week name abbreviation
0 Milliseconds
1 Microseconds
B Full month name
b or h Abbreviated month name
c Date and time, equivalent to "%a %b %e %H:%M:%S %Y"
D Month, day and year. Equivalent to "%m/%d/%y"
C Century number (2 digit)
d 2 digit month
F Year, month and day. Equivalent to "%Y-%m-%d"
e Day of month
H 2 digit hour of day (00-23)
i ISO 8601 date and time. Equivalent to "%Y-%m-%dT%H:%M:%S.%0"
I 2 digit hour of day (12-11)
l hour of day (0-23)
k hour of day (12-11)
j 3 digit day of year
M 2 digit minute (00-59)
m 2 digit month (01-12)
p AM/PM
n New line
R Hour and minute. Equivalent to "%H:%M"
r Time using AM/PM. Equivalent to "%I:%M:%S %p"
S Two digit seconds (00-59)
s Epoch time
t Tab character
T Time in 24-hour. Equivalent to "%H:%M:%S"
u Day of week as decimal.
U Week number as decimal.
V ISO week number.
G Four digit year.
g Two digit year.
v Equivalent to "%e-%b-%Y"
w Day of week as decimal.
W Two digit week of year.
x Date without time. Equivalent to "%m/%d/%y"
X Time without date. Equivalent to "%H:%M:%S"
Y Four digit year with century.
y Two digit year without century.
Z Timezone name.
z Hour and minute offset.
+ Date/time with timezone. Equivalent to "%a, %d %b %Y %H:%M:%S %z"
% Literal percent

Constructor & Destructor Documentation

◆ ETime() [1/5]

ETime::ETime ( )
inline

Default constructor. Initializes to current time.

◆ ETime() [2/5]

ETime::ETime ( const ETime a)
inline

Copy constructor.

◆ ETime() [3/5]

ETime::ETime ( Int  sec,
Int  usec 
)
inline

Class constructor.

Parameters
secthe number of seconds since 00:00 Coordinated Universal Time (UTC), January 1, 1970.
usecthe fractional number of micro seconds.

◆ ETime() [4/5]

ETime::ETime ( LongLong  ms)
inline

Class constructor.

Parameters
msmilliseconds.

◆ ETime() [5/5]

ETime::ETime ( Int  year,
Int  mon,
Int  day,
Int  hour,
Int  min,
Int  sec,
Bool  isLocal 
)

Class constructor.

Parameters
yearthe year.
monthe month.
daythe day of the month.
hourthe hour (24hr).
minthe minute of the hour.
secthe seconds within the minute.
isLocalindicates that this value represents a local time.

◆ ~ETime()

ETime::~ETime ( )
inline

Class destructor.

Member Function Documentation

◆ add() [1/2]

ETime ETime::add ( const timeval &  t)
inline

Adds the timeval amount to the current value.

Parameters
tthe timeval amount to add.
Returns
a new ETime object.

◆ add() [2/2]

ETime ETime::add ( Int  days,
Int  hrs,
Int  mins,
Int  secs,
Int  usecs 
)
inline

Adds the specified days, hours minutes seconds and microseconds to the current value.

Parameters
daysthe number of days to add.
hrsthe number of hours to add.
minsthe number of minutes to add.
secsthe number of seconds to add.
usecsthe number of microseconds to add.
Returns
a new ETime object.

◆ day()

Int ETime::day ( )

Retrieves the day.

Returns
the day.

◆ Format() [1/3]

EString ETime::Format ( cpStr  fmt,
Bool  local 
)
inline

Formats the date/time value as specified by the format string.

Parameters
fmtthe format string.
localindicates if the time/date value is to be converted to the current timezone or not.
Returns
a string containing the formatted output.

◆ Format() [2/3]

void ETime::Format ( EString dest,
cpStr  fmt,
Bool  local 
)

Formats the date/time value as specified by the format string.

Parameters
destcontains the resulting string.
fmtthe format string.
localindicates if the time/date value is to be converted to the current timezone or not.

◆ Format() [3/3]

void ETime::Format ( pStr  dest,
Int  maxsize,
cpStr  fmt,
Bool  local 
)

Formats the date/time value as specified by the format string.

Parameters
destcontains the resulting string.
maxsizethe maximum length of dest.
fmtthe format string.
localindicates if the time/date value is to be converted to the current timezone or not.

◆ getCassandraTimestmap()

LongLong ETime::getCassandraTimestmap ( )
inline

Converts this ETime value to one compatible with a Cassandra timestamp.

Returns
the Cassandra timestamp.

◆ getNTPTime()

void ETime::getNTPTime ( ntp_time_t &  ntp) const

Retrieves the NTP time representation of this ETime object.

Parameters
ntpthe ntp_time_t object that will contain the result.

◆ getTimeVal()

const timeval& ETime::getTimeVal ( )
inline

Retrieves a reference to the timeval structure.

Returns
a reference to the timeval structure.

◆ hour()

Int ETime::hour ( )

Retrieves the hour.

Returns
the hour.

◆ isValid()

Bool ETime::isValid ( )
inline

Indicates whether this ETime object is valid or not.

Returns
True indicates this object is valid, otherwise False.

◆ minute()

Int ETime::minute ( )

Retrieves the minute.

Returns
the minute.

◆ month()

Int ETime::month ( )

Retrieves the month.

Returns
the month.

◆ Now()

ETime ETime::Now ( )
static

Retrieves the current time.

Returns
an ETime object.

◆ operator!=()

Bool ETime::operator!= ( const ETime a)
inline

Inequality operator.

Parameters
athe ETime value to compare to.
Returns
True indicates that the values are not equal, otherwise False (values are equal).

◆ operator+() [1/2]

ETime ETime::operator+ ( const ETime a)
inline

Addition operator.

Parameters
athe ETime value to add to this value.
Returns
a reference to this object.

◆ operator+() [2/2]

ETime ETime::operator+ ( const timeval &  t)
inline

Addition operator.

Parameters
tthe timeval value to add to this value.
Returns
a reference to this object.

◆ operator-() [1/2]

ETime ETime::operator- ( const ETime a)
inline

Subtraction operator.

Parameters
athe ETime value to subtract from this value.
Returns
a reference to this object.

◆ operator-() [2/2]

ETime ETime::operator- ( const timeval &  t)
inline

Subtraction operator.

Parameters
tthe timeval value to subtract from this value.
Returns
a reference to this object.

◆ operator<()

Bool ETime::operator< ( const ETime a)
inline

Less than operator.

Parameters
athe ETime value to compare to.
Returns
True indicates that this value is less than the provided value, otherwise False.

◆ operator<=()

Bool ETime::operator<= ( const ETime a)
inline

Less than or equal to operator.

Parameters
athe ETime value to compare to.
Returns
True indicates that this value is less than or equal to the provided value, otherwise False.

◆ operator=() [1/3]

ETime& ETime::operator= ( const ETime a)
inline

Assignment operator.

Parameters
athe ETime value to copy.
Returns
a reference to this object.

◆ operator=() [2/3]

ETime& ETime::operator= ( const timeval &  a)
inline

Assignment operator.

Parameters
athe timeval value to copy.
Returns
a reference to this object.

◆ operator=() [3/3]

ETime& ETime::operator= ( LongLong  ms)
inline

Assignment operator.

Parameters
msthe milliseconds to set this value to.
Returns
a reference to this object.

◆ operator==()

Bool ETime::operator== ( const ETime a)
inline

Equality operator.

Parameters
athe ETime value to compare to.
Returns
True indicates that the values are equal, otherwise False.

◆ operator>()

Bool ETime::operator> ( const ETime a)
inline

Greater than operator.

Parameters
athe ETime value to compare to.
Returns
True indicates that this value is greater than the provided value, otherwise False.

◆ operator>=()

Bool ETime::operator>= ( const ETime a)
inline

Greater than or equal to operator.

Parameters
athe ETime value to compare to.
Returns
True indicates that this value is greater than or equal to the provided value, otherwise False.

◆ ParseDateTime()

bool ETime::ParseDateTime ( cpStr  pszDate,
Bool  isLocal = True 
)

Parses the string containing the time and date.

Parameters
pszDateNULL terminated string to parse.
isLocalindicates if the time/date string is in local time or not.
Returns
True indicates success, otherwise False.

◆ second()

Int ETime::second ( )

Retrieves the second.

Returns
the second.

◆ set() [1/2]

ETime& ETime::set ( const timeval &  a)
inline

Assigns the specified timeval value to this ETime object.

Parameters
athe timeval value to assign.
Returns
a reference to this object.

◆ set() [2/2]

ETime& ETime::set ( LongLong  ms)
inline

Assigns the specified millisecond value to this ETime object.

Parameters
msthe millisecond value to assign.
Returns
a reference to this object.

◆ setNTPTime()

void ETime::setNTPTime ( const ntp_time_t &  ntp)

Assigns the time represented by the NTP time to this ETime object.

Parameters
ntpthe ntp_time_t object to assign.

◆ subtract() [1/2]

ETime ETime::subtract ( const timeval &  t)
inline

Subtracts the timeval amount to the current value.

Parameters
tthe timeval amount to subtract.
Returns
a new ETime object.

◆ subtract() [2/2]

ETime ETime::subtract ( Int  days,
Int  hrs,
Int  mins,
Int  secs,
Int  usecs 
)
inline

Subtracts the specified days, hours minutes seconds and microseconds to the current value.

Parameters
daysthe number of days to subtract.
hrsthe number of hours to subtract.
minsthe number of minutes to subtract.
secsthe number of seconds to subtract.
usecsthe number of microseconds to subtract.
Returns
a new ETime object.

◆ year()

Int ETime::year ( )

Retrieves the year.

Returns
the year.

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