SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Static Public Member Functions | Friends | Related Functions

Deprecated. Represents a time, stored as the number of seconds since 00:00:00 January 1, 1901 GMT. More...

#include <rw/rwtime.h>

Inheritance diagram for RWTime:
RWCollectableTime

Public Member Functions

 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 &zone=RWZone::local())
 
 RWTime (const RWDate &date, const RWCString &str, const RWZone &zone=RWZone::local(), const RWLocale &locale=RWLocale::global())
 
 RWTime (const struct tm *ptm, const RWZone &zone=RWZone::local())
 
RWCString asString (char format= '\0', const RWZone &zone=RWZone::local(), const RWLocale &locale=RWLocale::global()) const
 
RWCString asString (const char *format, const RWZone &zone=RWZone::local(), const RWLocale &locale=RWLocale::global()) const
 
bool between (const RWTime &a, const RWTime &b) const
 
RWspace binaryStoreSize () const
 
int compareTo (const RWTime *t) const
 
void extract (struct tm *ptm, const RWZone &zone=RWZone::local()) const
 
unsigned hash () const
 
unsigned hour (const RWZone &zone=RWZone::local()) const
 
unsigned hourGMT () const
 
bool isDST (const RWZone &zone=RWZone::local()) const
 
bool 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
 
RWTime operator++ ()
 
RWTime operator++ (int)
 
RWTimeoperator+= (unsigned long s)
 
RWTime operator-- ()
 
RWTime operator-- (int)
 
RWTimeoperator-= (unsigned long s)
 
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 &zone=RWZone::local())
 
static unsigned hash (const RWTime &t)
 
static RWTime now ()
 

Friends

bool operator!= (const RWTime &t1, const RWTime &t2)
 
RWTime operator+ (const RWTime &t, unsigned long s)
 
RWTime operator+ (unsigned long s, const RWTime &t)
 
RWTime operator- (const RWTime &t, unsigned long s)
 
bool operator< (const RWTime &t1, const RWTime &t2)
 
std::ostream & operator<< (std::ostream &s, const RWTime &t)
 
bool operator<= (const RWTime &t1, const RWTime &t2)
 
bool operator== (const RWTime &t1, const RWTime &t2)
 
bool operator> (const RWTime &t1, const RWTime &t2)
 
bool operator>= (const RWTime &t1, const RWTime &t2)
 

Related Functions

(Note that these are not member functions.)

RWvostreamoperator<< (RWvostream &str, const RWTime &t)
 
RWFileoperator<< (RWFile &file, const RWTime &t)
 
RWvistreamoperator>> (RWvistream &str, RWTime &t)
 
RWFileoperator>> (RWFile &file, RWTime &t)
 

Detailed Description

Deprecated:
As of SourcePro 10, use RWDateTime instead.

Class RWTime represents a time, stored as the number of seconds since 00:00:00 January 1, 1901 GMT. The Essential Tools User's Guide chapter on date and time classes describes how to set the time zone for your compiler. Failure to do so may result in GMT times being wrong.

Note
RWTime is unable to store times prior to 00:00:00 1 Jan 1901.

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

Note
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 Essential Tools Module template collections should consider the following:

// Figures out the current time just once:

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.

Synopsis
#include <rw/rwtime.h>
RWTime a; // Construct with current time
Persistence
Simple
Example
#include <rw/rwtime.h>
#include <rw/rwdate.h>
int main()
{
// Current time
RWTime t;
std::cout << "Current time: " << t << std::endl;
std::cout << "Start of DST, 1990: " << d << std::endl;
}

Program output:

Current time: 06/18/09 13:43:39
Start of DST, 1990: 04/01/90 03:00:00

Constructor & Destructor Documentation

RWTime::RWTime ( )
inline

Default constructor. Constructs a time with the present time.

RWTime::RWTime ( unsigned long  s)
inline

Constructs a time with s seconds since 00:00:00 January 1, 1901 GMT. If s == 0, an invalid time is constructed.

