home *** CD-ROM | disk | FTP | other *** search
- #ifndef _IDATE_
- #define _IDATE_
- /*******************************************************************************
- * FILE NAME: idate.hpp *
- * *
- * DESCRIPTION: *
- * Declaration of the class(es): *
- * IDate - Class to represent dates *
- * *
- * COPYRIGHT: *
- * Licensed Materials - Property of IBM *
- * (C) Copyright IBM Corporation 1992, 1993 *
- * All Rights Reserved *
- * US Government Users Restricted Rights - Use, duplication, or disclosure *
- * restricted by GSA ADP Schedule Contract with IBM Corp. *
- * *
- *$Log: R:/IBMCLASS/IBASE/VCS/IDATE.HPV $ *
- //
- // Rev 1.2 25 Oct 1992 16:46:26 nunn
- //changed library name to ICLUI
-
- Rev 1.1 13 Oct 1992 09:58:00 law
- Removed virtual inheritance from IBase.
-
- Rev 1.0 07 Oct 1992 10:10:16 law
- Initial revision.
- *******************************************************************************/
- #ifndef _IBASE_
- #include <ibase.hpp>
- #endif
-
- #ifndef _ISTRING_
- #include <istring.hpp>
- #endif
-
- class ostream;
-
- class IDate : public IBase {
- /*******************************************************************************
- * Objects of this class represent given days and the class also provides *
- * general day/date handling functions. *
- * *
- * Externally, dates appear to consist of three pieces of information: a year, *
- * a month within that year, and a day within that month (alternatively, *
- * support is provided for simply specifying the day within the year). *
- *******************************************************************************/
- public:
- /*--------------------------- NESTED DECLARATIONS ------------------------------
- | IDate defines the following related types: |
- | DayOfWeek - enumeration values Monday-Sunday for the days of the week. |
- | Month - enumeration values January-December for the months of the year.|
- ------------------------------------------------------------------------------*/
- typedef enum
- {
- Monday = 0,
- Tuesday,
- Wednesday,
- Thursday,
- Friday,
- Saturday,
- Sunday
- } DayOfWeek;
-
- typedef enum
- {
- January = 1,
- February,
- March,
- April,
- May,
- June,
- July,
- August,
- September,
- October,
- November,
- December
- } Month;
-
-
- /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
- | There are six ways to construct IDate objects: |
- | |
- | 1. Using the default constructor, which returns the current |
- | day |
- | |
- | 2. By giving the year, month, and day for the desired day |
- | (accepted as either month/day/year or day/month/year) |
- | |
- | 3. By giving the year and day of the year for the desired day |
- | |
- | 4. By using the static member function today() to return the |
- | current date |
- | |
- | 5. By copying another IDate object. |
- | |
- | 6. By giving the Julian day number (as a long). |
- ------------------------------------------------------------------------------*/
- IDate ( );
-
- IDate ( Month aMonth,
- int aDay,
- int aYear );
-
- IDate ( int aDay,
- Month aMonth,
- int aYear );
-
- IDate ( int aYear,
- int aDay );
-
- IDate ( const IDate &aDate );
-
- IDate ( unsigned long julianDayNumber );
-
- static IDate
- today ( );
-
- /*-------------------------------- ACCESSORS -----------------------------------
- | These functions provide access to various portions of the |
- | representation of the IDate object: |
- | |
- | asString - returns the IDate as a string like "April 10, 1959" |
- | dayOfWeek - returns the index of the receiver's day of the |
- | week: Monday ... Sunday |
- | dayName - returns the name of the receiver's day of the week |
- | dayOfMonth - returns the day in the receiver's month as an |
- | integer 1-31 |
- | dayOfYear - returns the day in the receiver's year as an |
- | integer 1-366 |
- | julianDate - returns the Julian day number of the receiver IDate |
- | monthOfYear - returns the index of the receiver's month of the |
- | year: January ... December |
- | monthName - returns the name of the receiver's month |
- | year - returns the receiver's year |
- ------------------------------------------------------------------------------*/
- IString
- asString ( ) const,
- dayName ( ) const,
- monthName ( ) const;
-
- DayOfWeek
- dayOfWeek ( ) const;
-
- int
- dayOfMonth ( ) const,
- dayOfYear ( ) const;
-
- unsigned long
- julianDate ( ) const;
-
- Month
- monthOfYear ( ) const;
-
- int
- year ( ) const;
-
- /*--------------------------------- DISPLAY ------------------------------------
- | This function permits a Date to be output on an ostream using the |
- | conventional left-shift (<<) operator. |
- ------------------------------------------------------------------------------*/
- friend ostream
- &operator << ( ostream &aStream,
- const IDate &aDate );
-
- /*-------------------------- COMPARISON OPERATORS ------------------------------
- | Two IDates can be compared using the full complement of comparison |
- | operators and applying the natural meaning. |
- ------------------------------------------------------------------------------*/
- Boolean
- operator == ( const IDate &aDate ) const,
- operator != ( const IDate &aDate ) const,
- operator < ( const IDate &aDate ) const,
- operator <= ( const IDate &aDate ) const,
- operator > ( const IDate &aDate ) const,
- operator >= ( const IDate &aDate ) const;
-
- /*------------------------- MANIPULATION OPERATORS -----------------------------
- | These operators permit an integral number of days to be added or |
- | subtracted from a given IDate via operator+ and operator-, respectively. |
- | |
- | Two IDates can be subtracted to produce the number of days between them. |
- | |
- | The result can be placed back into the receiver via operator+= and |
- | operator-=, respectively. |
- ------------------------------------------------------------------------------*/
- IDate
- operator + ( int numDays ) const,
- operator - ( int numDays ) const;
-
- IDate
- &operator += ( int numDays ),
- &operator -= ( int numDays );
-
- long
- operator - ( const IDate &aDate ) const;
-
- /*--------------------------------- STATICS ------------------------------------
- | These functions are static; they provide general IDate utilities |
- | independent of specific IDates. |
- | |
- | dayName - returns the name of the week day corresponding to the |
- | argument DayOfWeek index |
- | monthName - returns the name of the month with the argument |
- | index |
- | daysInMonth - returns the number of days in a given month (in a given year) |
- | daysInYear - returns the number of days in a given year |
- | isLeapYear - returns true if the argument year is a leap year, |
- | false otherwise |
- | isValid - indicates whether the argument date (given as |
- | either year/month/day or year/day) is valid (e.g., |
- | February 29, 1990 is *not* valid) |
- ------------------------------------------------------------------------------*/
- static IString
- dayName ( DayOfWeek aDay ),
- monthName ( Month aMonth );
-
- static int
- daysInMonth ( Month aMonth,
- int aYear ),
- daysInYear ( int aYear );
-
- static Boolean
- isLeapYear ( int aYear ),
- isValid ( Month aMonth,
- int aDay,
- int aYear ),
- isValid ( int aDay,
- Month aMonth,
- int aYear ),
- isValid ( int aYear,
- int aDay );
-
- protected:
- /*----------------------------- IMPLEMENTATION ---------------------------------
- | These functions are utilized to implement class IDate: |
- | initialize - calculate julian day number |
- ------------------------------------------------------------------------------*/
- IDate
- &initialize ( Month aMonth,
- int aDay,
- int aYear );
-
- private:
- /*--------------------------------- PRIVATE ----------------------------------*/
- unsigned long
- julian;
- }; // IDate
-
- #endif /* _IDATE_ */