home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / PBL30DEV.ZIP / DATE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-28  |  4.9 KB  |  161 lines

  1. /*
  2.  * This file is part of PB-Lib v3.0 C++ Programming Library
  3.  *
  4.  * Copyright (c) 1995, 1997 by Branislav L. Slantchev
  5.  * A fine product of Silicon Creations, Inc. (gargoyle)
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the License which accompanies this
  9.  * software. This library is distributed in the hope that it will
  10.  * be useful, but without any warranty; without even the implied
  11.  * warranty of merchantability or fitness for a particular purpose.
  12.  *
  13.  * You should have received a copy of the License along with this
  14.  * library, in the file LICENSE.DOC; if not, write to the address
  15.  * below to receive a copy via electronic mail.
  16.  *
  17.  * You can reach Branislav L. Slantchev (Silicon Creations, Inc.)
  18.  * at bslantch@cs.angelo.edu. The file SUPPORT.DOC has the current
  19.  * telephone numbers and the postal address for contacts.
  20. */
  21.  
  22. #ifndef INCLUDED_DATE_H
  23. #define INCLUDED_DATE_H
  24. #include "typedef.h"
  25.  
  26. class zDate
  27. {
  28. public:
  29.     enum month {
  30.         jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
  31.     };
  32.  
  33.     enum week_day {
  34.         mon = 1, tue, wed, thu, fri, sat, sun
  35.     };
  36.  
  37.     enum moon_phase {
  38.         new_moon, waxing_crescent, first_quater, waxing_gibbous,
  39.         full_moon, waning_gibbous, third_quater, waning_crescent
  40.     };
  41.  
  42.     zDate();
  43.     zDate(month month, int day, int year);
  44.     zDate(int dayOfYear, int year);
  45.     zDate(const zDate &aDate);
  46.     zDate(ulong nDayNumber);
  47.     zDate(const struct tm *date);
  48.  
  49.     zDate             AddMonths(int nMonths) const;
  50.     zDate             AddWeeks(int nWeeks) const;
  51.     zDate             AddYears(int nYears) const;
  52.     int               Age(const zDate &aDate) const;
  53.     zDate             BeginDST() const;
  54.     static zDate      BeginDST(int aYear);
  55.     int               Day() const;
  56.     ulong             DayNumber() const;
  57.     week_day          DayOfWeek() const;
  58.     int               DayOfYear() const;
  59.     int               DaysInMonth() const;
  60.     static int        DaysInMonth(month aMonth, int aYear);
  61.     int               DaysInYear() const;
  62.     static int        DaysInYear(int year);
  63.     zDate             Easter() const;
  64.     static zDate      Easter(int year);
  65.     zDate             EndDST() const;
  66.     static zDate      EndDST(int aYear);
  67.     Boolean           IsDST() const;
  68.     static Boolean    IsDST(const zDate &date);
  69.     Boolean           IsLeapYear() const;
  70.     static Boolean    IsLeapYear(int year);
  71.     Boolean           IsValid() const;
  72.     static Boolean    IsValid(month aMonth, int aDay, int aYear);
  73.     month             Month() const;
  74.     moon_phase        MoonPhase() const;
  75.     static moon_phase MoonPhase(const zDate &date);
  76.                       operator long() const;
  77.     Boolean           operator!=(const zDate &aDate) const;
  78.     zDate             operator+(int nDays) const;
  79.     zDate             operator+(long nDays) const;
  80.     zDate             operator++();
  81.     zDate             operator++(int);
  82.     zDate&            operator+=(int nDays);
  83.     zDate&            operator+=(long nDays);
  84.     long              operator-(const zDate &aDate) const;
  85.     zDate             operator-(int nDays) const;
  86.     zDate             operator-(long nDays) const;
  87.     zDate             operator--();
  88.     zDate             operator--(int);
  89.     zDate&            operator-=(int nDays);
  90.     zDate&            operator-=(long nDays);
  91.     Boolean           operator<(const zDate &aDate) const;
  92.     Boolean           operator<=(const zDate &aDate) const;
  93.     zDate&            operator=(const zDate &aDate);
  94.     Boolean           operator==(const zDate &aDate) const;
  95.     Boolean           operator>(const zDate &aDate) const;
  96.     Boolean           operator>=(const zDate &aDate) const;
  97.     char              operator[](int index) const;
  98.     static void       SetBeginDST(month aMonth, week_day aWeekDay);
  99.     static void       SetEndDST(month aMonth, week_day aWeekDay);
  100.     static zDate      Today();
  101.     int               WeekOfMonth() const;
  102.     int               WeekOfYear() const;
  103.     int               WeeksInYear() const;
  104.     static int        WeeksInYear(int year);
  105.     int               Year() const;
  106.  
  107.     // Pope Gregor XIII's reform cancelled 10 days:
  108.     // the day after Oct 4 1582 was Oct 15 1582
  109.     static const int      ReformYear;
  110.     static const month    ReformMonth;
  111.     static const ulong    ReformDayNumber;
  112.  
  113. protected:
  114.     // Daylight Savings Time Month and Day of Week
  115.     static month    BeginDSTMonth;
  116.     static week_day BeginDSTDay;
  117.     static month    EndDSTMonth;
  118.     static week_day EndDSTDay;
  119.  
  120. protected:
  121.     zDate Set(month aMonth, int aDay, int aYear);
  122.     ulong MakeDayNumber() const;
  123.     void  FromDayNumber(ulong nDayNumber);
  124.  
  125. private:
  126.     month m_month;
  127.     int   m_day;
  128.     int   m_year;
  129.     ulong m_dayno;
  130. };
  131.  
  132. /*
  133.  * inline functions that belong to the zDate class
  134. */
  135.  
  136. inline int
  137. zDate::Year() const
  138. {
  139.     return m_year;
  140. }
  141.  
  142. inline int
  143. zDate::Day() const
  144. {
  145.     return m_day;
  146. }
  147.  
  148. inline zDate::month
  149. zDate::Month() const
  150. {
  151.     return m_month;
  152. }
  153.  
  154. inline ulong
  155. zDate::DayNumber() const
  156. {
  157.     return m_dayno;
  158. }
  159.  
  160. #endif /* INCLUDED_DATE_H */
  161.