WWC snapshot of http://www.alw.nih.gov/Docs/NIHCL/nihcl_51.html taken on Sat Jun 10 19:14:05 1995

Go to the previous, next section.

Time--Time of Day

SYNOPSIS

#include <nihcl/Time.h>

BASE CLASS

Object

DERIVED CLASSES

None

RELATED CLASSES

Date

DESCRIPTION

Instances of class Time represent a time of day, internally represented as the number of seconds elapsed since January 1, 1901, 00:00:00 GMT. Times through December 31, 2036, 23:59:59 GMT can be represented.

Class Time provides a complete set of arithmetic and relational operators along with member functions for converting a Time to a Date, obtaining the local or GMT hour, minute, and second, and printing a Time.

Member functions of class Time use the following data types:

typedef unsigned short hourTy;
typedef unsigned short minuteTy;
typedef unsigned short secondTy;
typedef unsigned long clockTy;          // seconds elapsed since
					// 1-Jan-01 GMT

CONSTRUCTORS

Time()
Contructs a Time for the current time.

Time(clockTy s)
Constructs a Time for s seconds since January 1, 1901, 00:00:00 GMT.

Time(hourTy h, minuteTy m, secondTy s =0, bool dst =NO)
Constructs a Time for today at the specfied (local) hour h, minute m, and second s. The argument dst is ignored unless Daylight Savings Time (DST) is observed locally and it is between 1:00 AM and 1:59 AM on the day when the transition from DST to Standard Time occurs, currently the last Sunday in October. In this case, dst = YES indicates DST and dst = NO indicates Standard Time.

If DST is observed locally, an NIHCL_BADTIME exception is raised if the specified time is between 1:00 AM and 1:59 AM on the day when the transition from Standard Time to DST occurs, currently the last Sunday in April.

Time(const Date& d, hourTy h =0, minuteTy m =0, secondTy s =0, bool dst =NO)
Constructs a Time for the Date d at the specfied (local) hour h, minute m, and second s. The argument dst is ignored unless Daylight Savings Time is observed locally and it is between 1:00 AM and 1:59 AM on the day when the transition from DST to Standard Time occurs, currently the last Sunday in October. In this case, dst = YES indicates DST and dst = NO indicates Standard Time.

If DST is observed locally, an NIHCL_BADTIME exception is raised if the time specified is between 1:00 AM and 1:59 AM on the day when the transition from Standard Time to DST occurs, currently the last Sunday in April. An NIHCL_DATERANGE exception is raised if the Date specified is before January 1, 1901, 00:00:00 GMT or after December 31, 2036, 23:59:59 GMT.

ARITHMETIC OPERATORS

friend Time operator+(const Time& t, long s)
friend Time operator+(long s, const Time& t)
Returns a Time that is s seconds after the Time t if s is positive, or s seconds before t if s is negative.

Time operator-(long s) const
Returns a Time that is s seconds before the Time t if s is positive, or s seconds after t if s is negative.

long operator-(const Time&) const
Returns the number of seconds between this Time and the argument Time. The result is negative if the argument Time is later than this Time.

void operator+=(long s)
Replaces this Time by one that is s seconds after this Time if s is positive, or s seconds before this Time if s is negative.

void operator-=(long s)
Replaces this Time by one that is s seconds before this Time if s is positive, or s seconds after this Time if s is negative.

SEARCHING

virtual unsigned hash() const
Returns a number suitable for use as a hash table probe.

RELATIONAL OPERATORS

bool operator<(const Time&) const
bool operator<=(const Time&) const
bool operator>(const Time&) const
bool operator>=(const Time&) const
bool operator==(const Time&) const
bool operator!=(const Time&) const
Returns YES if the indicated relation holds between this Time and the argument Time.

COMPARING TIMES

Time max(const Time& t) const
Returns the later of this Time and the argument Time.

Time min(const Time& t) const
Returns the earlier of this Time and the argument Time.

virtual int compare(const Object& ob) const
Compares this Time with the argument object ob, which must also be an instance of class Time. Returns a negative result if this Time is earlier than ob, zero if this Time equals ob, and a positive result if this Time is later than ob.

TESTING TIMES

bool between(const Time& min, const Time& max) const
Returns YES if this Time is later than or equal to min and earlier than or equal to max.

virtual bool isEqual(const Object& ob) const
Returns YES if ob is of species Time and equals this Time.

CONVERTING TIMES

operator Date() const
Converts this Time to an instance of class Date.

hourTy hour() const
minuteTy minute() const
secondTy second() const
Returns the hour (0-23), minute, or second of this Time adjusted to the local time zone.

hourTy hourGMT() const
minuteTy minuteGMT() const
secondTy second() const
Returns the hour (0-23), minute, or second of this Time in Greenwich Mean Time (GMT).

clockTy seconds() const
Returns the number of seconds elapsed from January 1, 1901, 00:00:00 GMT to this GMT Time.

COPYING TIMES

virtual void deepenShallowCopy()
This function is a no-op for class Time.

READING AND PRINTING TIMES

virtual void printOn(ostream& strm =cout)
Prints this Time adjusted to the local time zone on the output stream strm in the 24-hour format HH:MM:SS.

TIME SPECIES

virtual const Class* species() const
Returns a pointer to the class descriptor for class Time.

PROTECTED MEMBERS

Object I/O

virtual void storer(OIOofd& fd) const
virtual void storer(OIOout& strm) const
Stores this Time on fd or strm.

EXCEPTIONS RAISED

NIHCL_DATERANGE, NIHCL_BADTIME

Go to the previous, next section.