home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWDATE_H__
- #define __RWDATE_H__
- pragma push_align_members(64);
-
- /*
- * Declarations for RWDate Class
- *
- * $Header: E:/vcs/rw/rwdate.h_v 1.7 17 Mar 1992 11:59:16 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave Software, Inc.
- * P.O. Box 2328
- * Corvallis, OR 97339
- * Voice: (503) 754-3010 FAX: (503) 757-6650
- *
- * Copyright (C) 1989, 1990, 1991. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * An RWDate can be tested for validity using the member function isValid().
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/rw/rwdate.h_v $
- *
- * Rev 1.7 17 Mar 1992 11:59:16 KEFFER
- * Pre- and post-increment and decrement operators now have a return type.
- *
- * Rev 1.6 04 Mar 1992 10:21:20 KEFFER
- * Instance manager used in multi-thread situation.
- *
- * Rev 1.3 13 Nov 1991 11:10:24 keffer
- * Static variables maintained by a manager for multi-thread version
- *
- * Rev 1.2 29 Oct 1991 13:57:32 keffer
- * Added postfix ++ and --.
- *
- * Rev 1.1 28 Oct 1991 09:08:20 keffer
- * Changed inclusions to <rw/xxx.h>
- *
- */
-
- #include "rw/tooldefs.h"
- #include "rw/procinit.h" /* Uses instance manager */
-
- class RWExport RWTime;
- class RWExport RWCString;
-
- typedef unsigned dayTy;
- typedef unsigned monthTy;
- typedef unsigned yearTy;
- typedef unsigned long julTy;
- static const julTy jul1901 = 2415386L; // Julian day for 1/1/1901
-
- class RWExport RWDate {
- public:
- enum howToPrint {normal, terse, numbers, europeanNumbers, european};
- private:
- julTy julnum; // Julian Day Number (Not same as Julian date.)
- #ifndef RW_MULTI_THREAD
- /* If not compiling for an MT situation, then use static data--- */
- static howToPrint printOption; // Printing with different formats
- #endif
- private:
- void parseFrom(istream&); // Reading dates
- void near mdy(monthTy&, dayTy&, yearTy&) const;
- RWDate(julTy j) {julnum = j; }
- protected:
- static RWBoolean assertWeekDayNumber(dayTy d)
- {return d>=1 && d<=7;}
- static RWBoolean assertIndexOfMonth(monthTy m)
- {return m>=1 && m<=12;}
- public:
-
- // Construct a RWDate with the current date
- RWDate();
-
- /* Construct a RWDate with a given day of the year and a given year.
- The base date for this computation is Dec. 31 of the previous year.
- If year == 0, Construct a RWDate with Jan. 1, 1901 as the "day zero".
- i.e., RWDate(-1) = Dec. 31, 1900 and RWDate(1) = Jan. 2, 1901. */
- RWDate(dayTy day, yearTy year);
-
- // Construct a RWDate for the given day, month, and year.
- RWDate(dayTy, const char* month, yearTy);
- RWDate(dayTy, monthTy, yearTy);
- RWDate(istream& s) {parseFrom(s);} // Read date from stream.
- RWDate(const RWTime&); // Construct an RWDate from an RWTime
-
- RWCString asString() const;
- RWBoolean between(const RWDate& d1, const RWDate& d2) const
- { return julnum >= d1.julnum && julnum <= d2.julnum; }
- int compareTo(const RWDate*) const;
- dayTy day() const; // 1-365
- dayTy dayOfMonth() const; // 1-31
- dayTy firstDayOfMonth() const {return firstDayOfMonth(month());}
- dayTy firstDayOfMonth(monthTy) const;
- unsigned hash() const;
- RWBoolean isValid() const { return julnum>0; }
- RWBoolean leap() const { return leapYear(year());} // leap year?
- RWDate max(const RWDate& dt) const;
- RWDate min(const RWDate& dt) const;
- monthTy month() const;
- const char* nameOfDay() const {return dayName(weekDay());}
- const char* nameOfMonth() const {return monthName(month());}
- RWDate previous(const char* dayName) const; // Return date of previous dayName
- RWDate previous(dayTy) const; // Same as above, but use day of week
- dayTy weekDay() const;
- yearTy year() const;
-
- // Date comparisons:
- RWBoolean operator<(const RWDate& date) const
- { return julnum < date.julnum; }
- RWBoolean operator<=(const RWDate& date) const
- { return julnum <= date.julnum; }
- RWBoolean operator>(const RWDate& date) const
- { return julnum > date.julnum; }
- RWBoolean operator>=(const RWDate& date) const
- { return julnum >= date.julnum; }
- RWBoolean operator==(const RWDate& date) const
- { return julnum == date.julnum; }
- RWBoolean operator!=(const RWDate& date) const
- { return julnum != date.julnum; }
-
- // Arithmetic operators:
- julTy operator-(const RWDate& dt) const
- { return julnum - dt.julnum; }
- friend RWDate operator+(const RWDate& dt, int dd)
- { return RWDate(dt.julnum + dd); }
- friend RWDate operator+(int dd, const RWDate& dt)
- { return RWDate(dt.julnum + dd); }
- friend RWDate operator-(const RWDate& dt, int dd)
- { return RWDate(dt.julnum - dd); }
- RWDate operator++() { return RWDate(++julnum); }
- RWDate operator--() { return RWDate(--julnum); }
- #ifdef CPPV21
- RWDate operator++(int) { return RWDate(julnum++); }
- RWDate operator--(int) { return RWDate(julnum--); }
- #endif
- RWDate operator+=(int dd) { return RWDate(julnum += dd); }
- RWDate operator-=(int dd) { return RWDate(julnum -= dd); }
-
- // Read or write dates:
- friend ostream& operator<<(ostream&, const RWDate&);
- friend istream& operator>>(istream& s, RWDate& d)
- {d.parseFrom(s); return s;}
- unsigned binaryStoreSize() const {return sizeof(julnum);}
- void restoreFrom(RWvistream& s);
- void restoreFrom(RWFile&);
- void saveOn(RWvostream& s) const;
- void saveOn(RWFile&) const;
-
- // Static member functions:
- static const char* dayName(dayTy weekDayNumber);
- static dayTy dayOfWeek(const char* dayName);
- static RWBoolean dayWithinMonth(monthTy, dayTy, yearTy);
- static dayTy daysInYear(yearTy);
- static monthTy indexOfMonth(const char* monthName);
- static julTy jday(monthTy, dayTy, yearTy);
- static RWBoolean leapYear(yearTy year);
- static const char* monthName(monthTy monthNumber);
- static howToPrint setPrintOption(howToPrint h);
- #ifdef RW_MULTI_THREAD
- // Just declarations --- static data must be retrieved from the instance manager.
- static howToPrint getPrintOption();
- #else
- static howToPrint getPrintOption() {return printOption;}
- #endif
- };
-
- pragma pop_align_members();
- #endif /* __RWDATE_H__ */
-