home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / ITIME.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  10KB  |  189 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. *******************************************************************************/
  18. #ifndef _IBASE_
  19.   #include <ibase.hpp>
  20. #endif
  21.  
  22. #ifndef _ISTRING_
  23.   #include <istring.hpp>
  24. #endif
  25.  
  26. struct _CTIME;
  27.  
  28. /*----------------------------------------------------------------------------*/
  29. /* Align classes on four byte boundary.                                       */
  30. /*----------------------------------------------------------------------------*/
  31. #pragma pack(4)
  32.  
  33. class ostream;
  34.  
  35. class ITime : public IBase {
  36. /*******************************************************************************
  37. * Objects of the ITime class represent units of time (hours, minutes, and      *
  38. * seconds) as portions of days and provide support for converting these units  *
  39. * of time into numeric and ASCII format.                                       *
  40. *                                                                              *
  41. * ITime objects can be compared and operated on by adding them to and          *
  42. * subtracting them from other ITime objects.                                   *
  43. *                                                                              *
  44. * A related class whose objects also represent units of time is the IDate      *
  45. * class.                                                                       *
  46. *******************************************************************************/
  47. public:
  48. /*------------------------ Constructors ----------------------------------------
  49. | You can construct ITime objects in the following ways:                       |
  50. |                                                                              |
  51. |    - By using the default constructor, which returns the current time.       |
  52. |                                                                              |
  53. |    - By giving the number of seconds since midnight that the time is to      |
  54. |      represent.  In this case, the number of seconds can be negative and is  |
  55. |      subtracted from the number of seconds in a day.                         |
  56. |                                                                              |
  57. |    - By giving the number of hours, minutes, and seconds since midnight      |
  58. |      that the time is to represent.  In this case, the number of seconds     |
  59. |      cannot be negative.                                                     |
  60. |                                                                              |
  61. |    - By copying another ITime object.                                        |
  62. |                                                                              |
  63. |    - By giving a container CTIME structure.                                  |
  64. |                                                                              |
  65. |    - By using the static member function now to return the current time.     |
  66. ------------------------------------------------------------------------------*/
  67.   ITime ( );
  68.  
  69.   ITime ( long seconds );
  70.  
  71.   ITime ( unsigned hours,
  72.           unsigned minutes,
  73.           unsigned seconds = 0 );
  74.  
  75.   ITime ( const ITime &aTime );
  76.  
  77.   ITime ( const _CTIME &cTime );
  78.  
  79. /*----------------------------- Current Time -----------------------------------
  80. | Use the following function when you need the current time:                   |
  81. |   now - Returns the current time.  This function can be used as an ITime     |
  82. |         constructor.                                                         |
  83. ------------------------------------------------------------------------------*/
  84. static ITime
  85.   now ( );
  86.  
  87. /*-------------------------------- Accessors -----------------------------------
  88. | The following functions provide access to various portions of the            |
  89. | representation of the ITime object:                                          |
  90. |   asSeconds - Returns the number of seconds since midnight.                  |
  91. |   asString  - Returns the ITime object as a string that is formatted         |
  92. |               according to the format argument.  This format string can      |
  93. |               contain time "conversion specifiers" as defined for the        |
  94. |               standard C library function strftime in the time.h header      |
  95. |               file.  The default format is %X, which yields the time as      |
  96. |               hh:mm:ss.                                                      |
  97. |   asCTIME   - Returns the time as a container CTIME structure.               |
  98. |   hours     - Returns the number of hours past midnight.                     |
  99. |   minutes   - Returns the number of minutes past the hour.                   |
  100. |   seconds   - Returns the number of seconds past the minute.                 |
  101. ------------------------------------------------------------------------------*/
  102. long
  103.   asSeconds ( ) const;
  104.  
  105. IString
  106.   asString ( const char *fmt = "%X" ) const;
  107.  
  108. _CTIME
  109.   asCTIME ( ) const;
  110.  
  111. unsigned
  112.   hours   ( ) const,
  113.   minutes ( ) const,
  114.   seconds ( ) const;
  115.  
  116. /*-------------------------- Comparison Operators ------------------------------
  117. | Using the following operators, two ITime objects can be compared to each     |
  118. | other:                                                                       |
  119. |   operator == - Compares two objects to determine whether they are equal.    |
  120. |   operator != - Compares two objects to determine whether they are not       |
  121. |                 equal.                                                       |
  122. |   operator <  - Compares two objects to determine whether one is less than   |
  123. |                 the other.                                                   |
  124. |   operator <= - Compares two objects to determine whether one is less than   |
  125. |                 or equal to the other.                                       |
  126. |   operator >  - Compares two objects to determine whether one is greater     |
  127. |                 than the other.                                              |
  128. |   operator >= - Compares two objects to determine whether one is greater     |
  129. |                 than or equal to the other.                                  |
  130. ------------------------------------------------------------------------------*/
  131. Boolean
  132.   operator == ( const ITime &aTime ) const,
  133.   operator != ( const ITime &aTime ) const,
  134.   operator <  ( const ITime &aTime ) const,
  135.   operator <= ( const ITime &aTime ) const,
  136.   operator >  ( const ITime &aTime ) const,
  137.   operator >= ( const ITime &aTime ) const;
  138.  
  139. /*------------------------- Manipulation Operators -----------------------------
  140. | The following operators are used to manipulate the values of two ITime       |
  141. | objects and to store the results of those manipulations:                     |
  142. |   operator +  - Adds two objects together.                                   |
  143. |   operator -  - Subtracts one object from another.                           |
  144. |   operator += - Stores the result of an addition operation in the receiver.  |
  145. |   operator -= - Stores the result of a subtraction operation in the          |
  146. |                 receiver.                                                    |
  147. ------------------------------------------------------------------------------*/
  148. ITime
  149.   operator +  ( const ITime &aTime ) const,
  150.   operator -  ( const ITime &aTime ) const;
  151.  
  152. ITime
  153.  &operator += ( const ITime &aTime ),
  154.  &operator -= ( const ITime &aTime );
  155.  
  156. /*------------------------------- Displaying -----------------------------------
  157. | The following operator can be used to display an ITime object:               |
  158. |   operator << - Outputs an object on an ostream.                             |
  159. ------------------------------------------------------------------------------*/
  160. friend ostream
  161.  &operator << ( ostream     &aStream,
  162.                 const ITime &aTime );
  163.  
  164. protected:
  165. /*----------------------------- Implementation ---------------------------------
  166. | The following function is used to implement the ITime class:                 |
  167. |   initialize - Common initialization function used by constructors.          |
  168. ------------------------------------------------------------------------------*/
  169. ITime
  170.  &initialize ( long seconds );
  171.  
  172. private:
  173. /*--------------------------------- PRIVATE ----------------------------------*/
  174. long
  175.   ticks;
  176.  
  177. }; // ITime
  178.  
  179. /*----------------------------------------------------------------------------*/
  180. /* Resume compiler default packing.                                           */
  181. /*----------------------------------------------------------------------------*/
  182. #pragma pack()
  183.  
  184. #ifndef I_NO_INLINES
  185.   #include <itime.inl>
  186. #endif
  187.  
  188. #endif /* _ITIME_ */
  189.