ITime
- The ITime class represents units of time (hours, minutes, and seconds) as portions
of days and provides support for converting these
units of time into numeric and ASCII format. You can compare and operate
on ITime objects by adding them to and subtracting them from other
ITime objects. The accuracy of ITime is one second in the current implementation.
A related class whose objects also represent units of time is the class IDate.
The ITime class returns locale-sensitive information, based on the
current locale defined at run time. See the description of the standard C function
setlocale in your specific platform's system documentation
for information about setting the locale.
Note:
The value of ITime may go beyond the limit of a day during some operations, like
addition or substraction, and may not handle that correctly.
It is recommended to use ITimeStamp for these operations.
ITime - Member Functions and Data by Group
Constructors & Destructor
Construct and destruct ITime objects.
- ITime
- You can construct objects of this class in the following ways:
- Use the default constructor, which returns the current time.
- Give the number of seconds since midnight that the time
represents. In this case, the number of seconds can be negative and is
subtracted from the number of seconds in a day.
- Give the number of hours, minutes, and seconds since midnight
that the time represents. In this case, the number of seconds
cannot be negative.
- Copy another ITime object.
- Give a container details CTIME structure.
Overload 1
public:
ITime(const ITime& aTime)
- Use this constructor to copy another ITime object.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Overload 2
public:
ITime(long seconds)
- Use this constructor by specifying the number of seconds since midnight that the time
is to represent. For negative values, the constructor subtracts that value from
the number of seconds in a day.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Overload 3
public:
ITime(const ICnrTime& cnrTime)
- Use this constructor to construct an ITime object from a container details
ICnrTime structure.
-
cnrTime
-
The ICnrTime container time structure to initialize from.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Overload 4
public:
ITime( unsigned hours,
unsigned minutes,
unsigned seconds = 0 )
- Specify the number of hours, minutes, and seconds since midnight that the time represents.
The number of seconds cannot be negative.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Overload 5
public:
ITime()
- Use this constructor to return the current time; it is the default.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Comparisons
Use these members to compare two ITime objects. Use any of the full complement
of comparison operators and applying the natural meaning.
- operator !=
public:
bool operator !=(const ITime& aTime) const
- Compares this time object to another time object for inequality.
The aTime parameter is the time to add to this time to create a new time.
Returns true if this object is not equal to the passed object, otherwise returns false.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator <
public:
bool operator <(const ITime& aTime) const
- Compares this time object to another time object for relative magnitude.
The parameter aTime is the time to compare to this time.
Returns true if this object respresents a time prior to the passed time.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator <=
public:
bool operator <=(const ITime& aTime) const
- Compares this time object to another time object for relative magnitude or equality.
The parameter aTime is the time to compare to this time.
Returns true if this object respresents a time prior to or equal to the passed time.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator ==
public:
bool operator ==(const ITime& aTime) const
- Compares this time object to another time object for equality.
The aTime parameter is the time to add to this time to create a new time.
Returns true if this object is equal to the passed object, otherwise returns false.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator >
public:
bool operator >(const ITime& aTime) const
- Compares this time object to another time object for relative magnitude.
The aTime parameter is the time to add to this time to create a new time.
Returns true if this object respresents a time subsequent to the passed time.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator >=
public:
bool operator >=(const ITime& aTime) const
- Compares this time object to another time object for relative magnitude or equality.
The aTime parameter is the time to add to this time to create a new time.
Returns true if this object respresents a time subsequent to or equal to the passed time.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Current Time
Use this member when you need the current time.
- now
public:
static ITime now()
- Returns the current time. You can use this function as an ITime constructor.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Diagnostics
Use these members to provide an IString representation for an ITime object and the capability to output
the object to a stream. The formatting is based on the strftime conversion specifications. Often, you use
these members to write trace information when debugging your code.
- asString
public:
IString asString(const char* fmt = " % X") const
Returns the ITime object as a string that is formatted according to the specified
format string. This format string, fmt, controls how the time is formatted
and 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.
The conversion specifiers that apply to ITime and their meanings are listed in the
following table. IDate::asString describes conversion specifiers that apply to dates.
| Specifier
| Meaning
| %c
| Insert date and time of locale.
|
| %H
| Insert hour (24-hour clock) as a decimal number (00-23).
|
| %I
| Insert hour (12-hour clock) as a decimal number (01-12).
|
| %M
| Insert minute (00-59).
|
| %p
| Insert equivalent of either AM or PM locale.
|
| %S
| Insert second (00-61).
|
| %X
| Insert time representation of locale.
|
| %Z
| Insert name of time zone, or no characters if time zone is not available.
|
| %%
| Insert %.
| |
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Manipulation
Use these members to update an ITime object by adding or subtracting another ITime object.
Use any of the full complement of addition or subtraction operators and apply the natural meaning.
- operator +
public:
ITime operator +(const ITime& aTime) const
- Adds two time objects and returns a new ITime object with the resulting time.
The aTime parameter is the time to add to this time to create a new time.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator +=
public:
ITime& operator +=(const ITime& aTime)
- Adds a time object to this time object. This object is modifed to reflect the new time.
The parameter aTime is the time to add to this time to create the new time.
Returns a reference to this object.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator -
public:
ITime operator -(const ITime& aTime) const
- Subtracts a specified time from a time object and returns a new ITime object
with the resulting time.
The parameter aTime is the time to subtract from this time to
create a new time.
- aTime
- is the time to subtract from this time to create a new time.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator -=
public:
ITime& operator -=(const ITime& aTime)
- Subtracts a time object from this time object. This object is modified to reflect the new time.
The parameter aTime is the time to subtract from this time to create the new time.
Returns a reference to this object.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Streaming Support
These members allow you to stream time objects. Binary streams support in and output streaming, while text
streams support only output streaming.
- operator <<=
public:
void operator <<=(IDataStream& fromWhere)
- Streams this object in from the passed data stream. Any existing contents of this object are overwritten by
the information streamed in.
-
fromWhere
-
The stream to stream in from.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- operator >>=
public:
void operator >>=(IDataStream& toWhere)
- Streams this time object out to the passed data stream.
-
toWhere
-
The stream to stream out to.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
Time Queries
Use these members to access the seconds, minutes, and hours of an ITime object.
- asICnrTime
public:
ICnrTime asICnrTime() const
- Creates a container ICnrTime structure which represents
this object's time information and returns it by value.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- asSeconds
public:
long asSeconds() const
- Returns the number of seconds since midnight represented by this time object.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- hours
public:
unsigned hours() const
- Returns the number of hours past midnight represented by this object.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- minutes
public:
unsigned minutes() const
- Returns the number of minutes past the hour represented by this object.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
- seconds
public:
unsigned seconds() const
- Returns the number of seconds past the minute represented by this object.
- Supported Platforms
| Windows |
OS/2 |
AIX |
| Yes |
Yes |
Yes |
ITime - Inherited Member Functions and Data
Inherited Public Functions
Inherited Public Data
Inherited Protected Functions
- ITime
-
ITime& initialize(long seconds)
void readFromStream(IDataStream& fromWhere)
void writeToStream(IDataStream& toWhere) const
Inherited Protected Data