YGP::ATimestamp Class Reference

Class for timestamp (containing date and time) attributes. More...

Inherits YGP::ADate, and YGP::ATime.

List of all members.

Public Member Functions

 ATimestamp ()
 ATimestamp (bool now)
 ATimestamp (const ATimestamp &other)
 ATimestamp (char Day, char Month, int Year, char Hour, char minute, char second) throw (std::invalid_argument)
 ATimestamp (const char *pStamp) throw (std::invalid_argument)
 ATimestamp (const std::string &stamp) throw (std::invalid_argument)
 ATimestamp (const struct tm &tm)
 ATimestamp (const time_t &stamp, bool local=true)
virtual ~ATimestamp ()
bool isDefined () const
virtual void undefine ()
virtual void define ()
int checkIntegrity () const
Assignment methods
ATimestampoperator= (const std::string &stamp) throw (std::invalid_argument)
ATimestampoperator= (const char *pValue) throw (std::invalid_argument)
ATimestampoperator= (const struct tm &tm)
ATimestampoperator= (const ATimestamp &other)
ATimestampoperator= (const time_t &stamp)
ATimestampassignGMT (const time_t &stamp)
virtual void readFromStream (std::istream &in) throw (std::invalid_argument)
Convertion
virtual std::string toUnformattedString () const
virtual std::string toString () const
virtual std::string toString (const char *format) const
time_t toSysTime () const
struct tm toStructTM () const
time_t toGMTTime () const
time_t toLocalTime () const
Comparison
bool operator== (const ATimestamp &other) const
bool operator!= (const ATimestamp &other) const
bool operator< (const ATimestamp &other) const
bool operator> (const ATimestamp &other) const
bool operator<= (const ATimestamp &other) const
bool operator>= (const ATimestamp &other) const
long compare (const ATimestamp &other) const

Static Public Member Functions

static ATimestamp now ()

Protected Member Functions

virtual bool maxAdapt ()
virtual bool minAdapt ()

Friends

std::istream & operator>> (std::istream &in, ATimestamp &inValue)
std::ostream & operator<< (std::ostream &out, const ATimestamp &outValue)

Calculation

ATimestampoperator+= (const ATimestamp &rhs)
ATimestampoperator-= (const ATimestamp &rhs)
ATimestampadd (char Day, char Month=0, int Year=0, char Hour=0, char minute=0, char second=0)
ATimestampsub (char Day, char month=0, int Year=0, char Hour=0, char minute=0, char second=0)
ATimestamp operator+ (const ATimestamp &lhs, const ATimestamp &rhs)
ATimestamp operator- (const ATimestamp &lhs, const ATimestamp &rhs)


Detailed Description

Class for timestamp (containing date and time) attributes.

As every AttributValue is supports undefined values.


Constructor & Destructor Documentation

YGP::ATimestamp::ATimestamp (  ) 

Defaultconstructor; the timestamp is not defined.

YGP::ATimestamp::ATimestamp ( bool  now  ) 

Constructor; depending on the parameter the timestamp is either set to the 1st of January, 1900 0:00:00 (now = false), or to the current time (now = true).

Parameters:
now Flag if current time or default time (1.1.1900) should be set

YGP::ATimestamp::ATimestamp ( const ATimestamp other  )  [inline]

Copy constructor from another ATimestamp object.

YGP::ATimestamp::ATimestamp ( char  Day,
char  Month,
int  Year,
char  Hour,
char  minute,
char  second 
) throw (std::invalid_argument)

Constructor; sets the passed time.

The object is undefined, if the passed parameters represent no valid date/time-combination (e.g. Hour > 23, minute > 59, second > 61 or day > 31).

Parameters:
Day Day for this object
Month Month of this object
Year Year of this object
Hour Hour of this object
minute Minute of this object
second Other time-parameters

YGP::ATimestamp::ATimestamp ( const char *  pStamp  )  throw (std::invalid_argument) [inline]

Constructor from an (unformatted) text.

YGP::ATimestamp::ATimestamp ( const std::string &  stamp  )  throw (std::invalid_argument) [inline]

Constructor from an (unformatted) text.

YGP::ATimestamp::ATimestamp ( const struct tm &  tm  )  [inline]

Constructor from a broken down time.

YGP::ATimestamp::ATimestamp ( const time_t &  stamp,
bool  local = true 
) [inline]

Constructor from a system time.

YGP::ATimestamp::~ATimestamp (  )  [virtual]

Destructor.


Member Function Documentation

ATimestamp & YGP::ATimestamp::add ( char  Day,
char  Month = 0,
int  Year = 0,
char  Hour = 0,
char  minute = 0,
char  second = 0 
)

