SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

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 (const RWDate &date, const RWCString &str, const RWZone &zone=RWZone::local(), const RWLocale &locale=RWLocale::global())
 
 RWTime (const RWDate &date, unsigned hour=0, unsigned minute=0, unsigned second=0, const RWZone &zone=RWZone::local())
 
 RWTime (const struct tm *ptm, const RWZone &zone=RWZone::local())
 
 RWTime (unsigned hour, unsigned minute, unsigned second=0, const RWZone &zone=RWZone::local())
 
 RWTime (unsigned long s)
 
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 Symbols

(Note that these are not member symbols.)

RWFileoperator<< (RWFile &file, const RWTime &t)
 
RWvostreamoperator<< (RWvostream &str, const RWTime &t)
 
RWFileoperator>> (RWFile &file, RWTime &t)
 
RWvistreamoperator>> (RWvistream &str, 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
Deprecated. Represents a time, stored as the number of seconds since 00:00:00 January 1,...
Definition rwtime.h:111

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:
Maintains a collection of values implemented as a vector.
Definition tvordvec.h:108
RWTime()
Definition rwtime.h:116

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/rwdate.h>
#include <rw/rwtime.h>
int main() {
// Current time
RWTime t;
std::cout << "Current time: " << t << std::endl;
std::cout << "Start of DST, 1990: " << d << std::endl;
}
static RWTime beginDST(unsigned year, const RWZone &zone=RWZone::local())
static const RWZone & local()

Program output:

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

Constructor & Destructor Documentation

◆ RWTime() [1/6]

RWTime::RWTime ( )
inline

Default constructor. Constructs a time with the present time.

◆ RWTime() [2/6]

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() [3/6]

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() [4/6]

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() [5/6]

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() [6/6]

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

◆ asString() [1/2]

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.

◆ asString() [2/2]

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.

◆ beginDST()

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.

◆ between()

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

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

◆ binaryStoreSize()

RWspace RWTime::binaryStoreSize ( ) const
inline

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

Represents an abstraction of a filesystem regular file.
Definition rwfile.h:68
friend std::ostream & operator<<(std::ostream &s, const RWTime &t)

◆ compareTo()

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

◆ endDST()

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.

◆ extract()

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.

◆ hash() [1/2]

unsigned RWTime::hash ( ) const

Returns a suitable hashing value.

◆ hash() [2/2]

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

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

◆ hour()

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

Returns the hour, adjusted to the time zone specified.

◆ hourGMT()

unsigned RWTime::hourGMT ( ) const

Returns the hour in GMT.

◆ isDST()

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.

◆ isValid()

bool RWTime::isValid ( ) const
inline

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

◆ max()

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

Returns the later time of self or t .

◆ min()

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

Returns the earlier time of self or t .

◆ minute()

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

Returns the minute, adjusted to the time zone specified.

◆ minuteGMT()

unsigned RWTime::minuteGMT ( ) const

Returns the minute in GMT.

◆ now()

static RWTime RWTime::now ( )
static

Returns the present time.

◆ operator++() [1/2]

RWTime RWTime::operator++ ( )
inline

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

◆ operator++() [2/2]

RWTime RWTime::operator++ ( int )
inline

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

◆ operator+=()

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

Adds s seconds to self, returning self.

◆ operator--() [1/2]

RWTime RWTime::operator-- ( )
inline

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

◆ operator--() [2/2]

RWTime RWTime::operator-- ( int )
inline

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

◆ operator-=()

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

Subtracts s seconds from self, returning self.

◆ second()

unsigned RWTime::second ( ) const

Returns the second in local time or GMT.

◆ seconds()

unsigned long RWTime::seconds ( ) const
inline

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

Friends And Related Symbol Documentation

◆ operator!=

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

Returns true if t1 is not equal to t2.

◆ operator+ [1/2]

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

Returns an RWTime s seconds greater than t.

◆ operator+ [2/2]

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

Returns an RWTime s seconds greater than t.

◆ operator-

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

Returns an RWTime s seconds less than t.

◆ operator<

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

Returns true if t1 is less than t2.

◆ operator<<() [1/3]

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

Saves an RWTime t onto the RWFile file.

◆ operator<<() [2/3]

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

Saves an RWTime t onto the virtual stream str.

◆ operator<< [3/3]

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.

◆ operator<=

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

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

◆ operator==

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

Returns true if t1 is equal to t2.

◆ operator>

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

Returns true if t1 is greater than t2.

◆ operator>=

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

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

◆ operator>>() [1/2]

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

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

◆ operator>>() [2/2]

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

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

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