Module: DB Interface Module Group: Data Type
RWDBDuration RWCollectable
operator!=() operator>() operator>=() |
operator<() operator<=() operator*() |
operator+() operator-() operator/() |
operator==() |
#include <rw/db/duration.h> RWDBDuration d; // construct zero length duration RWDBDuration d(2,4); // construct duration of 2 years // and 4 months
RWDBDuration represents a time span, stored in a double as a 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:
#define RWDB_MILLISECONDS_PER_SEC ((double)1000.0) #define RWDB_SECONDS_PER_MIN ((double)60.0) #define RWDB_SECONDS_PER_HR (RWDB_SECONDS_PER_MIN * 60.0) #define RWDB_SECONDS_PER_DAY (RWDB_SECONDS_PER_HR * 24.0) #define RWDB_SECONDS_PER_WEEK (RWDB_SECONDS_PER_DAY * 7.0) #define RWDB_SECONDS_PER_RWMTH (RWDB_SECONDS_PER_WEEK * 4.0) #define RWDB_SECONDS_PER_RWYR (RWDB_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.
RWDBDuration();
Default constructor. Constructs an RWDBDuration of zero length.
RWDBDuration(double numSec);
Constructs an RWDBDuration that takes a time span stored in a double as a number of seconds.
RWDBDuration(int years, int rwmonths = 0, int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0);
Constructs an RWDBDuration that is the sum of the supplied parts, according to the conversions listed above.
RWDBDuration(const RWDBDuration& d);
Copy constructor. RWDBDuration obeys value semantics.
void addDays(int days);
Adds the given number of days to self.
void addHours(int hours);
Adds the given number of hours to self.
void addMilliseconds(int milliseconds);
Adds the given number of milliseconds to self.
void addMinutes(int minutes);
Adds the given number of minutes to self.
void addRWMonths(int months);
Adds the given number of months to self.
void addRWYears(int years);
Adds the given number of years to self.
void addSeconds(int seconds);
Adds the given number of seconds to self.
void addWeeks(int weeks);
Adds the given number of weeks to self.
double asDays() const;
Returns self converted to days.
double asHours() const;
Returns self converted to hours.
double asMilliseconds() const;
Returns self converted to milliseconds.
double asMinutes() const;
Returns self converted to minutes.
double asRWMonths() const;
Returns self converted to months.
double asRWYears() const;
Returns self converted to years.
double asSeconds() const;
Returns self converted to seconds.
double asWeeks() const;
Returns self converted to weeks.
RWCString 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.
RWspace binaryStoreSize() const;
Returns the number of bytes required to store self.
int 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 hash() const;
Returns a value suitable for hashing.
bool isEqual(const RWDBDuration* d) const;
Returns true if compareTo(this, d) == 0, otherwise returns false.
void restoreFrom(RWFile& file);
Reads file, replacing contents of self.
void restoreFrom(RWvistream& vis);
Reads vis, replacing contents of self.
void saveOn(RWFile& file) const;
Writes the contents of self to file.
void saveOn(RWvostream& vos) const;
Writes the contents of self to vos.
RWDBDuration& operator=(const RWDBDuration& dur);
Assignment operator. RWDBDuration obeys value semantics.
RWDBDuration operator-();
Unary minus. Returns the negation of self.
RWDBDuration& operator+=(const RWDBDuration& duration);
Adds duration to self and returns the result.
RWDBDuration& operator+=(double seconds);
Adds seconds to self and returns the result.
RWDBDuration& operator-=(const RWDBDuration& duration);
Subtracts duration from self and returns the result.
RWDBDuration& operator-=(double seconds);
Subtracts seconds from self and returns the result.
RWDBDuration& operator*=(double factor);
Multiplies self by factor and returns the result.
RWDBDuration& operator/=(double divisor);
Divides self by divisor and returns the result.
bool operator==(const RWDBDuration& a, const RWDBDuration& b);
Returns true if a and b are exactly equal, otherwise returns false.
bool operator!=(const RWDBDuration& a, const RWDBDuration& b);
Returns true if a and b are not exactly equal, otherwise returns false.
bool operator>(const RWDBDuration& a, const RWDBDuration& b);
Returns true if a is greater than b, otherwise returns false.
bool operator>=(const RWDBDuration& a, const RWDBDuration& b);
Returns true if a is greater than or equal to b, otherwise returns false.
bool operator<(const RWDBDuration& a, const RWDBDuration& b);
Returns true if a is less than b, otherwise returns false.
bool operator<=(const RWDBDuration& a, const RWDBDuration& b);
Returns true if a is less than or equal to b, otherwise returns false.
RWDBDuration operator+(RWDBDuration& a, const RWDBDuration& b);
Returns the result of adding a and b.
RWDBDuration operator+(RWDBDuration& duration, double seconds);
Adds seconds to duration and returns the result.
RWDBDuration operator-(RWDBDuration& a, const RWDBDuration& b);
Returns the result of subtracting b from a.
RWDBDuration operator-(RWDBDuration& duration, double seconds);
Subtracts seconds from duration and returns the result.
RWDBDuration operator*(RWDBDuration& duration, double factor);
Returns the result of multiplying duration by factor.
RWDBDuration operator/(RWDBDuration& duration, double divisor);
Returns the result of dividing duration by divisor.
RWDBDuration operator-(const RWDBDateTime& a, const RWDBDateTime& b);
Returns the duration between RWDBDateTimes a and b.
© 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.