Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWDate

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

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 "Using Class RWDate" in the Tools.h++ User's Guide.

RWDate's can be converted to and from RWTime's, and to and from the Standard C library type struct tm defined in <time.h>.

Note that using a 2-digit year specifier in your code may lead to less-than-perfect behavior at the turn of the century. We urge you to create programs that are "millenially correct" by using 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.

RWDate v[5000];     // Figures out the current date 5000 times

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

// Figures out the current date just once:
RWTValOrderedVector<RWDate> v(5000, RWDate());

Thanks to the smart allocation scheme of the standard collections, the above declaration will result 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

#include <rw/rwdate.h>
#include <rw/rstream.h>

main(){
  // Today's date
  RWDate d;

  // Last Sunday's date:
  RWDate lastSunday = d.previous("Sunday");

  cout << d << endl << lastSunday << endl;
}

Program output:

03/22/91
03/17/91

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;
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 dayNum, 
            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 documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.