contents up previous next

wxdatespan

this class is a "logical time span" and is useful for implementing program logic for such things as "add one month to the date" which, in general, doesn't mean to add 60*60*24*31 seconds to it, but to take the same date the next month (to understand that this is indeed different consider adding one month to feb, 15 -- we want to get mar, 15, of course).

when adding a month to the date, all lesser components (days, hours, ...) won't be changed unless the resulting date would be invalid: for example, jan 31 + 1 month will be feb 28, not (non-existing) feb 31.

because of this feature, adding and subtracting back again the same wxdatespan will not, in general give back the original date: feb 28 - 1 month will be jan 28, not jan 31!

wxdatespan objects can be either positive or negative. they may be multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1 month and 1 day) is 2 months and 2 days. they can be added together and with wxdatetime or wxtimespan, but the type of result is different for each case.

beware about weeks: if you specify both weeks and days, the total number of days added will be 7*weeks + days! see also gettotaldays() function.

equality operators are defined for wxdatespans. two datespans are equal if and only if they both give the same target date when added to every source date. thus wxdatespan::months(1) is not equal to wxdatespan::days(30), because they don't give the same date when added to 1 feb. but wxdatespan::days(14) is equal to wxdatespan::weeks(2)

finally, notice that for adding hours, minutes and so on you don't need this class at all: wxtimespan will do the job because there are no subtleties associated with those (we don't support leap seconds).

derived from

no base class

include files

<wx/datetime.h>

see also

date classes overview, wxdatetime

members

wxdatespan::wxdatespan
wxdatespan::add
wxdatespan::day
wxdatespan::days
wxdatespan::getdays
wxdatespan::getmonths
wxdatespan::gettotaldays
wxdatespan::getweeks
wxdatespan::getyears
wxdatespan::month
wxdatespan::months
wxdatespan::multiply
wxdatespan::negate
wxdatespan::neg
wxdatespan::setdays
wxdatespan::setyears
wxdatespan::setmonths
wxdatespan::setweeks
wxdatespan::subtract
wxdatespan::week
wxdatespan::weeks
wxdatespan::year
wxdatespan::years
wxdatespan::operator==
wxdatespan::operator!=


wxdatespan::wxdatespan

wxdatespan(int years = 0, int months = 0, int weeks = 0, int days = 0)

constructs the date span object for the given number of years, months, weeks and days. note that the weeks and days add together if both are given.


wxdatespan::add

wxdatespan add(const wxdatespan& other) const

wxdatespan& add(const wxdatespan& other)

wxdatespan& operator+=(const wxdatespan& other)

returns the sum of two date spans. the first version returns a new object, the second and third ones modify this object in place.


wxdatespan::day

static wxdatespan day()

returns a date span object corresponding to one day.

see also

days


wxdatespan::days

static wxdatespan days(int days)

returns a date span object corresponding to the given number of days.

see also

day


wxdatespan::getdays

int getdays() const

returns the number of days (only, that it not counting the weeks component!) in this date span.

see also

gettotaldays


wxdatespan::getmonths

int getmonths() const

returns the number of the months (not counting the years) in this date span.


wxdatespan::gettotaldays

int gettotaldays() const

returns the combined number of days in this date span, counting both weeks and days. it still doesn't take neither months nor years into the account.

see also

getweeks, getdays


wxdatespan::getweeks

int getweeks() const

returns the number of weeks in this date span.

see also

gettotaldays


wxdatespan::getyears

int getyears() const

returns the number of years in this date span.


wxdatespan::month

static wxdatespan month()

returns a date span object corresponding to one month.

see also

months


wxdatespan::months

static wxdatespan months(int mon)

returns a date span object corresponding to the given number of months.

see also

month


wxdatespan::multiply

wxdatespan multiply(int factor) const

wxdatespan& multiply(int factor)

wxdatespan& operator*=(int factor)

returns the product of the date span by the specified factor. the product is computed by multiplying each of the components by the factor.

the first version returns a new object, the second and third ones modify this object in place.


wxdatespan::negate

wxdatespan negate() const

returns the date span with the opposite sign.

see also

neg


wxdatespan::neg

wxdatespan& neg()

wxdatespan& operator-()

changes the sign of this date span.

see also

negate


wxdatespan::setdays

wxdatespan& setdays(int n)

sets the number of days (without modifying any other components) in this date span.


wxdatespan::setyears

wxdatespan& setyears(int n)

sets the number of years (without modifying any other components) in this date span.


wxdatespan::setmonths

wxdatespan& setmonths(int n)

sets the number of months (without modifying any other components) in this date span.


wxdatespan::setweeks

wxdatespan& setweeks(int n)

sets the number of weeks (without modifying any other components) in this date span.


wxdatespan::subtract

wxdatespan subtract(const wxdatespan& other) const

wxdatespan& subtract(const wxdatespan& other)

wxdatespan& operator+=(const wxdatespan& other)

returns the difference of two date spans. the first version returns a new object, the second and third ones modify this object in place.


wxdatespan::week

static wxdatespan week()

returns a date span object corresponding to one week.

see also

weeks


wxdatespan::weeks

static wxdatespan weeks(int weeks)

returns a date span object corresponding to the given number of weeks.

see also

week


wxdatespan::year

static wxdatespan year()

returns a date span object corresponding to one year.

see also

years


wxdatespan::years

static wxdatespan years(int years)

returns a date span object corresponding to the given number of years.

see also

year


wxdatespan::operator==

bool operator==(wxdatespan& other) const

returns true if this date span is equal to the other one. two date spans are considered equal if and only if they have the same number of years and months and the same total number of days (counting both days and weeks).


wxdatespan::operator!=

bool operator!=(wxdatespan& other) const

returns true if this date span is different from the other one.

see also

operator==