home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 24 / PCPLUS115.iso / pcplus / tclite / include / date.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-28  |  3.5 KB  |  84 lines

  1. #ifndef    DATE_H
  2. #define    DATE_H
  3.  
  4. #include "object.h"
  5.  
  6. typedef unsigned short dayTy;
  7. typedef unsigned short monthTy;
  8. typedef unsigned short yearTy;
  9.  
  10. extern const Class class_Date;
  11.  
  12. dayTy       dayOfWeek(const char* dayName);
  13. dayTy       daysInYear(yearTy year);
  14. monthTy     numberOfMonth(const char* monthName);
  15. bool        leapYear(yearTy year);
  16. const char*    nameOfMonth(monthTy monthNumber);
  17. const char*    nameOfDay(dayTy weekDayNumber);
  18.  
  19. class Date: public Object {
  20.     dayTy   dy;       // day of year
  21.     yearTy  yr;      // year
  22.     void    setDate(int,yearTy);
  23. public:
  24.     ////////////////////////
  25.     ///// Constructors /////
  26.     ////////////////////////
  27.             Date(const Date& date) { dy=date.dy; yr=date.yr;}
  28.             Date& operator=(const Date& date)
  29.             { dy=date.dy; yr=date.yr; return *this; }
  30.             Date();                         // current date
  31.             Date(long dayCount);
  32.             Date(int dayCount, yearTy referenceYear);
  33.             Date(dayTy newDay, const char* monthName, yearTy newYear);
  34.             Date(istream&);                 // read date from stream
  35.     bool    operator<(Date)         const;
  36.     bool    operator<=(Date)        const;
  37.     bool    operator>(Date date)    const   { return date < *this; }
  38.     bool    operator>=(Date date)   const   { return date <= *this; }
  39.     bool    operator==(Date date)   const   {
  40.                                                return dy == date.dy
  41.                                                && yr == date.yr;
  42.                                             }
  43.     bool    operator!=(Date date)   const   {
  44.                                               return dy != date.dy
  45.                                               || yr != date.yr;
  46.                                             }
  47.  
  48. friend Date operator+(Date dt, int dd)  { return Date(dt.dy+dd, dt.yr); }
  49. friend Date operator+(int dd, Date dt)  { return Date(dt.dy+dd, dt.yr); }
  50.  
  51.     long    operator-(Date dt)      const;
  52.     Date    operator-(int dd)       const   { return Date(dy-dd, yr); }
  53.     void    operator+=(int dd)              { setDate(dy+dd, yr); }
  54.     void    operator-=(int dd)              { setDate(dy-dd, yr); }
  55.     bool    between(Date, Date)     const;
  56.     dayTy   day()                   const   { return dy; }
  57.     dayTy   dayOfMonth()            const;
  58.     dayTy   firstDayOfMonth()       const   {
  59.                                                 return
  60.                                                 firstDayOfMonth(month());
  61.                                             }
  62.     dayTy   firstDayOfMonth(monthTy month) const;
  63.     bool    leap()                  const   { return leapYear(yr); }
  64.     Date    max(Date)               const;
  65.     Date    min(Date)               const;
  66.     monthTy month()                 const;
  67. const char* nameOfMonth()       const;
  68.     Date    previous(const char* dayName) const;
  69.     dayTy   weekDay()               const;
  70.     yearTy  year()                  const   { return yr; }
  71.  
  72.     virtual int             compare(const Object&)  const;
  73.     virtual Object*         copy()                  const;
  74.     virtual void            deepenShallowCopy();
  75.     virtual unsigned        hash()                  const;
  76.     virtual const Class*    isA()                   const;
  77.     virtual bool            isEqual(const Object&)  const;
  78.     virtual void            printOn(ostream& strm)  const;
  79.     virtual void            scanFrom(istream& strm);
  80.     virtual const Class*    species()               const;
  81. };
  82.  
  83. #endif
  84.