Wt::WDate Class Reference

A gregorian calendar date. More...

List of all members.

Public Member Functions

 WDate ()
 Construct a Null date.
 WDate (long modifiedJulianDays)
 Create a representing a modified Julian Days count.
 WDate (int year, int month, int day)
 Specify a date by year, month (1-12), and day (1-31).
void setDate (int year, int month, int day)
 Set a date by year, month (1-12), and day (1-31).
WDate addDays (int ndays) const
 Add days to a date.
WDate addMonths (int nmonths) const
 Add months to a date.
WDate addYears (int nyears) const
 Add years to a date.
bool isNull () const
 Returns if this date is Null.
bool isValid () const
 Returns if this date is valid.
int year () const
 Year.
int month () const
 Month (1-12).
int day () const
 Day of month (1-31).
int dayOfWeek () const
 Day of week (1-7).
int daysTo (const WDate &d) const
 Returns the number of days from this date to d.
long modifiedJulianDay () const
 Returns the modified Julian day corresponding to this date.
bool operator< (const WDate &other) const
 Compare two dates.
bool operator<= (const WDate &other) const
 Compare two dates.
bool operator> (const WDate &other) const
 Compare two dates.
bool operator>= (const WDate &other) const
 Compare two dates.
bool operator== (const WDate &other) const
 Compare two dates.
bool operator!= (const WDate &other) const
 Compare two dates.
WString toString () const
 Format this date to a WString using a default format.
WString toString (const WString &format) const
 Format this date to a WString using a specified format.

Static Public Member Functions

static WDate fromString (const WString &s)
 Parse a WString to a date using a default format.
static WDate fromString (const WString &s, const WString &format)
 Parse a WString to a date using a specified format.
static WDate currentDate ()
 Construct a date for the current client date.
static WDate currentServerDate ()
 Construct a date for the current server date.
static WString shortDayName (int weekday)
 Returns the short day name.
static WString shortMonthName (int month)
 Returns the short month name.
static WString longDayName (int weekday)
 Returns the long day name.
static WString longMonthName (int month)
 Returns the long month name.


Detailed Description

A gregorian calendar date.

Class which holds a date on the gregorian calendar, specified as day/month/year.

A WDate may either specify a valid date, or be a Null date (using the default constructor WDate::WDate(), for which isNull() returns true).

A valid date may be specified by year, month, and day of month (using the WDate(int year, int month, int day) constructor, or the setDate() method). When attempting to specify an invalid date (with an impossible combination of year/month/date), isIvalid() will return false.

The class provides a flexible way for converting between strings and dates. Use toString() to convert to strings, and fromString() for parsing strings. Both methods take a format string, and the same format syntax is supported by both methods.

Simple operations are supported to compare dates, or to calculate with dates. These operations throw InvalidDateException when one of the dates is invalid.

This class is still missing localization support in its conversion methods from and to string representations.


Constructor & Destructor Documentation

Wt::WDate::WDate (  ) 

Construct a Null date.

A date for which isNull() returns true. A Null date is also invalid.

See also:
isValid(), isNull()

Wt::WDate::WDate ( long  modifiedJulianDays  ) 

Create a representing a modified Julian Days count.

The modified Julian day is the number of days since Wednesday November 17, 1858.

Wt::WDate::WDate ( int  year,
int  month,
int  day 
)

Specify a date by year, month (1-12), and day (1-31).

When the date is invalid, isValid() is set to false.

See also:
setDate(), year(), month(), day()


Member Function Documentation

void Wt::WDate::setDate ( int  year,
int  month,
int  day 
)

Set a date by year, month (1-12), and day (1-31).

When the new date is invalid, isValid() is set to false.

See also:
WDate(int year, int month, int day), year(), month(), day()

WDate Wt::WDate::addDays ( int  ndays  )  const

Add days to a date.

Returns a date that is ndays later than this date. Negative values for ndays will result in a date that is as many days earlier.

See also:
addMonths(), addYears()

WDate Wt::WDate::addMonths ( int  nmonths  )  const

Add months to a date.

Returns a date that is the same day of the month, but nmonths later than this date. Negative values for nmonths will result in a date that is as many months earlier.

See also:
addDays(), addYears()

WDate Wt::WDate::addYears ( int  nyears  )  const

Add years to a date.

Returns a date that is nyears later than this date. Negative values for nyears will result in a date that is as many years earlier.

See also:
addDays(), addMonths()

bool Wt::WDate::isNull (  )  const

Returns if this date is Null.

A null date is also invalid.

See also:
isValid(), WDate()