Note
For small s, this may be prior to January 1, 1901 in your time zone.

The compiler can parse 0 as either an integer or a pointer. Since there is also a constructor that takes a pointer (to struct tm, if you want to construct a time from the unsigned long value 0, you must be explicit:

RWTime earlyTime((unsigned long)0);
RWTime::RWTime ( unsigned  hour,
unsigned  minute,
unsigned  second = 0,
const RWZone zone = RWZone::local() 
)

Constructs a time with today's date and the specified hour, minute, and second, relative to the time zone zone, which defaults to local time.

RWTime::RWTime ( const RWDate date,
unsigned  hour = 0,
unsigned  minute = 0,
unsigned  second = 0,
const RWZone zone = RWZone::local() 
)

Constructs a time for a given date, hour, minute, and second, relative to the time zone zone, which defaults to local time.

Note
The maximum RWTime is much sooner than maximum RWDate. (In fact, it is on Feb. 5, 2037 for platforms with 4-byte longs.) This is a consequence of the fact that RWTime counts seconds, while RWDate deals only with full days.
RWTime::RWTime ( const RWDate date,
const RWCString str,
const RWZone zone = RWZone::local(),
const RWLocale locale = RWLocale::global() 
)

Constructs a time for the given date, extracting the time from the string str. The string str should contain only the time. The time is understood to be relative to the time zone zone, which defaults to local time. The specified locale is used for formatting information. Use function isValid() to check the results.

Note
Not all time string errors can be detected by this function.
RWTime::RWTime ( const struct tm *  ptm,
const RWZone zone = RWZone::local() 
)

Constructs a time from the tm_year, tm_mon, tm_mday, tm_hour, tm_min, and tm_sec components of the struct tm argument. These components are understood to be relative to the time zone zone, which defaults to local time.

Note
The numbering of months and years in a struct tm differs from that used in RWTime arguments.

Member Function Documentation

RWCString RWTime::asString ( char  format = '\0',
const RWZone zone = RWZone::local(),
const RWLocale locale = RWLocale::global() 
) const

Returns self as a string, formatted by the RWLocale argument, with the time zone adjusted according to the RWZone argument. Formats are as defined by the C++ Standard Library function std::strftime(). The default format is the date followed by the time: "%x %X". The exact format of the date and time returned is dependent upon the Locale-dependent %x and %X formatting. For more information, see RWLocale.

RWCString RWTime::asString ( const char *  format,
const RWZone zone = RWZone::local(),
const RWLocale locale = RWLocale::global() 
) const

Returns self as a string, formatted by the RWLocale argument, with the time zone adjusted according to the RWZone argument. Formats are as defined by the C++ Standard Library function std::strftime(). For more information, see RWLocale.

static RWTime RWTime::beginDST ( unsigned  year,
const RWZone zone = RWZone::local() 
)
static

Returns the start of Daylight Saving Time (DST) for the given year, in the given time zone. Returns an "invalid time" if DST is not observed in that year and zone.

bool RWTime::between ( const RWTime a,
const RWTime b 
) const
inline

Returns true if RWTime is between a and b, inclusive.

RWspace RWTime::binaryStoreSize ( ) const
inline

Returns the number of bytes necessary to store the object using the global function

int RWTime::compareTo ( const RWTime t) const

Compares self to the contents of t, returning a value from the table below based on the result of the comparison.

0 self == *t
<0 self < *t
>0 self > *t
static RWTime RWTime::endDST ( unsigned  year,
const RWZone zone = RWZone::local() 
)
static

Returns the end of Daylight Saving Time for the given year, in the given time zone. Returns an "invalid time" if DST is not observed in that year and zone.

void RWTime::extract ( struct tm *  ptm,
const RWZone zone = RWZone::local() 
) const

Fills all members of the struct tm argument, adjusted to the time zone specified by the RWZone argument. If the time is invalid, the struct tm members are all set to -1.

Note
The encoding of struct tm members is different from that used in RWTime and RWDate functions.
unsigned RWTime::hash ( ) const

Returns a suitable hashing value.

static unsigned RWTime::hash ( const RWTime t)
static

Returns the hash value of t as returned by t.hash().

unsigned RWTime::hour ( const RWZone zone = RWZone::local()) const

Returns the hour, adjusted to the time zone specified.

unsigned RWTime::hourGMT ( ) const

Returns the hour in GMT.

bool RWTime::isDST ( const RWZone zone = RWZone::local()) const

Returns true if self is during Daylight Saving Time in the time zone given by zone, false otherwise.

bool RWTime::isValid ( void  ) const
inline

Returns true if this is a valid time, false otherwise.

RWTime RWTime::max ( const RWTime t) const
inline

Returns the later time of self or t .

RWTime RWTime::min ( const RWTime t) const
inline

Returns the earlier time of self or t .

unsigned RWTime::minute ( const RWZone zone = RWZone::local()) const

Returns the minute, adjusted to the time zone specified.

unsigned RWTime::minuteGMT ( ) const

Returns the minute in GMT.

static RWTime RWTime::now ( )
static

Returns the present time.

RWTime RWTime::operator++ ( )
inline

Prefix increment operator. Adds one second to self, then returns the results.

RWTime RWTime::operator++ ( int  )
inline

Postfix increment operator. Adds one second to self, returning the initial value.

RWTime& RWTime::operator+= ( unsigned long  s)
inline

Adds s seconds to self, returning self.

RWTime RWTime::operator-- ( )
inline

Prefix decrement operator. Subtracts one second from self, then returns the results.

RWTime RWTime::operator-- ( int  )
inline

Postfix decrement operator. Subtracts one second from self, returning the initial value.

RWTime& RWTime::operator-= ( unsigned long  s)
inline

Subtracts s seconds from self, returning self.

unsigned RWTime::second ( ) const

Returns the second in local time or GMT.

unsigned long RWTime::seconds ( ) const
inline

Returns the number of seconds since 00:00:00 January 1, 1901 GMT.

Friends And Related Function Documentation

bool operator!= ( const RWTime t1,
const RWTime t2 
)
friend

Returns true if t1 is not equal to t2.

RWTime operator+ ( const RWTime t,
unsigned long  s 
)
friend

Returns an RWTime s seconds greater than t.

RWTime operator+ ( unsigned long  s,
const RWTime t 
)
friend

Returns an RWTime s seconds greater than t.

RWTime operator- ( const RWTime t,
unsigned long  s 
)
friend

Returns an RWTime s seconds less than t.

bool operator< ( const RWTime t1,
const RWTime t2 
)
friend

Returns true if t1 is less than t2.

std::ostream& operator<< ( std::ostream &  s,
const RWTime t 
)
friend

Outputs the time t on ostream s, according to the locale imbued in the stream (see class RWLocale), or by RWLocale::global() if none.

RWvostream & operator<< ( RWvostream str,
const RWTime t 
)
related

Saves an RWTime t onto the virtual stream str.

RWFile & operator<< ( RWFile file,
const RWTime t 
)
related

Saves an RWTime t onto the RWFile file.

bool operator<= ( const RWTime t1,
const RWTime t2 
)
friend

Returns true if t1 is less than or equal to t2.

bool operator== ( const RWTime t1,
const RWTime t2 
)
friend

Returns true if t1 is equal to t2.

bool operator> ( const RWTime t1,
const RWTime t2 
)
friend

Returns true if t1 is greater than t2.

bool operator>= ( const RWTime t1,
const RWTime t2 
)
friend

Returns true if t1 is greater than or equal to t2.

RWvistream & operator>> ( RWvistream str,
RWTime t 
)
related

Restores an RWTime into t from the virtual stream str, replacing the previous contents of t.

RWFile & operator>> ( RWFile file,
RWTime t 
)
related

Restores an RWTime into t from the RWFile file, replacing the previous contents of t.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.