Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Tools Module Reference Guide

RWDate

Module:  Essential Tools Module   Group:  Date and Time


Does not inherit

Local Index

Members

Non-Members

Synopsis

#include <rw/rwdate.h>
RWDate a;   // Construct today's date

Description

Class RWDate represents a date, stored as a Julian day number. The member function isValid() can be used to determine whether an RWDate is a valid date. For example, isValid() would return FALSE for the date 29 February 1991 because 1991 is not a leap year. See the chapter on date and time classes in the Essential Tools Module User's Guide.


NOTE -- The Essential Tools Module now includes the class RWDateTime combining functionality from RWDate and RWTime, but with a much greater range and millisecond accuracy. This works around a limitation in RWTime which can only represent time until the year 2037. RWDate will be deprecated in a future major release of the Essential Tools Module.

RWDates can be converted to and from RWTimes, and to and from the Standard C Library type struct tm defined in <time.h>.

We recommend creating programs that use 4-digit year specifiers.

Note that because the default constructor for this class creates an instance holding the current date, constructing a large array of RWDate may be slow.

Those with access to the Standard C++ Library-based versions of the Essential Tools Module template collections should consider the following:

Thanks to the smart allocation scheme of the standard collections, the above declaration results in only one call to the default constructor followed by 5000 invocations of the copy constructor. In the case of RWDate, the copy constructor amounts to an assignment of one long to another, resulting in faster creation than the simple array.

Persistence

Simple

Example

Program output:

Public Constructors

RWDate();
RWDate(const RWDate&);
RWDate(unsigned day, unsigned year);
RWDate(unsigned day, unsigned month, unsigned year);
RWDate(unsigned day, const char* mon, unsigned year,
       const RWLocale& locale = RWLocale::global());
RWDate(istream& s,const RWLocale& locale = 
       RWLocale::global());
RWDate(const RWCString& str, 
       const RWLocale& locale = RWLocale::global());
RWDate(const RWTime& t, 
       const RWZone& zone = RWZone::local());
RWDate(const struct tm*);
RWDate(unsigned long jd);

Public Member Operators

RWDate&
operator=(const RWDate&);
RWDate
operator++();
RWDate
operator--();
RWDate
operator++(int);
RWDate
operator--(int);
RWDate&
operator+=(unsigned long s);
RWDate&
operator-=(unsigned long s);

Public Member Functions

RWCString
asString(char format = 'x', 
         const RWLocale& = RWLocale::global()) const;
RWCString
asString(const char* format, 
         const RWLocale& = RWLocale::global()) const;
RWBoolean
between(const RWDate& a, const RWDate& b) const;
size_t
binaryStoreSize() const;
int
compareTo(const RWDate* d) const;
unsigned
day() const;
unsigned
dayOfMonth() const;
void
extract(struct tm*) const;
unsigned
firstDayOfMonth() const;
unsigned
firstDayOfMonth(unsigned month) const;
unsigned
hash() const;
RWBoolean
isValid() const;

NOTE -- The next two functions let you manipulate the date via Julian days. Note that the Julian day number is not the same as a date according to the Julian calendar. The Julian day number is calculated using Algorithm 199 from Communications of the ACM, Volume 6, No. 8, (Aug. 1963), p. 444 and is valid for any valid Gregorian date in the Gregorian calendar. The User's Guide provides more information.
unsigned long
julian() const;
void
julian(unsigned long j);
RWBoolean
leap() const;
RWDate
max(const RWDate& t) const;
RWDate
min(const RWDate& t) const;
unsigned
month() const;
RWCString
monthName(const RWLocale& = RWLocale::global()) const;
RWDate
next(unsigned dayNum) const;
RWDate
next(const char* dayName, 
     const RWLocale& = RWLocale::global()) const;
RWDate
previous(unsigned dayNum) const;
RWDate
previous(const char* dayName, 
         const RWLocale& = RWLocale::global()) const;
RWCString
weekDayName(const RWLocale& = RWLocale::global()) const;
unsigned
weekDay() const;
unsigned
year() const;

Static Public Member Functions

static unsigned
dayOfWeek(const char* dayName, 
          const RWLocale& = RWLocale::global());
static unsigned
daysInMonthYear(unsigned month, unsigned year);
static unsigned
daysInYear(unsigned year);
static RWBoolean
dayWithinMonth(unsigned monthNum, unsigned dayNum,
               unsigned year);
static unsigned
hash(const RWDate& d);
static unsigned
indexOfMonth(const char* monthName,
             const RWLocale& = RWLocale::global());
static unsigned long
jday(unsigned mon, unsigned day, unsigned year);
static RWCString
nameOfMonth(unsigned monNum, 
            const RWLocale& = RWLocale::global());
static RWBoolean
leapYear(unsigned year);
static RWDate
now();
static RWCString
weekDayName(unsigned const RWLocale& = RWLocale::global());

Related Global Operators

RWBoolean
operator<(const RWDate& d1, const RWDate& d2);
RWBoolean
operator<=(const RWDate& d1, const RWDate& d2);
RWBoolean
operator>(const RWDate& d1, const RWDate& d2);
RWBoolean
operator>=(const RWDate& d1, const RWDate& d2);
RWBoolean
operator==(const RWDate& d1, const RWDate& d2);
RWBoolean
operator!=(const RWDate& d1, const RWDate& d2);
RWDate
operator+(const RWDate& d, unsigned long s);
RWDate
operator+(unsigned long s, const RWDate& d);
unsigned long
operator-(const RWDate& d1, const RWDate& d2);
RWDate
operator-(const RWDate& d, unsigned long s);
ostream&
operator<<(ostream& s, const RWDate& d);
istream&
operator>>(istream& s, RWDate& t);
RWvostream&
operator<<(RWvostream&, const RWDate& date);
RWFile&
operator<<(RWFile&,     const RWDate& date);
RWvistream&
operator>>(RWvistream&, RWDate& date);
RWFile&
operator>>(RWFile&,     RWDate& date);


Previous fileTop of DocumentContentsIndex pageNext file

©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.