home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / idate.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  5.2 KB  |  209 lines

  1.  
  2. #ifndef _IDATE_
  3. #define _IDATE_
  4. /*******************************************************************************
  5. * FILE NAME: idate.hpp                                                         *
  6. *                                                                              *
  7. * DESCRIPTION:                                                                 *
  8. *   Declaration of the classes:                                                *
  9. *     IDate                                                                    *
  10. *                                                                              *
  11. * COPYRIGHT:                                                                   *
  12. *   IBM Open Class Library                                                     *
  13. *   (C) Copyright International Business Machines Corporation 1992, 1996       *
  14. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  15. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #include <ibase.hpp>
  20.  
  21. /*  The "struct blocks" must be placed before SOM enablement test  */
  22. #if ( IC_OBSOLETE <= IC_OBSOLETE_2 )
  23. #endif
  24.  
  25. struct ICnrDate {
  26.   unsigned char  day;
  27.   unsigned char  month;
  28.   unsigned short year;
  29. };
  30.  
  31.  
  32. #pragma pack(4)
  33.  
  34. class ostream;
  35.  
  36.  
  37.  
  38.  
  39.  
  40. class IString;
  41.  
  42. class IDate : public IBase {
  43. public:
  44. /*-------------------------- Day/Month/Year Declarations ---------------------*/
  45. typedef enum {
  46.   Monday = 0,
  47.   Tuesday,
  48.   Wednesday,
  49.   Thursday,
  50.   Friday,
  51.   Saturday,
  52.   Sunday
  53.   } DayOfWeek;
  54.  
  55. typedef enum {
  56.   January = 1,
  57.   February,
  58.   March,
  59.   April,
  60.   May,
  61.   June,
  62.   July,
  63.   August,
  64.   September,
  65.   October,
  66.   November,
  67.   December
  68.   } Month;
  69.  
  70. typedef enum {
  71.   yy,
  72.   yyyy
  73.   } YearFormat;
  74.  
  75. /*-------------------------- Constructors ------------------------------------*/
  76.   IDate       ( );
  77.  
  78.   IDate       ( Month aMonth,
  79.                 int   aDay,
  80.                 int   aYear );
  81.  
  82.   IDate       ( int   aDay,
  83.                 Month aMonth,
  84.                 int   aYear );
  85.  
  86.   IDate       ( int   aYear,
  87.                 int   aDay );
  88.  
  89.   IDate       ( const IDate&    aDate );
  90.  
  91.   IDate       ( unsigned long   julianDayNumber );
  92.  
  93.   IDate       ( const ICnrDate& cnrDate );
  94.  
  95. /*-------------------------- Current Date ------------------------------------*/
  96. static IDate
  97.   today       ( );
  98.  
  99. /*-------------------------- Diagnostics -------------------------------------*/
  100. IString
  101.   asString    ( YearFormat  yearFmt = yy ) const,
  102.   asString    ( const char *fmt ) const;
  103.  
  104. friend ostream
  105.  &operator << ( ostream     &aStream,
  106.                 const IDate &aDate );
  107.  
  108. /*-------------------------- Day Queries -------------------------------------*/
  109. DayOfWeek
  110.   dayOfWeek   ( ) const;
  111.  
  112. IString
  113.   dayName     ( ) const;
  114.  
  115. int
  116.   dayOfMonth  ( ) const,
  117.   dayOfYear   ( ) const;
  118.  
  119. /*-------------------------- Month Queries -----------------------------------*/
  120. Month
  121.   monthOfYear ( ) const;
  122.  
  123. IString
  124.   monthName   ( ) const;
  125.  
  126. /*-------------------------- Year Queries ------------------------------------*/
  127. int
  128.   year        ( ) const;
  129.  
  130. /*-------------------------- Date Queries ------------------------------------*/
  131. unsigned long
  132.   julianDate  ( ) const;
  133.  
  134. ICnrDate
  135.   asICnrDate  ( ) const;
  136.  
  137. /*-------------------------- Comparisons -------------------------------------*/
  138. Boolean
  139.   operator == ( const IDate &aDate ) const,
  140.   operator != ( const IDate &aDate ) const,
  141.   operator <  ( const IDate &aDate ) const,
  142.   operator <= ( const IDate &aDate ) const,
  143.   operator >  ( const IDate &aDate ) const,
  144.   operator >= ( const IDate &aDate ) const;
  145.  
  146. /*------------------------- Manipulations ------------------------------------*/
  147. IDate
  148.   operator +  ( int numDays ) const,
  149.   operator -  ( int numDays ) const;
  150.  
  151. IDate
  152.  &operator += ( int numDays ),
  153.  &operator -= ( int numDays );
  154.  
  155. long
  156.   operator -  ( const IDate &aDate ) const;
  157.  
  158. /*------------------------- General Date Queries -----------------------------*/
  159. static IString
  160.   dayName     ( DayOfWeek aDay   ),
  161.   monthName   ( Month     aMonth );
  162.  
  163. static int
  164.   daysInMonth ( Month aMonth,
  165.                 int   aYear ),
  166.   daysInYear  ( int   aYear );
  167.  
  168. /*------------------------- Validation ---------------------------------------*/
  169. static Boolean
  170.   isLeapYear  ( int   aYear ),
  171.   isValid     ( Month aMonth,
  172.                 int   aDay,
  173.                 int   aYear ),
  174.   isValid     ( int   aDay,
  175.                 Month aMonth,
  176.                 int   aYear ),
  177.   isValid     ( int   aYear,
  178.                 int   aDay );
  179.  
  180. protected:
  181. /*------------------------- Initialize ---------------------------------------*/
  182. IDate
  183.  &initialize  ( Month aMonth,
  184.                 int   aDay,
  185.                 int   aYear );
  186.  
  187. private:
  188. /*--------------------------------- Private ----------------------------------*/
  189. #if ( IC_OBSOLETE <= IC_OBSOLETE_2 )
  190. #endif
  191.  
  192. unsigned long
  193.   julian;
  194.  
  195.  
  196.  
  197.  
  198. }; // IDate
  199.  
  200.  
  201.  
  202. #pragma pack()
  203.  
  204.   #include <idate.inl>
  205.  
  206. #endif /* _IDATE_ */
  207.  
  208.  
  209.