The Date class stores and manipulates dates. A date is a year-month-day triplet. In
LYRIC years are coded on a 32 bits unsigned integer. This should be enough until the
solar system explodes.
The Date class has day addition and substraction operators. They are implemented
with the best leap year rule I could find, but it is likely the used rule is uncomplete and
will fail somewhen in the future (probably not in the next 1’000 years). A modification of
the leap year rule will be necessary some day.
Synopsis
#include <lyric/Date.hpp>
class Date
{
public:
enum When { Yesterday, Today, Tomorrow };
~Date ();
Date ();
Date (uint32 year, uint8 month, uint8 day);
Date (When when);
Date (const Date& date);
Date& operator = (const Date& date);
Date& operator << (const Date::String& strdate);
bool operator == (const Date& date) const;
bool operator != (const Date& date) const;
bool operator < (const Date& date) const;
bool operator > (const Date& date) const;
bool operator <= (const Date& date) const;
bool operator >= (const Date& date) const;
Date& operator ++ ();
Date& operator -- ();
Date& operator += (uint64 days);
Date& operator -= (uint64 days);
uint32 year () const;
uint8 month () const;
uint8 day () const;
WeekDay weekday () const;
void set (When when);
friend:
Date::String& operator << (Date::String& out, const Date& date);
};
Description
The Date class defines a nested enumerated type When, which defines
date constants. Table 3.2 gives an overview of the defined constants and their
meaning.
|
| When constant | Meaning |
|
| Date::Yesterday | The current system date minus one day. |
Date::Today | The current system date. |
Date::Tomorrow | The current system date plus one day. |
|
| |
Table 3.2: | When date constants and their meaning. |
|
-
˜Date () -
Destroys this date. Release eventually allocated memory resources.
-
Date () -
Constructs this date as an invalid everything set to zero date.
-
Date (uint32 year, uint8 month, uint8 day) -
Constructs this date from the given year, month, day triplet.
As of this release the given year, month, day triplet is not checked against
coherence. Better be sure to enter a valid date. This behaviour is likely to
change in future releases.
-
Date (Date::When when) -
Constructs this date from the given when argument. Table 3.2 gives the
possible values for when and the values this date will store. accordingly.
-
Date& operator = (const Date& date) -
Assigns the given date to this date, and returns a reference to this for
assignment chainig.
-
Date& operator << (const Date::String& strdate) -
Assigns this date from the given date representing string strdate. The date
string is interpreted according to its format and the date values stored in this
date are assigned accordingly. See Section 3.3.1 for the documentation of the
Date::String class.
-
bool operator == (const Date& date) const -
Returns true if the given date and this date are equal (i.e: contain the same
year, month, day triplet); false if not.
-
bool operator != (const Date& date) const -
Returns true if the given date and this date are not equal (i.e: contain a
different year, month, day triplet); false if not.
-
bool operator < (const Date& date) const -
Returns true if this date is smaller than (e.g: preceedes) the given date;
false if not.
-
bool operator > (const Date& date) const -
Returns true if this date is bigger than (e.g: follows) the given date; false
if not.
-
bool operator <= (const Date& date) const -
Returns true if this date is smaller than (e.g: preceedes) or equal to the given
date; false if not.
-
bool operator >= (const Date& date) const -
Returns true if this date is bigger than (e.g: follows) or equal to the given
date; false if not.
-
Date& operator ++ () -
Adds one day to this date, and returns a reference to this for assignement
chaining.
-
Date& operator -- () -
Subsracts one day from this date, and returns a reference to this for
assignement chaining.
-
Date& operator += (uint64 days) -
Adds the given number of days to this date, and returns a reference to this
for assignment chaining.
-
Date& operator -= (uint64 days) -
Substracts the given number of days from this date, and returns a reference
to this for assignment chaining.
-
uint32 year () const -
Returns the year part of this date.
-
uint8 month () const -
Returns the month part of this date.
-
uint8 day () const -
Returns the day part of this date.
-
Date::WeekDay weekday () const -
Returns the day of the week of this date. See Section 3.3.2 for the
documentation of the Date::WeekDay class.
-
void set (Date::When when) -
Sets this date to a given when. Table 3.2 gives the possible values for when
and the values this date will store.
-
Date::String& operator << (Date::String& out, const Date& date) -
Assigns the given date to the output date string, and returns a reference to this
output string. See Section 3.3.1 for the documentation of the Date::String
class.