home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
ITIME.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
10KB
|
189 lines
#ifndef _ITIME_
#define _ITIME_
/*******************************************************************************
* FILE NAME: itime.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* ITime - Class of objects representing time-of-day values *
* *
* 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. *
* *
*******************************************************************************/
#ifndef _IBASE_
#include <ibase.hpp>
#endif
#ifndef _ISTRING_
#include <istring.hpp>
#endif
struct _CTIME;
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
class ostream;
class ITime : public IBase {
/*******************************************************************************
* Objects of the ITime class represent units of time (hours, minutes, and *
* seconds) as portions of days and provide support for converting these units *
* of time into numeric and ASCII format. *
* *
* ITime objects can be compared and operated on by adding them to and *
* subtracting them from other ITime objects. *
* *
* A related class whose objects also represent units of time is the IDate *
* class. *
*******************************************************************************/
public:
/*------------------------ Constructors ----------------------------------------
| You can construct ITime objects in the following ways: |
| |
| - By using the default constructor, which returns the current time. |
| |
| - By giving the number of seconds since midnight that the time is to |
| represent. In this case, the number of seconds can be negative and is |
| subtracted from the number of seconds in a day. |
| |
| - By giving the number of hours, minutes, and seconds since midnight |
| that the time is to represent. In this case, the number of seconds |
| cannot be negative. |
| |
| - By copying another ITime object. |
| |
| - By giving a container CTIME structure. |
| |
| - By using the static member function now to return the current time. |
------------------------------------------------------------------------------*/
ITime ( );
ITime ( long seconds );
ITime ( unsigned hours,
unsigned minutes,
unsigned seconds = 0 );
ITime ( const ITime &aTime );
ITime ( const _CTIME &cTime );
/*----------------------------- Current Time -----------------------------------
| Use the following function when you need the current time: |
| now - Returns the current time. This function can be used as an ITime |
| constructor. |
------------------------------------------------------------------------------*/
static ITime
now ( );
/*-------------------------------- Accessors -----------------------------------
| The following functions provide access to various portions of the |
| representation of the ITime object: |
| asSeconds - Returns the number of seconds since midnight. |
| asString - Returns the ITime object as a string that is formatted |
| according to the format argument. This format string can |
| contain time "conversion specifiers" as defined for the |
| standard C library function strftime in the time.h header |
| file. The default format is %X, which yields the time as |
| hh:mm:ss. |
| asCTIME - Returns the time as a container CTIME structure. |
| hours - Returns the number of hours past midnight. |
| minutes - Returns the number of minutes past the hour. |
| seconds - Returns the number of seconds past the minute. |
------------------------------------------------------------------------------*/
long
asSeconds ( ) const;
IString
asString ( const char *fmt = "%X" ) const;
_CTIME
asCTIME ( ) const;
unsigned
hours ( ) const,
minutes ( ) const,
seconds ( ) const;
/*-------------------------- Comparison Operators ------------------------------
| Using the following operators, two ITime objects can be compared to each |
| other: |
| operator == - Compares two objects to determine whether they are equal. |
| operator != - Compares two objects to determine whether they are not |
| equal. |
| operator < - Compares two objects to determine whether one is less than |
| the other. |
| operator <= - Compares two objects to determine whether one is less than |
| or equal to the other. |
| operator > - Compares two objects to determine whether one is greater |
| than the other. |
| operator >= - Compares two objects to determine whether one is greater |
| than or equal to the other. |
------------------------------------------------------------------------------*/
Boolean
operator == ( const ITime &aTime ) const,
operator != ( const ITime &aTime ) const,
operator < ( const ITime &aTime ) const,
operator <= ( const ITime &aTime ) const,
operator > ( const ITime &aTime ) const,
operator >= ( const ITime &aTime ) const;
/*------------------------- Manipulation Operators -----------------------------
| The following operators are used to manipulate the values of two ITime |
| objects and to store the results of those manipulations: |
| operator + - Adds two objects together. |
| operator - - Subtracts one object from another. |
| operator += - Stores the result of an addition operation in the receiver. |
| operator -= - Stores the result of a subtraction operation in the |
| receiver. |
------------------------------------------------------------------------------*/
ITime
operator + ( const ITime &aTime ) const,
operator - ( const ITime &aTime ) const;
ITime
&operator += ( const ITime &aTime ),
&operator -= ( const ITime &aTime );
/*------------------------------- Displaying -----------------------------------
| The following operator can be used to display an ITime object: |
| operator << - Outputs an object on an ostream. |
------------------------------------------------------------------------------*/
friend ostream
&operator << ( ostream &aStream,
const ITime &aTime );
protected:
/*----------------------------- Implementation ---------------------------------
| The following function is used to implement the ITime class: |
| initialize - Common initialization function used by constructors. |
------------------------------------------------------------------------------*/
ITime
&initialize ( long seconds );
private:
/*--------------------------------- PRIVATE ----------------------------------*/
long
ticks;
}; // ITime
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#ifndef I_NO_INLINES
#include <itime.inl>
#endif
#endif /* _ITIME_ */