home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IDATE.INL < prev    next >
Text File  |  1993-10-22  |  5KB  |  137 lines

  1. #ifndef _IDATE_INL_
  2. #define _IDATE_INL_ 0
  3. /*******************************************************************************
  4. * FILE NAME: idate.inl                                                         *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   This file contains the definition of the inline functions for the          *
  8. *   class(es) declared in idate.hpp.                                           *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or               *
  15. *   disclosure                                                                 *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #ifndef _IDATE_
  20.   #undef  _IDATE_INL_
  21.   #define _IDATE_INL_ 1
  22.   #include <idate.hpp>
  23. #endif
  24.  
  25. extern "C"
  26.   {
  27.   #include <time.h>
  28.   }
  29.  
  30. #if _IDATE_INL_
  31.   #define inline
  32. #endif
  33.  
  34. /*------------------------------- Constructors -------------------------------*/
  35. inline IDate IDate :: today ( )
  36.   {
  37.   time_t t   = time(0);
  38.   tm     now = *localtime( &t );
  39.   return IDate(  now.tm_year + 1900, now.tm_yday + 1 );
  40.   }
  41. inline IDate :: IDate ( )
  42.   {
  43.   this->julian = this->today().julian;
  44.   }
  45. inline IDate :: IDate ( int   aDay,
  46.                         Month aMonth,
  47.                         int   aYear )
  48.   {
  49.   this->initialize( aMonth, aDay, aYear );
  50.   }
  51. inline IDate :: IDate ( Month aMonth,
  52.                         int   aDay,
  53.                         int   aYear )
  54.   {
  55.   this->initialize( aMonth, aDay, aYear );
  56.   }
  57. inline IDate :: IDate ( const IDate& aDate )
  58.   : julian( aDate.julian )
  59.   {
  60.   }
  61. inline IDate :: IDate ( unsigned long julianDayNumber )
  62.   : julian( julianDayNumber )
  63.   {
  64.   }
  65. /*-------------------------------- Accessors ---------------------------------*/
  66. inline IDate::DayOfWeek IDate :: dayOfWeek ( ) const
  67.   {
  68.   return (DayOfWeek) ( this->julian % 7 );
  69.   }
  70. inline unsigned long IDate :: julianDate ( ) const
  71.   {
  72.   return this->julian;
  73.   }
  74. /*-------------------------------- Comparison --------------------------------*/
  75. inline IBase::Boolean IDate :: operator == ( const IDate &aDate ) const
  76.   {
  77.   return this->julian == aDate.julian;
  78.   }
  79. inline IBase::Boolean IDate :: operator != ( const IDate &aDate ) const
  80.   {
  81.   return this->julian != aDate.julian;
  82.   }
  83. inline IBase::Boolean IDate :: operator <  ( const IDate &aDate ) const
  84.   {
  85.   return this->julian <  aDate.julian;
  86.   }
  87. inline IBase::Boolean IDate :: operator <= ( const IDate &aDate ) const
  88.   {
  89.   return this->julian <= aDate.julian;
  90.   }
  91. inline IBase::Boolean IDate :: operator >  ( const IDate &aDate ) const
  92.   {
  93.   return this->julian >  aDate.julian;
  94.   }
  95. inline IBase::Boolean IDate :: operator >= ( const IDate &aDate ) const
  96.   {
  97.   return this->julian >= aDate.julian;
  98.   }
  99. /*-------------------------- Manipulation Operators --------------------------*/
  100. inline IDate IDate :: operator + ( int numDays ) const
  101.   {
  102.   return IDate( this->julian + numDays );
  103.   }
  104. inline IDate IDate :: operator - ( int numDays ) const
  105.   {
  106.   return IDate( this->julian - numDays );
  107.   }
  108. inline IDate& IDate :: operator += ( int numDays )
  109.   {
  110.   this->julian += numDays;
  111.   return *this;
  112.   }
  113. inline IDate& IDate :: operator -= ( int numDays )
  114.   {
  115.   this->julian -= numDays;
  116.   return *this;
  117.   }
  118. inline long IDate :: operator - ( const IDate &aDate ) const
  119.   {
  120.   return this->julian - aDate.julian;
  121.   }
  122. /*--------------------------------- Testing ----------------------------------*/
  123. inline IBase::Boolean IDate :: isValid ( int   aDay,
  124.                                          Month aMonth,
  125.                                          int  aYear )
  126.   {
  127.   return IDate :: isValid( aMonth, aDay, aYear );
  128.   }
  129. inline IBase::Boolean IDate :: isValid ( int  aYear,
  130.                                          int  aDay )
  131.   {
  132.   return ( aYear != 0
  133.            &&
  134.            aDay <= IDate::daysInYear( aYear ) );
  135.   }
  136. #endif // _IDATE_INL_
  137.