YGP::ADate Class Reference

Class for date attributes. More...

Inherits YGP::AYear.

Inherited by YGP::ATimestamp [virtual].

List of all members.

Public Member Functions

 ADate ()
 ADate (bool now)
 ADate (const ADate &other)
 ADate (char Day, char Month, int Year) throw (std::invalid_argument)
 ADate (const char *pDate) throw (std::invalid_argument)
 ADate (const std::string &date) throw (std::invalid_argument)
 ADate (const struct tm &tm)
 ADate (const time_t &date)
virtual ~ADate ()
virtual void define ()
void setDay (char Day) throw (std::invalid_argument)
void setMonth (char Month) throw (std::invalid_argument)
void setYear (int Year)
Assignment methods
ADateoperator= (const std::string &date) throw (std::invalid_argument)
ADateoperator= (const struct tm &date)
ADateoperator= (const time_t &date)
ADateoperator= (const ADate &other)
ADateoperator= (const char *pValue) throw (std::invalid_argument)
void assign (const char *pTime, unsigned int len)
virtual void readFromStream (std::istream &in) throw (std::invalid_argument)
Query methods
char getDay () const
char getMonth () const
int getYear () const
Convertion
virtual std::string toUnformattedString () const
virtual std::string toString () const
virtual std::string toString (const char *format) const
time_t toSysTime () const
virtual struct tm toStructTM () const
Comparison
bool operator== (const ADate &other) const
bool operator!= (const ADate &other) const
bool operator< (const ADate &other) const
bool operator> (const ADate &other) const
bool operator<= (const ADate &other) const
bool operator>= (const ADate &other) const
long compare (const ADate &other) const

Static Public Member Functions

static ADate today ()

Protected Member Functions

void incDay ()
void decDay ()
virtual bool minAdapt ()
virtual bool maxAdapt ()

Calculation

ADateoperator+= (const ADate &rhs)
ADateoperator-= (const ADate &rhs)
ADateadd (signed char Day, signed char Month=0, int Year=0)
ADatesub (signed char Day, signed char month=0, int Year=0)
ADate operator+ (const ADate &lhs, const ADate &rhs)
ADate operator- (const ADate &lhs, const ADate &rhs)

Usefull utility-functions

char maxDayOf () const
virtual int checkIntegrity () const
static char maxDayOf (char month, int year)


Detailed Description

Class for date attributes.

As every AYear is supports undefined values.

Note:
It's possible to calculate with ADate objects. But beware, that the results are not always intuitive (e.g. what's today - today? Mathematically it's the 0.0.0, which is not a valid date and therefore changed to the 31.12.-1; a result which might not be expected).
Invariant:
Objects hold always a valid date; even if they are not defined.

Constructor & Destructor Documentation

YGP::ADate::ADate (  )  [inline]

Default constructor; creates an undefined object.

YGP::ADate::ADate ( bool  now  ) 

Constructor; depending on the parameter the date is either set to the first of January, 1900 (now = false), or to the current day (now = true).

Parameters:
now Flag which date to set (1900/1/1 (false) or now (true))

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

Copy constructor from another date object.

YGP::ADate::ADate ( char  Day,
char  Month,
int  Year 
) throw (std::invalid_argument)

Constructor; sets the passed date.

The date is undefined, if the passed parameters represent no valid day.

Parameters:
Day Day for this ADate
Month Month
Year Year to set
Exceptions:
std::invalid_argument in case of an invalid input

YGP::ADate::ADate ( const char *  pDate  )  throw (std::invalid_argument) [inline]

Constructor from a text (unformatted).

YGP::ADate::ADate ( const std::string &  date  )  throw (std::invalid_argument) [inline]

Constructor from a text (unformatted).

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

Constructor from broken down time.

YGP::ADate::ADate ( const time_t &  date  )  [inline]

Construct from system time.

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

Destructor.


Member Function Documentation

ADate & YGP::ADate::add ( signed char  Day,
signed char  Month = 0,
int  Year = 0 
)

If this is not undefined, the passed values are added (with attention to overflows).

The result is returned.

Parameters:
Day Day to add
Month Month to add
Year Year to add
Returns:
ADate& Self
Remarks:
In counterpart to the mathematic operators (operator+() and operator-()) this method does not change the object if it is undefined!

void YGP::ADate::assign ( const char *  pDate,
unsigned int  len 
)

Assignment-operator from a const char-pointer.

The date must be passed either in the local format or as DDMMY[...}. If the buffer does not represent a valid date an excpetion is thrown.

Parameters:
pDate Character array specifying date to assign
len Length of the passed date
Exceptions:
std::invalid_argument if the parameter does not represent a valid date

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

Checks if this object represents a valid date.

Returns:
int Status; 0: OK
Remarks:
Even undefined dates must have valid values!

Reimplemented in YGP::ATimestamp.

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

Returns the (approximated) difference in days between two dates.

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

If both dates are undefined, those difference is "0", if only this is undefined the result is MINLONG; if other is undefined MAXLONG is returned (-> undefined dates are considered as (very) old).

Parameters:
other Object to compare
Returns:
long >0 if this "younger" other; 0 if this == other; <0 else

void YGP::ADate::decDay (  )  [inline, protected]

