SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWDBDuration Class Reference

Represents a time span in number of seconds. More...

#include <rw/db/duration.h>

Public Member Functions

 RWDBDuration ()
 
 RWDBDuration (const RWDBDuration &d)
 
 RWDBDuration (double seconds)
 
 RWDBDuration (int yr, int mth=0, int day=0, int hr=0, int min=0, int sec=0, int msec=0)
 
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- (const RWDBDateTime &a, const RWDBDateTime &b)
 
RWDBDuration operator- (RWDBDuration &a, const RWDBDuration &b)
 
RWDBDuration operator- (RWDBDuration &duration, double seconds)
 
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
static const double DUR_SECONDS_PER_WEEK
Definition duration.h:414
static const double DUR_SECONDS_PER_RWYR
Definition duration.h:427
static const double DUR_MILLISECONDS_PER_SEC
Definition duration.h:390
static const double DUR_SECONDS_PER_MIN
Definition duration.h:396
static const double DUR_SECONDS_PER_RWMTH
Definition duration.h:420
static const double DUR_SECONDS_PER_HR
Definition duration.h:402
static const double DUR_SECONDS_PER_DAY
Definition duration.h:408

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
Represents a time span in number of seconds.
Definition duration.h:66

Constructor & Destructor Documentation

◆ RWDBDuration() [1/4]

RWDBDuration::RWDBDuration ( )

Default constructor. Constructs an RWDBDuration of zero length.

◆ RWDBDuration() [2/4]

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

RWDBDuration::RWDBDuration ( double seconds)

Constructs an RWDBDuration that takes a time span stored in a double as a number of seconds.

◆ RWDBDuration() [4/4]

RWDBDuration::RWDBDuration ( const RWDBDuration & d)

Copy constructor. RWDBDuration obeys value semantics.

Member Function Documentation

◆ addDays()

void RWDBDuration::addDays ( int days)

Adds the given number of days to self.

◆ addHours()

void RWDBDuration::addHours ( int hours)

Adds the given number of hours to self.

◆ addMilliseconds()

void RWDBDuration::addMilliseconds ( int milliseconds)

Adds the given number of milliseconds to self.

◆ addMinutes()

void RWDBDuration::addMinutes ( int minutes)

Adds the given number of minutes to self.

◆ addRWMonths()

void RWDBDuration::addRWMonths ( int months)

Adds the given number of months to self.

◆ addRWYears()

void RWDBDuration::addRWYears ( int years)

Adds the given number of years to self.

◆ addSeconds()

void RWDBDuration::addSeconds ( int seconds)

Adds the given number of seconds to self.

◆ addWeeks()

void RWDBDuration::addWeeks ( int weeks)

Adds the given number of weeks to self.

◆ asDays()

double RWDBDuration::asDays ( ) const

Returns self converted to days.

◆ asHours()

double RWDBDuration::asHours ( ) const

Returns self converted to hours.

◆ asMilliseconds()

double RWDBDuration::asMilliseconds ( ) const

Returns self converted to milliseconds.

◆ asMinutes()

double RWDBDuration::asMinutes ( ) const

Returns self converted to minutes.

◆ asRWMonths()

double RWDBDuration::asRWMonths ( ) const

Returns self converted to months.

◆ asRWYears()

double RWDBDuration::asRWYears ( ) const

Returns self converted to years.

◆ asSeconds()

double RWDBDuration::asSeconds ( ) const

Returns self converted to seconds.

◆ asString()

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.

◆ asWeeks()

double RWDBDuration::asWeeks ( ) const

Returns self converted to weeks.

◆ binaryStoreSize()

RWspace RWDBDuration::binaryStoreSize ( ) const

Returns the number of bytes required to store self.

◆ compareTo()

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.

◆ hash()

unsigned RWDBDuration::hash ( ) const

Returns a value suitable for hashing.

◆ isEqual()

bool RWDBDuration::isEqual ( const RWDBDuration * d) const

Returns true if compareTo(this, d) == 0, otherwise returns false.

◆ operator*=()

RWDBDuration & RWDBDuration::operator*= ( double factor)

Multiplies self by factor and returns the result.

◆ operator+=() [1/2]

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

Adds duration to self and returns the result.

◆ operator+=() [2/2]

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

Adds seconds to self and returns the result.

◆ operator-()

RWDBDuration RWDBDuration::operator- ( ) const

Unary minus. Returns the negation of self.

◆ operator-=() [1/2]

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

Subtracts duration from self and returns the result.

◆ operator-=() [2/2]

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

Subtracts seconds from self and returns the result.

◆ operator/=()

RWDBDuration & RWDBDuration::operator/= ( double divisor)

Divides self by divisor and returns the result.

◆ operator=()

RWDBDuration & RWDBDuration::operator= ( const RWDBDuration & dur)

Assignment operator. RWDBDuration obeys value semantics.

◆ restoreFrom() [1/2]

void RWDBDuration::restoreFrom ( RWFile & file)

Reads file, replacing contents of self.

◆ restoreFrom() [2/2]

void RWDBDuration::restoreFrom ( RWvistream & vis)

Reads vis, replacing contents of self.

◆ saveOn() [1/2]

void RWDBDuration::saveOn ( RWFile & file) const

Writes the contents of self to file.

◆ saveOn() [2/2]

void RWDBDuration::saveOn ( RWvostream & vos) const

Writes the contents of self to vos.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const RWDBDuration & a,
const RWDBDuration & b )
friend

Returns true if a and b are not exactly equal, otherwise returns false.

◆ operator*

RWDBDuration operator* ( RWDBDuration & duration,
double factor )
friend

Returns the result of multiplying duration by factor.

◆ operator+ [1/2]

RWDBDuration operator+ ( RWDBDuration & a,
const RWDBDuration & b )
friend

Returns the result of adding a and b.

◆ operator+ [2/2]

RWDBDuration operator+ ( RWDBDuration & duration,
double seconds )
friend

Adds seconds to duration and returns the result.

◆ operator- [1/3]

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.

◆ operator- [2/3]

RWDBDuration operator- ( RWDBDuration & a,
const RWDBDuration & b )
friend

Returns the result of subtracting b from a.

◆ operator- [3/3]

RWDBDuration operator- ( RWDBDuration & duration,
double seconds )
friend

Subtracts seconds from duration and returns the result.

◆ operator/

RWDBDuration operator/ ( RWDBDuration & duration,
double divisor )
friend

Returns the result of dividing duration by divisor.

◆ operator<

bool operator< ( const RWDBDuration & a,
const RWDBDuration & b )
friend

Returns true if a is less than b, otherwise returns false.

◆ operator<=

bool operator<= ( const RWDBDuration & a,
const RWDBDuration & b )
friend

Returns true if a is less than or equal to b, otherwise returns false.

◆ operator==

bool operator== ( const RWDBDuration & a,
const RWDBDuration & b )
friend

Returns true if a and b are exactly equal, otherwise returns false.

◆ operator>

bool operator> ( const RWDBDuration & a,
const RWDBDuration & b )
friend

Returns true if a is greater than b, otherwise returns false.

◆ operator>=

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

◆ DUR_MILLISECONDS_PER_SEC

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.

◆ DUR_SECONDS_PER_DAY

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.

◆ DUR_SECONDS_PER_HR

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.

◆ DUR_SECONDS_PER_MIN

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.

◆ DUR_SECONDS_PER_RWMTH

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.

◆ DUR_SECONDS_PER_RWYR

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.

◆ DUR_SECONDS_PER_WEEK

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