SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Represents a time span in number of seconds. More...
#include <rw/db/duration.h>
Public Member Functions | |
RWDBDuration () | |
RWDBDuration (int yr, int mth=0, int day=0, int hr=0, int min=0, int sec=0, int msec=0) | |
RWDBDuration (double seconds) | |
RWDBDuration (const RWDBDuration &d) | |
double | asRWYears () const |
double | asRWMonths () const |
double | asWeeks () const |
double | asDays () const |
double | asHours () const |
double | asMinutes () const |
double | asSeconds () const |
double | asMilliseconds () const |
void | addRWYears (int years) |
void | addRWMonths (int months) |
void | addWeeks (int weeks) |
void | addDays (int days) |
void | addHours (int hours) |
void | addMinutes (int minutes) |
void | addSeconds (int seconds) |
void | addMilliseconds (int milliseconds) |
RWCString | asString () const |
RWspace | binaryStoreSize () const |
int | compareTo (const RWDBDuration *d) const |
bool | isEqual (const RWDBDuration *d) const |
unsigned | hash () const |
void | saveOn (RWFile &file) const |
void | saveOn (RWvostream &vos) const |
void | restoreFrom (RWFile &file) |
void | restoreFrom (RWvistream &vis) |
RWDBDuration | operator- () const |
RWDBDuration & | operator= (const RWDBDuration &dur) |
RWDBDuration & | operator+= (const RWDBDuration &duration) |
RWDBDuration & | operator-= (const RWDBDuration &duration) |
RWDBDuration & | operator+= (double seconds) |
RWDBDuration & | operator-= (double seconds) |
RWDBDuration & | operator*= (double factor) |
RWDBDuration & | operator/= (double divisor) |
Static Public Attributes | |
static const double | DUR_MILLISECONDS_PER_SEC |
static const double | DUR_SECONDS_PER_MIN |
static const double | DUR_SECONDS_PER_HR |
static const double | DUR_SECONDS_PER_DAY |
static const double | DUR_SECONDS_PER_WEEK |
static const double | DUR_SECONDS_PER_RWMTH |
static const double | DUR_SECONDS_PER_RWYR |
Friends | |
bool | operator== (const RWDBDuration &a, const RWDBDuration &b) |
bool | operator!= (const RWDBDuration &a, const RWDBDuration &b) |
bool | operator> (const RWDBDuration &a, const RWDBDuration &b) |
bool | operator>= (const RWDBDuration &a, const RWDBDuration &b) |
bool | operator< (const RWDBDuration &a, const RWDBDuration &b) |
bool | operator<= (const RWDBDuration &a, const RWDBDuration &b) |
RWDBDuration | operator+ (RWDBDuration &a, const RWDBDuration &b) |
RWDBDuration | operator- (RWDBDuration &a, const RWDBDuration &b) |
RWDBDuration | operator+ (RWDBDuration &duration, double seconds) |
RWDBDuration | operator- (RWDBDuration &duration, double seconds) |
RWDBDuration | operator* (RWDBDuration &duration, double factor) |
RWDBDuration | operator/ (RWDBDuration &duration, double divisor) |
RWDBDuration | operator- (const RWDBDateTime &a, const RWDBDateTime &b) |
RWDBDuration represents a time span, stored in a double
as number of seconds.
RWDBDuration supports arithmetic operations involving the imprecise quantities months and years. As a reminder, the terms RWMonth and RWYear are used in some member function names. The following conversions are used:
static const double DUR_MILLISECONDS_PER_SEC = ((double)1000.0); static const double DUR_SECONDS_PER_MIN = ((double)60.0); static const double DUR_SECONDS_PER_HR = ((double)3600.0); // DUR_SECONDS_PER_MIN * 60.0 static const double DUR_SECONDS_PER_DAY = ((double)86400.0); // DUR_SECONDS_PER_HR * 24.0 static const double DUR_SECONDS_PER_WEEK = ((double)604800.0); // DUR_SECONDS_PER_DAY * 7.0 static const double DUR_SECONDS_PER_RWMTH = ((double)2419200.0); // DUR_SECONDS_PER_WEEK * 4.0 static const double DUR_SECONDS_PER_RWYR = ((double)29030400.0); // DUR_SECONDS_PER_RWMTH * 12.0
For example, adding one RWMonth to an RWDBDuration adds four weeks' worth of seconds to the duration, regardless of the number of weeks in any particular month.
#include <rw/db/duration.h> RWDBDuration d; // construct zero length duration RWDBDuration d(2,4); // construct duration of 2 years // and 4 months
RWDBDuration::RWDBDuration | ( | ) |
Default constructor. Constructs an RWDBDuration of zero length.
RWDBDuration::RWDBDuration | ( | int | yr, | |
int | mth = 0 , |
|||
int | day = 0 , |
|||
int | hr = 0 , |
|||
int | min = 0 , |
|||
int | sec = 0 , |
|||
int | msec = 0 | |||
) |
Constructs an RWDBDuration that is the sum of the supplied parts, according to the conversions listed above.
RWDBDuration::RWDBDuration | ( | double | seconds | ) |
Constructs an RWDBDuration that takes a time span stored in a double as a number of seconds.
RWDBDuration::RWDBDuration | ( | const RWDBDuration & | d | ) |
Copy constructor. RWDBDuration obeys value semantics.
void RWDBDuration::addDays | ( | int | days | ) |
Adds the given number of days to self.
void RWDBDuration::addHours | ( | int | hours | ) |
Adds the given number of hours to self.
void RWDBDuration::addMilliseconds | ( | int | milliseconds | ) |
Adds the given number of milliseconds to self.
void RWDBDuration::addMinutes | ( | int | minutes | ) |
Adds the given number of minutes to self.
void RWDBDuration::addRWMonths | ( | int | months | ) |
Adds the given number of months to self.
void RWDBDuration::addRWYears | ( | int | years | ) |
Adds the given number of years to self.
void RWDBDuration::addSeconds | ( | int | seconds | ) |
Adds the given number of seconds to self.
void RWDBDuration::addWeeks | ( | int | weeks | ) |
Adds the given number of weeks to self.
double RWDBDuration::asDays | ( | ) | const |
Returns self converted to days
.
double RWDBDuration::asHours | ( | ) | const |
Returns self converted to hours
.
double RWDBDuration::asMilliseconds | ( | ) | const |
Returns self converted to milliseconds
.
double RWDBDuration::asMinutes | ( | ) | const |
Returns self converted to minutes
.
double RWDBDuration::asRWMonths | ( | ) | const |
Returns self converted to months
.
double RWDBDuration::asRWYears | ( | ) | const |
Returns self converted to years
.
double RWDBDuration::asSeconds | ( | ) | const |
Returns self converted to seconds
.
RWCString RWDBDuration::asString | ( | ) | const |
Returns a string of the format # interval
, where the interval is determined by the modularity of the duration, that is, days, seconds, etc. Applications should interpret the actual contents of the interval, and format a string appropriately.
double RWDBDuration::asWeeks | ( | ) | const |
Returns self converted to weeks
.
RWspace RWDBDuration::binaryStoreSize | ( | ) | const |
Returns the number of bytes required to store self.
int RWDBDuration::compareTo | ( | const RWDBDuration * | d | ) | const |
Returns -1
, 0
, or 1
depending upon whether self is less than, equal to, or greater than the RWDBDuration addressed by d.
unsigned RWDBDuration::hash | ( | ) | const |
Returns a value suitable for hashing.
bool RWDBDuration::isEqual | ( | const RWDBDuration * | d | ) | const |
Returns true
if compareTo(this, d) == 0
, otherwise returns false
.
RWDBDuration& RWDBDuration::operator*= | ( | double | factor | ) |
Multiplies self by factor and returns the result.
RWDBDuration& RWDBDuration::operator+= | ( | double | seconds | ) |
Adds seconds to self and returns the result.
RWDBDuration& RWDBDuration::operator+= | ( | const RWDBDuration & | duration | ) |
Adds duration to self and returns the result.
RWDBDuration RWDBDuration::operator- | ( | ) | const |
Unary minus. Returns the negation of self.
RWDBDuration& RWDBDuration::operator-= | ( | double | seconds | ) |
Subtracts seconds from self and returns the result.
RWDBDuration& RWDBDuration::operator-= | ( | const RWDBDuration & | duration | ) |
Subtracts duration from self and returns the result.
RWDBDuration& RWDBDuration::operator/= | ( | double | divisor | ) |
Divides self by divisor and returns the result.
RWDBDuration& RWDBDuration::operator= | ( | const RWDBDuration & | dur | ) |
Assignment operator. RWDBDuration obeys value semantics.
void RWDBDuration::restoreFrom | ( | RWvistream & | vis | ) |
Reads vis, replacing contents of self.
void RWDBDuration::restoreFrom | ( | RWFile & | file | ) |
Reads file, replacing contents of self.
void RWDBDuration::saveOn | ( | RWvostream & | vos | ) | const |
Writes the contents of self to vos.
void RWDBDuration::saveOn | ( | RWFile & | file | ) | const |
Writes the contents of self to file.
bool operator!= | ( | const RWDBDuration & | a, | |
const RWDBDuration & | b | |||
) | [friend] |
Returns true
if a and b are not exactly equal, otherwise returns false
.
RWDBDuration operator* | ( | RWDBDuration & | duration, | |
double | factor | |||
) | [friend] |
Returns the result of multiplying duration by factor.
RWDBDuration operator+ | ( | RWDBDuration & | duration, | |
double | seconds | |||
) | [friend] |
Adds seconds to duration and returns the result.
RWDBDuration operator+ | ( | RWDBDuration & | a, | |
const RWDBDuration & | b | |||
) | [friend] |
Returns the result of adding a and b.
RWDBDuration operator- | ( | const RWDBDateTime & | a, | |
const RWDBDateTime & | b | |||
) | [friend] |
Returns the duration between RWDBDateTime objects a and b.
RWDBDuration operator- | ( | RWDBDuration & | duration, | |
double | seconds | |||
) | [friend] |
Subtracts seconds from duration and returns the result.
RWDBDuration operator- | ( | RWDBDuration & | a, | |
const RWDBDuration & | b | |||
) | [friend] |
Returns the result of subtracting b from a.
RWDBDuration operator/ | ( | RWDBDuration & | duration, | |
double | divisor | |||
) | [friend] |
Returns the result of dividing duration by divisor.
bool operator< | ( | const RWDBDuration & | a, | |
const RWDBDuration & | b | |||
) | [friend] |
Returns true
if a is less than b, otherwise returns false
.
bool operator<= | ( | const RWDBDuration & | a, | |
const RWDBDuration & | b | |||
) | [friend] |
Returns true
if a is less than or equal to b, otherwise returns false
.
bool operator== | ( | const RWDBDuration & | a, | |
const RWDBDuration & | b | |||
) | [friend] |
Returns true
if a and b are exactly equal, otherwise returns false
.
bool operator> | ( | const RWDBDuration & | a, | |
const RWDBDuration & | b | |||
) | [friend] |
Returns true
if a is greater than b, otherwise returns false
.
bool operator>= | ( | const RWDBDuration & | a, | |
const RWDBDuration & | b | |||
) | [friend] |
Returns true
if a is greater than or equal to b, otherwise returns false
.
const double RWDBDuration::DUR_MILLISECONDS_PER_SEC [static] |
Static constant double
with value 1000.0
, used in arithmetic operations involving the imprecise quantities months and years.
const double RWDBDuration::DUR_SECONDS_PER_DAY [static] |
Static constant double
with value 86400.0
, used in arithmetic operations involving the imprecise quantities months and years.
const double RWDBDuration::DUR_SECONDS_PER_HR [static] |
Static constant double
with value 3600.0
, used in arithmetic operations involving the imprecise quantities months and years.
const double RWDBDuration::DUR_SECONDS_PER_MIN [static] |
Static constant double
with value 60.0
, used in arithmetic operations involving the imprecise quantities months and years.
const double RWDBDuration::DUR_SECONDS_PER_RWMTH [static] |
Static constant double
with value 2419200.0
, used in arithmetic operations involving the imprecise quantities months and years.
const double RWDBDuration::DUR_SECONDS_PER_RWYR [static] |
Static constant double
with value 29030400.0
, used in arithmetic operations involving the imprecise quantities months and years.
const double RWDBDuration::DUR_SECONDS_PER_WEEK [static] |
Static constant double
with value 604800.0
, used in arithmetic operations involving the imprecise quantities months and years.
© 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.