SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Static Public Attributes | Friends
RWDBDuration Class Reference

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)
 
void addDays (int days)
 
void addHours (int hours)
 
void addMilliseconds (int milliseconds)
 
void addMinutes (int minutes)
 
void addRWMonths (int months)
 
void addRWYears (int years)
 
void addSeconds (int seconds)
 
void addWeeks (int weeks)
 
double asDays () const
 
double asHours () const
 
double asMilliseconds () const
 
double asMinutes () const
 
double asRWMonths () const
 
double asRWYears () const
 
double asSeconds () const
 
RWCString asString () const
 
double asWeeks () const
 
RWspace binaryStoreSize () const
 
int compareTo (const RWDBDuration *d) const
 
unsigned hash () const
 
bool isEqual (const RWDBDuration *d) const
 
RWDBDurationoperator*= (double factor)
 
RWDBDurationoperator+= (const RWDBDuration &duration)
 
RWDBDurationoperator+= (double seconds)
 
RWDBDuration operator- () const
 
RWDBDurationoperator-= (const RWDBDuration &duration)
 
RWDBDurationoperator-= (double seconds)
 
RWDBDurationoperator/= (double divisor)
 
RWDBDurationoperator= (const RWDBDuration &dur)
 
void restoreFrom (RWFile &file)
 
void restoreFrom (RWvistream &vis)
 
void saveOn (RWFile &file) const
 
void saveOn (RWvostream &vos) const
 

Static Public Attributes

static const double DUR_MILLISECONDS_PER_SEC
 
static const double DUR_SECONDS_PER_DAY
 
static const double DUR_SECONDS_PER_HR
 
static const double DUR_SECONDS_PER_MIN
 
static const double DUR_SECONDS_PER_RWMTH
 
static const double DUR_SECONDS_PER_RWYR
 
static const double DUR_SECONDS_PER_WEEK
 

Friends

bool operator!= (const RWDBDuration &a, const RWDBDuration &b)
 
RWDBDuration operator* (RWDBDuration &duration, double factor)
 
RWDBDuration operator+ (RWDBDuration &a, const RWDBDuration &b)
 
RWDBDuration operator+ (RWDBDuration &duration, double seconds)
 
RWDBDuration operator- (RWDBDuration &a, const RWDBDuration &b)
 
RWDBDuration operator- (RWDBDuration &duration, double seconds)
 
RWDBDuration operator- (const RWDBDateTime &a, const RWDBDateTime &b)
 
RWDBDuration operator/ (RWDBDuration &duration, double divisor)
 
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)
 

Detailed Description

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.

Synopsis
#include <rw/db/duration.h>
RWDBDuration d; // construct zero length duration
RWDBDuration d(2,4); // construct duration of 2 years
// and 4 months

Constructor & Destructor Documentation

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.

Member Function Documentation

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.

As a precondition, d is tested to determine if it is a null pointer. If null, the method asserts in debug mode, and throws RWInternalErr in optimized builds.

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+= ( const RWDBDuration duration)

Adds duration to self and returns the result.

RWDBDuration& RWDBDuration::operator+= ( double  seconds)

Adds seconds to self and returns the result.

RWDBDuration RWDBDuration::operator- ( ) const

Unary minus. Returns the negation of self.

RWDBDuration& RWDBDuration::operator-= ( const RWDBDuration duration)

Subtracts duration from self and returns the result.

RWDBDuration& RWDBDuration::operator-= ( double  seconds)

Subtracts seconds 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 ( RWFile file)

Reads file, replacing contents of self.

void RWDBDuration::restoreFrom ( RWvistream vis)

Reads vis, replacing contents of self.

void RWDBDuration::saveOn ( RWFile file) const

Writes the contents of self to file.

void RWDBDuration::saveOn ( RWvostream vos) const

Writes the contents of self to vos.

Friends And Related Function Documentation

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 a,
const RWDBDuration b 
)
friend

Returns the result of adding a and b.

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 subtracting b from a.

RWDBDuration operator- ( RWDBDuration duration,
double  seconds 
)
friend

Subtracts seconds from duration and returns the result.

RWDBDuration operator- ( const RWDBDateTime a,
const RWDBDateTime b 
)
friend
Deprecated:
As of SourcePro 12.5, use operator-(const RWDateTime&, const RWDateTime&) instead. This function can be replaced by code similar to RWDBDuration((<RWDateTime_instance1> - <RWDateTime_instance2>)/1000.0);.

Returns the duration between RWDBDateTime objects a and b.

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.

Member Data Documentation

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 © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.