bool Wt::WDate::isValid (  )  const [inline]

Returns if this date is valid.

See also:
isNull(), WDate(int, int, int), setDate()

int Wt::WDate::dayOfWeek (  )  const

Day of week (1-7).

Returns the day of week, from Monday (=1) to Sunday (=7).

long Wt::WDate::modifiedJulianDay (  )  const

Returns the modified Julian day corresponding to this date.

The modified Julian day is the number of days since Wednesday November 17, 1858.

WString Wt::WDate::toString (  )  const

Format this date to a WString using a default format.

The default format is "ddd MMM d yyyy". For example, a date constructed as:

   WDate d(2007,8,29);
will be formatted as:
   "Wed Aug 29 2007"

See also:
toString(const WString& format) const, fromString()

WString Wt::WDate::toString ( const WString format  )  const

Format this date to a WString using a specified format.

The format is a string in which the following contents has a special meaning.

CodeMeaning Example (for Mon Aug 3 2007)
dThe day as a one or two-digit number 3
ddThe day as a two-digit number (with leading 0) 03
dddThe day abbreviated using shortDayName() Mon
ddddThe day abbreviated using longDayName() Monday
MThe month as a one or two-digit number 8
MMThe month as a two-digit number (with leading 0) 08
MMMThe month abbreviated using shortMonthName() Aug
MMMMThe month abbreviated using longMonthName() August
yyThe year as a two-digit number 07
yyyyThe year as a four-digit number 2007

Any other text is kept literally. String content between single quotes (') are not interpreted as special codes. Inside a string, a literal quote may be specifed using a double quote ('').

Example of format and result:
FormatResult (for Mon Aug 3 2007)
ddd MMM d yyyyMon Aug 3 2007
dd/MM/yyyy03/08/2007
dddd, MMM d, yyyyWednesday, Aug 3, 2007
'MM': MM, 'd': d, 'yyyy': yyyyMM: 08, d: 3, yyyy: 2007

See also:
fromString(const WString& value, const WString& format)

WDate Wt::WDate::fromString ( const WString s  )  [static]

Parse a WString to a date using a default format.

The default format is "ddd MMM d yyyy". For example, a date specified as:

   "Wed Aug 29 2007"
will be parsed as a date that equals a date constructed as:
   WDate d(2007,8,29);

When the date could not be parsed or is not valid, an invalid date is returned (for which isValid() returns false).

See also:
fromString(const WString& s, const WString& format), isValid()

WDate Wt::WDate::fromString ( const WString s,
const WString format 
) [static]

Parse a WString to a date using a specified format.

The format follows the same syntax as used by toString(const WString& format).

When the date could not be parsed or is not valid, an invalid date is returned (for which isValid() returns false).

See also:
toString(const WString&) const

WDate Wt::WDate::currentDate (  )  [static]

Construct a date for the current client date.

This method uses browser information to retrieve the date that is configured in the client.

WDate Wt::WDate::currentServerDate (  )  [static]

Construct a date for the current server date.

This method returns the date as indicated by the system clock of the server.

WString Wt::WDate::shortDayName ( int  weekday  )  [static]

Returns the short day name.

Results (for given weekDay) are:
"Mon" (1),
"Tue" (2),
"Wed" (3),
"Thu" (4),
"Fri" (5),
"Sat" (6),
"Sun" (7).

See also:
longDayName()

WString Wt::WDate::shortMonthName ( int  month  )  [static]

Returns the short month name.

Results (for given month) are:
"Jan" (1),
"Feb" (2),
"Mar" (3),
"Apr" (4),
"May" (5),
"Jun" (6),
"Jul" (7),
"Aug" (8),
"Sep" (9),
"Oct" (10),
"Nov" (11),
"Dec" (12)
.

See also:
longMonthName()

WString Wt::WDate::longDayName ( int  weekday  )  [static]

Returns the long day name.

Results (for given weekDay) are:
"Monday" (1),
"Tuesday" (2),
"Wednesday" (3),
"Thursday" (4),
"Friday" (5),
"Saturday" (6),
"Sunday" (7).

See also:
shortDayName()

WString Wt::WDate::longMonthName ( int  month  )  [static]

Returns the long month name.

Results (for given month) are:
"January" (1),
"February" (2),
"March" (3),
"April" (4),
"May" (5),
"June" (6),
"July" (7),
"August" (8),
"September" (9),
"October" (10),
"November" (11),
"December" (12).

See also:
shortDayName()


Generated on Mon Nov 3 15:00:59 2008 for Wt by doxygen 1.5.6