Decreases the day.

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

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

Reimplemented from YGP::AYear.

Reimplemented in YGP::ATimestamp.

char YGP::ADate::getDay (  )  const [inline]

Returns the actual day.

char YGP::ADate::getMonth (  )  const [inline]

Returns the actual month.

int YGP::ADate::getYear (  )  const [inline]

Returns the actual year.

void YGP::ADate::incDay (  )  [inline, protected]

Increases the day.

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

Corrects the object after an (possible) overflows.

If the object is integer after the operation, true is returned.

Returns:
bool Flag, if object is integer

Reimplemented in YGP::ATimestamp.

char YGP::ADate::maxDayOf ( char  month,
int  year 
) [static]

Returns the maximal day for the the passed month/year-combination.

Parameters:
month Month to check
year Year to check
Returns:
char Maximal day for the passed parameters [28 - 31]

char YGP::ADate::maxDayOf (  )  const [inline]

Returns the maximal day of the specified month (in the passed year).

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

Corrects the object after an (possible) underflows.

If the object is integer after the operation, true is returned.

Returns:
bool Flag, if object is integer

Reimplemented in YGP::ATimestamp.

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

Compares if two objects are not equal

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

Adds another date-value to the date-object.

An undefined date is treated as 0.0.0; so only if both objects are undefined, the result is (remains) undefined. Overflows (of day or month) are corrected.

Parameters:
rhs Value to add
Returns:
ADate& Self

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

Substracts another date-value from the date-object.

An undefined date is treated as 0.0.0; the result is (remains) undefined if both objects are undefined. Underflows (of day or month) are corrected.

Parameters:
rhs Value to substract
Returns:
ADate& Self

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

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

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

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

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

Assignment-operator from a const char-pointer.

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

Parameters:
pValue Character array holding date to assign
Returns:
ADate& Reference to self
Exceptions:
std::invalid_argument if the characters don't represent a valid date

Reimplemented from YGP::AYear.

Reimplemented in YGP::ATimestamp.

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

Assignment-operator.

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

ADate& YGP::ADate::operator= ( const time_t &  date  )  [inline]

Assignment operator from system time

Reimplemented in YGP::ATimestamp.

ADate & YGP::ADate::operator= ( const struct tm &  date  ) 

Assignment operator from a broken down time structure.

Parameters:
date Structure holding the date to assign
Returns:
ADate& Reference to self

Reimplemented in YGP::ATimestamp.

ADate& YGP::ADate::operator= ( const std::string &  date  )  throw (std::invalid_argument) [inline]

Assignment operator from an (unformatted) text.

Reimplemented from YGP::AYear.

Reimplemented in YGP::ATimestamp.

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

Compares two objects for equalnesss

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

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

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

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

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

Reads a date as DDMMY[Y.

..] from a stream. If the input is not valid, an exception is thrown.

Parameters:
in:Stream to parse
Exceptions:
std::invalid_argument in case of an invalid input

Reimplemented from YGP::AYear.

Reimplemented in YGP::ATimestamp.

void YGP::ADate::setDay ( char  Day  )  throw (std::invalid_argument)

Sets the day to the passed value.

If the date is not valid, it is set to undefined.

Parameters:
Day Day to set

void YGP::ADate::setMonth ( char  Month  )  throw (std::invalid_argument)

Sets the month to the passed value.

If the date is not valid, it is set to undefined.

Parameters:
Month Month to set

void YGP::ADate::setYear ( int  Year  )  [inline]

Sets the year of the date object.

ADate & YGP::ADate::sub ( signed char  Day,
signed char  Month = 0,
int  Year = 0 
)

If this is defined, the passed values are substracted (with attention to underflows).

The result is returned.

Parameters:
Day Day to substract
Month Month to substract
Year Year to substract
Returns:
ADate& Self
Remarks:
In counterpart to the mathematic operators (operator+() and operator-()) this method does not change the object if it is undefined!

static ADate YGP::ADate::today (  )  [inline, static]

Returns the current date.

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

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

The parameter format can be any value accepted by the strftime std::string String-representation of ADate

Remarks:
Only dates valid for struct tm can be printed (e.g. dates after 1900)

Reimplemented in YGP::ATimestamp.

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

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

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

Reimplemented from YGP::AttributValue.

Reimplemented in YGP::ATimestamp.

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

Converting to a struct tm.

Returns:
struct tm Date in struct tm-format; the time-part is set to zeros
Remarks:
It is not checked if the date is in the right range for a

Reimplemented in YGP::ATimestamp.

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

Converting into a system time.

Reimplemented in YGP::ATimestamp.

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

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

..]; each entry is filled up with zeros.

Returns:
std::string String-representation of ADate

Reimplemented from YGP::AYear.

Reimplemented in YGP::ATimestamp.


Friends And Related Function Documentation

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

Adds two date-values and returns the result.

An undefined date is treated as "0.0.0"; the result is (remains) undefined if both objects are undefined. Overflows (of day or month) are corrected.

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

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

Substracts two date-values and returns the result.

An undefined date is treated as "0.0.0"; the result is (remains) undefined if both objects are undefined. Overflows (of day or month) are corrected.

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


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