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

  1. #ifndef _ITIME_INL_
  2. #define _ITIME_INL_ 0
  3. /*******************************************************************************
  4. * FILE NAME: itime.inl                                                         *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   This file contains the definition of the inline functions for the          *
  8. *   class(es) declared in itime.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 _ITIME_
  20.   #undef  _ITIME_INL_
  21.   #define _ITIME_INL_ 1
  22.   #include <itime.hpp>
  23. #endif
  24.  
  25. extern "C"
  26.   {
  27.   #include <time.h>
  28.   }
  29.  
  30. #if _ITIME_INL_
  31.   #define inline
  32. #endif
  33.  
  34. /*------------------------------ Implementation ------------------------------*/
  35. inline ITime& ITime :: initialize ( long seconds )
  36.   {
  37.   const long secondsPerDay = 24*60*60L;
  38.   if ( seconds < 0 )
  39.     this->ticks = secondsPerDay - (-seconds % secondsPerDay);
  40.   else
  41.     this->ticks = seconds % secondsPerDay;
  42.   return *this;
  43.   }
  44. /*------------------------------- Constructors -------------------------------*/
  45. inline ITime :: ITime ( unsigned hours,
  46.                         unsigned minutes,
  47.                         unsigned seconds )
  48.   {
  49.   long secs = hours;
  50.   secs *= 60;
  51.   secs += minutes;
  52.   secs *= 60;
  53.   secs += seconds;
  54.   this->initialize( secs );
  55.   }
  56. inline ITime ITime :: now ( )
  57.   {
  58.   time_t t    = time( 0 );
  59.   tm     time = *localtime( &t );
  60.   return ITime( time.tm_hour, time.tm_min, time.tm_sec );
  61.   }
  62. inline ITime :: ITime ( )
  63.   {
  64.   this->ticks = this->now().ticks;
  65.   }
  66. inline ITime :: ITime ( long seconds )
  67.   {
  68.   this->initialize( seconds );
  69.   }
  70. inline ITime :: ITime ( const ITime &aTime )
  71.   {
  72.   this->ticks = aTime.ticks;
  73.   }
  74. /*-------------------------------- Accessors ---------------------------------*/
  75. inline long ITime :: asSeconds ( ) const
  76.   {
  77.   return this->ticks;
  78.   }
  79. inline unsigned ITime :: hours ( ) const
  80.   {
  81.   // seconds/(seconds/hour) -> hours.
  82.   return this->ticks / 3600;
  83.   }
  84. inline unsigned ITime :: minutes ( ) const
  85.   {
  86.   // seconds (past hour)/(seconds/minute) -> minutes.
  87.   return ( this->ticks % 3600 ) / 60;
  88.   }
  89. inline unsigned ITime :: seconds ( ) const
  90.   {
  91.   // seconds (past minute)
  92.   return this->ticks % 60;
  93.   }
  94. /*-------------------------------- Comparison --------------------------------*/
  95. inline IBase::Boolean ITime :: operator == ( const ITime &aTime ) const
  96.   {
  97.   return this->ticks == aTime.ticks;
  98.   }
  99. inline IBase::Boolean ITime :: operator != ( const ITime &aTime ) const
  100.   {
  101.   return this->ticks != aTime.ticks;
  102.   }
  103. inline IBase::Boolean ITime :: operator <  ( const ITime &aTime ) const
  104.   {
  105.   return this->ticks <  aTime.ticks;
  106.   }
  107. inline IBase::Boolean ITime :: operator <= ( const ITime &aTime ) const
  108.   {
  109.   return this->ticks <= aTime.ticks;
  110.   }
  111. inline IBase::Boolean ITime :: operator >  ( const ITime &aTime ) const
  112.   {
  113.   return this->ticks >  aTime.ticks;
  114.   }
  115. inline IBase::Boolean ITime :: operator >= ( const ITime &aTime ) const
  116.   {
  117.   return this->ticks >= aTime.ticks;
  118.   }
  119. /*-------------------------- Manipulation Operators --------------------------*/
  120. inline ITime& ITime :: operator += ( const ITime &aTime )
  121.   {
  122.   return this->initialize( this->ticks + aTime.ticks );
  123.   }
  124. inline ITime ITime :: operator + ( const ITime &aTime ) const
  125.   {
  126.   return ITime( this->ticks + aTime.ticks );
  127.   }
  128. inline ITime& ITime :: operator -= ( const ITime &aTime )
  129.   {
  130.   return this->initialize( this->ticks - aTime.ticks );
  131.   }
  132. inline ITime ITime :: operator - ( const ITime &aTime ) const
  133.   {
  134.   return ITime( this->ticks - aTime.ticks );
  135.   }
  136. #endif // _ITIME_INL_
  137.