home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / ibmcli / itime.hp_ / ITIME.HPP
Encoding:
C/C++ Source or Header  |  1992-10-26  |  7.0 KB  |  148 lines

  1. #ifndef _ITIME_
  2. #define _ITIME_
  3. /*******************************************************************************
  4. * FILE NAME: itime.hpp                                                         *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     ITime - Class of objects representing time-of-day values                 *
  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 disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. *$Log:   R:/IBMCLASS/IBASE/VCS/ITIME.HPV  $                                                                         *
  18. //
  19. //   Rev 1.2   25 Oct 1992 16:46:40   nunn
  20. //changed library name to ICLUI
  21.    
  22.       Rev 1.1   13 Oct 1992 09:58:14   law
  23.    Removed virtual inheritance from IBase.
  24.    
  25.       Rev 1.0   08 Oct 1992 17:11:34   law
  26.    Initial revision.
  27. *******************************************************************************/
  28. #ifndef _IBASE_
  29.   #include <ibase.hpp>
  30. #endif
  31.  
  32. #ifndef _ISTRING_
  33.   #include <istring.hpp>
  34. #endif
  35.  
  36. class ostream;
  37.  
  38. class ITime : public IBase {
  39. /*******************************************************************************
  40. * Objects of this class represent units of time.  These ITime objects          *
  41. * represent portions of days (see also class IDate) and provide                *
  42. * support for converting to hours, minutes, and seconds in numeric             *
  43. * and ascii format.                                                            *
  44. *                                                                              *
  45. * ITimes can be compared and operated on via addition/subtraction with         *
  46. * other ITime objects.                                                         *
  47. *******************************************************************************/
  48. public:
  49. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
  50. | There are four ways to construct ITime objects:                              |
  51. |                                                                              |
  52. | 1. Using the default constructor, which returns the current                  |
  53. |    time.                                                                     |
  54. |                                                                              |
  55. | 2. By giving the number of seconds (or the number of hours,                  |
  56. |    minutes, and seconds) since midnight that the time is                     |
  57. |    to represent; in the former case, the number of seconds                   |
  58. |    may be negative and is subtracted from the number of                      |
  59. |    seconds in a day                                                          |
  60. |                                                                              |
  61. | 3. By using the static member function now() to return the                   |
  62. |    current time.                                                             |
  63. |                                                                              |
  64. | 4. By copying another ITime object.                                          |
  65. ------------------------------------------------------------------------------*/
  66.   ITime ( );
  67.  
  68.   ITime ( long seconds );
  69.  
  70.   ITime ( unsigned hours,
  71.           unsigned minutes,
  72.           unsigned seconds = 0 );
  73.  
  74.   ITime ( const ITime &aTime );
  75.  
  76. static ITime
  77.   now ( );
  78.  
  79. /*-------------------------------- ACCESSORS -----------------------------------
  80. | These functions provide access to various portions of the                    |
  81. | representation of the ITime object:                                          |
  82. |   asSeconds   -  returns the number of seconds since midnight                |
  83. |   asString    -  returns the ITime as a string "hh:mm:ss"                    |
  84. |   hours       -  returns the number of hours past midnight                   |
  85. |   minutes     -  returns the number of minutes past the hour                 |
  86. |   seconds     -  returns the number of seconds past the minute               |
  87. ------------------------------------------------------------------------------*/
  88. long 
  89.   asSeconds ( ) const;
  90.  
  91. IString
  92.   asString ( ) const;
  93.  
  94. unsigned 
  95.   hours   ( ) const,
  96.   minutes ( ) const,
  97.   seconds ( ) const;
  98.  
  99. /*-------------------------- COMPARISON OPERATORS ------------------------------
  100. | Two ITime objects can be compared, applying the intuitive logic.             |
  101. ------------------------------------------------------------------------------*/
  102. Boolean
  103.   operator == ( const ITime &aTime ) const,
  104.   operator != ( const ITime &aTime ) const,
  105.   operator <  ( const ITime &aTime ) const,
  106.   operator <= ( const ITime &aTime ) const,
  107.   operator >  ( const ITime &aTime ) const,
  108.   operator >= ( const ITime &aTime ) const;
  109.  
  110. /*------------------------- MANIPULATION OPERATORS -----------------------------
  111. | These operators permit two ITimes to be added or subtracted                  |
  112. | (via operator+ and operator-, respectively).  The result can                 |
  113. | be placed back into the receiver (via operator+= and                         |
  114. | operator-=, respectively).                                                   |
  115. ------------------------------------------------------------------------------*/
  116. ITime
  117.   operator +  ( const ITime &aTime ) const,
  118.   operator -  ( const ITime &aTime ) const;
  119.  
  120. ITime
  121.  &operator += ( const ITime &aTime ),
  122.  &operator -= ( const ITime &aTime );
  123.  
  124. /*------------------------------- DISPLAYING -----------------------------------
  125. | ITimes can be output on an ostream using the conventional left-shift (<<)    |
  126. | operator.                                                                    |
  127. ------------------------------------------------------------------------------*/
  128. friend ostream
  129.  &operator << ( ostream     &aStream,
  130.                 const ITime &aTime );
  131.  
  132. protected:
  133. /*----------------------------- IMPLEMENTATION ---------------------------------
  134. | These function are used to implement the ITime class:                        |
  135. |   initialize - common initialization function used by ctors                  |
  136. ------------------------------------------------------------------------------*/
  137. ITime
  138.  &initialize ( long seconds );
  139.  
  140. private:
  141. /*--------------------------------- PRIVATE ----------------------------------*/
  142. long
  143.   ticks;
  144.  
  145. }; // ITime
  146.  
  147. #endif /* _ITIME_ */
  148.