Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTime

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <rw/rwtime.h>
RWTime a;   // Construct with current time

Description

Class RWTime represents a time, stored as the number of seconds since 00:00:00 January 1, 1901 GMT. See Section 5 of the User's Guide for how to set the time zone for your compiler. Failure to do this may result in GMT times being wrong.

Output formatting is done using an RWLocale object. The default locale formats according to U.S. conventions.

Note that because the default constructor for this class creates an instance holding the current date and time, constructing a large array of RWTime may be slow.

RWTime v[5000];     // Figures out the current time 5000 times

Those with access to the C++ Standard Library-based versions of the Tools.h++ template collections should consider the following:

// Figures out the current time just once:
RWTValOrderedVector<RWTime> v(5000, RWTime());

Thanks to the smart allocation scheme of the standard collections, the above declaration will result in only one call to the default constructor followed by 5000 invocations of the copy constructor. In the case of RWTime, the copy constructor amounts to an assignment of one long to another, resulting in faster creation than the simple array.

Persistence

Simple

Example

This example constructs a current time, and the time when Daylight-Saving Time starts in the year 1990. It then prints them out.

#include <rw/rwtime.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>

main(){
 RWTime t;   // Current time
 RWTime d(RWTime::beginDST(1990, RWZone::local()));
   cout << "Current time:         " << RWDate(t) << " " << t << 
            endl;
   cout << "Start of DST, 1990:   " << RWDate(d) << " " << d << 
           endl;
}

Program output

Current time:         03/22/91 15:01:40
Start of DST, 1990:   05/01/90 02:00:00

Public Constructors

RWTime();
RWTime(const RWTime&);
RWTime(unsigned long s);
RWTime(unsigned hour, unsigned minute, unsigned second=0,
       const RWZone& zone = RWZone::local());
RWTime(const RWDate& date, unsigned hour = 0, 
       unsigned minute = 0,unsigned second = 0, 
       const RWZone& = RWZone::local());
RWTime(const struct tm*, const RWZone& = RWZone::local());
RWTime(const RWDate& date, const RWCString& str,
       const RWZone& zone = RWZone::local(),
       const RWLocale& locale = RWLocale::global());

Public Member Operators

RWTime&
operator=(const RWTime&);
RWTime
operator++();
RWTime
operator--();
RWTime
operator++(int);
RWTime
operator--(int);
RWTime&
operator+=(unsigned long s);
RWTime&
operator-=(unsigned long s);

Public Member Functions

RWCString
asString(char format = '\0',const RWZone& = RWZone::local(),
         const RWLocale& = RWLocale::global()) const;
RWCString
asString(char* format,const RWZone&   = RWZone::local(),
         const RWLocale& = RWLocale::global()) const;
RWBoolean
between(const RWTime& a, const RWTime& b) const;
size_t
binaryStoreSize() const;
int
compareTo(const RWTime* t) const;
void
extract(struct tm*,const RWZone& = RWZone::local()) const;
unsigned
hash() const;
unsigned
hour(const RWZone& zone = RWZone::local()) const;
unsigned
hourGMT() const;
RWBoolean
isDST(const RWZone& zone = RWZone::local()) const;
RWBoolean
isValid() const;
RWTime
max(const RWTime& t) const;
RWTime
min(const RWTime& t) const;
unsigned
minute(const RWZone& zone = RWZone::local()) const;
unsigned
minuteGMT() const;
unsigned
second() const;
unsigned long
seconds() const;

Static Public Member Functions

static RWTime
beginDST(unsigned year,
         const RWZone& zone = RWZone::local());
static RWTime
endDST(unsigned year, const RWZone& = RWZone::local());
static unsigned
hash(const RWTime& t);
static RWTime
now();

Related Global Operators

RWTime
operator+(const RWTime& t, unsigned long s);
RWTime
operator+(unsigned long s, const RWTime& t);
RWTime
operator-(const RWTime& t, unsigned long s);
RWBoolean
operator<(const RWTime& t1, const RWTime& t2);
RWBoolean
operator<=(const RWTime& t1, const RWTime& t2);
RWBoolean
operator>(const RWTime& t1, const RWTime& t2);
RWBoolean
operator>=(const RWTime& t1, const RWTime& t2);
RWBoolean
operator==(const RWTime& t1, const RWTime& t2);
RWBoolean
operator!= (const RWTime& t1, const RWTime& t2);
ostream&
operator<<(ostream& s, const RWTime& t);
//istream&
//operator>>(istream&, RWTime&);
RWvostream&
operator<<(RWvostream&, const RWTime& t);
RWFile&
operator<<(RWFile&,     const RWTime& t);
RWvistream&
operator>>(RWvistream&, RWTime& t);
RWFile&
operator>>(RWFile&,     RWTime& t);


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.