SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Deprecated. Represents a time, stored as the number of seconds since 00:00:00 January 1, 1901 GMT. More...
#include <rw/rwtime.h>
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()) | |
void | extract (struct tm *ptm, const RWZone &zone=RWZone::local()) const |
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 |
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 |
unsigned | second () const |
unsigned long | seconds () const |
RWTime | operator++ () |
RWTime | operator-- () |
RWTime | operator++ (int) |
RWTime | operator-- (int) |
RWTime & | operator+= (unsigned long s) |
RWTime & | operator-= (unsigned long s) |
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 RWTime | now () |
static unsigned | hash (const RWTime &t) |
Friends | |
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) |
bool | operator>= (const RWTime &t1, const RWTime &t2) |
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) |
Related Functions | |
(Note that these are not member functions.) | |
RWvistream & | operator>> (RWvistream &str, RWTime &t) |
RWFile & | operator>> (RWFile &file, RWTime &t) |
RWvostream & | operator<< (RWvostream &str, const RWTime &t) |
RWFile & | operator<< (RWFile &file, const RWTime &t) |
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.
Output formatting is done using an RWLocale object. The default locale formats according to U.S. conventions.
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: 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.
#include <rw/rwtime.h> RWTime a; // Construct with current time
Simple
#include <rw/rwtime.h> #include <rw/rwdate.h> int main() { // Current time RWTime t; RWTime d (RWTime::beginDST (1990, RWZone::local())); 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
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.
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 () | |||
) | [inline] |
Constructs a time for a given date, hour, minute, and second, relative to the time zone zone, which defaults to local time.
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.
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.
struct tm
differs from that used in RWTime arguments. 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 C99 function 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.
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.
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
RWFile& operator<<(RWFile&, const RWTime&);
Reimplemented in RWCollectableTime.
int RWTime::compareTo | ( | const RWTime * | t | ) | const |
Comparison function, useful for sorting times. Compares self to the RWTime pointed to by t.
0 | if self == *t; | |
1 | if self > *t; | |
-1 | if self < *t; |
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 |
static unsigned RWTime::hash | ( | const RWTime & | t | ) | [static] |
Returns the hash value of t as returned by t.hash().
unsigned RWTime::hash | ( | ) | const |
Returns a suitable hashing value.
Reimplemented in RWCollectableTime.
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.
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++ | ( | int | ) | [inline] |
Postfix increment operator. Adds one second to self, returning the initial value.
RWTime RWTime::operator++ | ( | ) | [inline] |
Prefix increment operator. Adds one second to self, then returns the results.
RWTime& RWTime::operator+= | ( | unsigned long | s | ) | [inline] |
Adds s seconds to self, returning self.
RWTime RWTime::operator-- | ( | int | ) | [inline] |
Postfix decrement operator. Subtracts one second from self, returning the initial value.
RWTime RWTime::operator-- | ( | ) | [inline] |
Prefix decrement operator. Subtracts one second from self, then returns the results.
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.
Returns true
if t1 is not equal to t2.
Returns an RWTime s seconds greater than t.
Returns an RWTime s seconds greater than t.
Returns an RWTime s seconds less than t.
Returns true
if t1 is less than t2.
RWvostream & operator<< | ( | RWvostream & | str, | |
const RWTime & | t | |||
) | [related] |
Saves an RWTime t onto the virtual stream str.
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.
Returns true
if t1 is less than or equal to t2.
Returns true
if t1 is equal to t2.
Returns true
if t1 is greater than t2.
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.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.