If this is not undefined, the passed values are added.

Overflows are corrected. The result is returned. In counterpart to the mathematic operators (+ and -) this method does not change the object if it is undefined!

Parameters:
Day Day to add
Month Month to add
Year Year to add
Hour Hour to add
minute Minute to add
second Second to add
Returns:
ATimestamp& Self

ATimestamp& YGP::ATimestamp::assignGMT ( const time_t &  stamp  )  [inline]

Assignment operator from an (unformatted) text.

int YGP::ATimestamp::checkIntegrity (  )  const [virtual]

Checks if this object represents a valid timestamp.

Note: Even undefined times must have valid values!

Returns:
int Status; 0: OK

Reimplemented from YGP::ADate.

long YGP::ATimestamp::compare ( const ATimestamp other  )  const

Returns the (approximated) difference in days, or - if the day is equal - in seconds between two timestamps.

"Younger times" (closer to the past) are considered bigger than "older times" (further in the past; that means the numeric value of the time is compared (e.g.: "yesterday" < "now" < "tomorrow").

If both objects are undefined, those difference is "0", if only this is undefined the result is MINLONG, if only other is undefined MAXLONG is returned (-> undefined times are considered to be very old).

Parameters:
other Object to compare
Returns:
long >0 if this is closer to the past than other; 0 if this == other; <0 else

virtual void YGP::ATimestamp::define (  )  [inline, virtual]

Defining the object; setting it to a default value (of 1/1/1900 0:0:0).

Reimplemented from YGP::ADate.

bool YGP::ATimestamp::isDefined (  )  const [inline]

Checks if the object is defined (has a value).

Reimplemented from YGP::AttributValue.

bool YGP::ATimestamp::maxAdapt (  )  [protected, virtual]

Corrects the object after overflows.

If the the object is integer after the operation, true is returned (else false).

Returns:
bool True, if object is integer after the operation

Reimplemented from YGP::ADate.

bool YGP::ATimestamp::minAdapt (  )  [protected, virtual]

Corrects the object after underflows.

If the the object is integer after the operation, true is returned (else false).

Returns:
bool True, if object is integer after the operation

Reimplemented from YGP::ADate.

static ATimestamp YGP::ATimestamp::now (  )  [inline, static]

Returns the current date/time.

Reimplemented from YGP::ATime.

bool YGP::ATimestamp::operator!= ( const ATimestamp other  )  const [inline]

Compares if two objects are not equal

ATimestamp & YGP::ATimestamp::operator+= ( const ATimestamp rhs  ) 

Adds another timestamp-value to the object.

An undefined timestamp is treated as "0.0.0 0:00:00"; if both objects are undefined, the result is undefined. Overflows are corrected.

Parameters:
rhs Value to add
Returns:
ATimestamp& Self

ATimestamp & YGP::ATimestamp::operator-= ( const ATimestamp rhs  ) 

Substracts another timestamp-value to the object.

An undefined timestamp is treated as "0.0.0 0:00:00"; if both objects are undefined, the result is undefined. Underflows are corrected.

Parameters:
rhs Value to substract
Returns:
ATimestamp& Self

bool YGP::ATimestamp::operator< ( const ATimestamp other  )  const [inline]

Checks if one object is "younger" than the other. See compare() for details.

bool YGP::ATimestamp::operator<= ( const ATimestamp other  )  const [inline]

Checks if one object is "younger" than or equal to the other. See compare() for details.

ATimestamp& YGP::ATimestamp::operator= ( const time_t &  stamp  )  [inline]

Assignment operator from an (unformatted) text.

Reimplemented from YGP::ADate.

ATimestamp & YGP::ATimestamp::operator= ( const ATimestamp other  ) 

Assignment-operator from another timestamp object.

Parameters:
other Object to assign
Returns:
ATimestamp& Reference to self

ATimestamp & YGP::ATimestamp::operator= ( const struct tm &  tm  ) 

Assignment-operator; assigns the values from the passed struct tm.

Parameters:
tm Object to assign as char-string
Returns:
ATimestamp& Reference to self

Reimplemented from YGP::ADate.

ATimestamp & YGP::ATimestamp::operator= ( const char *  pValue  )  throw (std::invalid_argument)

Assignment-operator from an const char-pointer.

The timestamp must be passed as DDMMY[Y...] hhmmss. If the buffer does not represent a valid timestamp, an exception is thrown.

Parameters:
pValue Character array specifying timestamp to assign
Returns:
ATimestamp& Reference to self
Exceptions:
std::invalid_argument if the parameters has a wrong format
Remarks:
A NULL-pointer as parameter is not permitted!

Reimplemented from YGP::ADate.

ATimestamp& YGP::ATimestamp::operator= ( const std::string &  stamp  )  throw (std::invalid_argument) [inline]

Assignment operator from an (unformatted) text.

Reimplemented from YGP::ADate.

bool YGP::ATimestamp::operator== ( const ATimestamp other  )  const [inline]

Compares two objects for equalnesss

bool YGP::ATimestamp::operator> ( const ATimestamp other  )  const [inline]

Checks if one object is "older" than the other. See compare() for details.

bool YGP::ATimestamp::operator>= ( const ATimestamp other  )  const [inline]

Checks if one object is "older" than or equal to the other. See compare() for details.

void YGP::ATimestamp::readFromStream ( std::istream &  in  )  throw (std::invalid_argument) [virtual]

Reads the timestamp in the format DDMMY[Y.

..] hhmmss (with leading zeros) from a stream. If the input is not a valid timestamp an exception is thrown.

Parameters:
in Stream to parse
Exceptions:
std::invalid_argument in case of a format error

Reimplemented from YGP::ADate.

ATimestamp & YGP::ATimestamp::sub ( char  Day,
char  Month = 0,
int  Year = 0,
char  Hour = 0,
char  minute = 0,
char  second = 0 
)

If this is not undefined, the passed values are substracted.

Underflows are corrected. The result is returned. In counterpart to the mathematic operators (+ and -) this method does not change the object if it is undefined!

Parameters:
Day Day to substract
Month Month to substract
Year Year to substract
Hour Hour to substract
minute Minute to substract
second Second to substract
Returns:
ATimestamp& Self

time_t YGP::ATimestamp::toGMTTime (  )  const

Converts the object to a system-timestructure (as GMT).

Returns:
time_t Converted time

time_t YGP::ATimestamp::toLocalTime (  )  const [inline]

Converting into a system time (local time)

std::string YGP::ATimestamp::toString ( const char *  format  )  const [virtual]

Converts the object into a string, in the specified format.

The parameter format can be any value accepted by the strftime library-routine.

Returns:
String-representation of the object
Remarks:
Only dates valid for struct tm can be printed (e.g. dates after 1900)

Reimplemented from YGP::ADate.

std::string YGP::ATimestamp::toString (  )  const [virtual]

Converts the object into a string, in a format specified by the current locale.

Returns:
String-representation of the object
Remarks:
Only dates valid for struct tm can be printed (e.g. dates after 1900)

Reimplemented from YGP::ADate.

struct tm YGP::ATimestamp::toStructTM (  )  const [read, virtual]

Converts the object to a struct tm.

Returns:
struct tm Timestamp in struct tm-format
Remarks:
It is not checked if the date is in the right range for a struct tm (after 1900 and before 2039)

Reimplemented from YGP::ADate.

time_t YGP::ATimestamp::toSysTime (  )  const [inline]

Converting into a system time (GMT).

Reimplemented from YGP::ADate.

std::string YGP::ATimestamp::toUnformattedString (  )  const [virtual]

Converts the object into a string, in the format DDMMYYYY[.

..] hhmmss.

Returns:
String-representation of ATimestamp

Reimplemented from YGP::ADate.

virtual void YGP::ATimestamp::undefine (  )  [inline, virtual]

Undefines the object.

Undefines the object (has no value anymore)

Reimplemented from YGP::AttributValue.


Friends And Related Function Documentation

ATimestamp operator+ ( const ATimestamp lhs,
const ATimestamp rhs 
) [friend]

Returns the addition of two timestamp-values.

An undefined time is treated as "0.0.0 0:00:00"; if both objects are undefined, the result is undefined. Overflows are corrected.

Parameters:
lhs Left-hand-side of addition
rhs Right-hand-side of addition
Returns:
ATimestamp Result of additon

ATimestamp operator- ( const ATimestamp lhs,
const ATimestamp rhs 
) [friend]

Returns the substraction of two timestamp-values.

An undefined time is treated as "0.0.0 0:00:00"; if both objects are undefined, the result is undefined. Underflows are corrected.

Parameters:
lhs Left-hand-side of substraction
rhs Right-hand-side of substraction
Returns:
ATimestamp Result of substraction

std::ostream& operator<< ( std::ostream &  out,
const ATimestamp outValue 
) [friend]

Output to a stream using the toUnformattedString() method.

std::istream& operator>> ( std::istream &  in,
ATimestamp inValue 
) [friend]

Input from a stream using the readFromStream() method.


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

YGP Version 0.9.31 - Generated on Wed Nov 18 11:25:27 2009 by doxygen 1.5.8