| Version: 3.0.5

- Main Page
- Related Pages
- Categories
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | List of all members
wxDateSpan Class Reference
Class List by Category » Data Structures

`#include <wx/datetime.h>`

## Detailed Description

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 with wxDateTime or wxTimeSpan, but the type of result is different for each case.

Warning
  If you specify both weeks and days, the total number of days added will be 7*weeks + days! See also GetTotalDays().

Equality operators are defined for wxDateSpans. Two wxDateSpans 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 Feb 1st. 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).

##

Library: wxBase
Category: Data Structures

See also
  Date and Time, wxDateTime

## Public Member Functions

| 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. More...
wxDateSpan | Add (const wxDateSpan &other) const
| Returns the sum of two date spans. More...
wxDateSpan & | Add (const wxDateSpan &other)
| Adds the given wxDateSpan to this wxDateSpan and returns a reference to itself. More...
int | GetDays () const
| Returns the number of days (not counting the weeks component) in this date span. More...
int | GetMonths () const
| Returns the number of the months (not counting the years) in this date span. More...
int | GetTotalMonths () const
| Returns the combined number of months in this date span, counting both years and months. More...
int | GetTotalDays () const
| Returns the combined number of days in this date span, counting both weeks and days. More...
int | GetWeeks () const
| Returns the number of weeks in this date span. More...
int | GetYears () const
| Returns the number of years in this date span. More...
wxDateSpan | Multiply (int factor) const
| Returns the product of the date span by the specified factor. More...
wxDateSpan & | Multiply (int factor)
| Multiplies this date span by the specified factor. More...
wxDateSpan & | Neg ()
| Changes the sign of this date span. More...
wxDateSpan | Negate () const
| Returns a date span with the opposite sign. More...
wxDateSpan & | SetDays (int n)
| Sets the number of days (without modifying any other components) in this date span. More...
wxDateSpan & | SetMonths (int n)
| Sets the number of months (without modifying any other components) in this date span. More...
wxDateSpan & | SetWeeks (int n)
| Sets the number of weeks (without modifying any other components) in this date span. More...
wxDateSpan & | SetYears (int n)
| Sets the number of years (without modifying any other components) in this date span. More...
wxDateSpan | Subtract (const wxDateSpan &other) const
| Returns the difference of two date spans. More...
wxDateSpan & | Subtract (const wxDateSpan &other)
| Subtracts the given wxDateSpan to this wxDateSpan and returns a reference to itself. More...
wxDateSpan & | operator+= (const wxDateSpan &other)
| Adds the given wxDateSpan to this wxDateSpan and returns the result. More...
wxDateSpan & | operator-= (const wxDateSpan &other)
| Subtracts the given wxDateSpan to this wxDateSpan and returns the result. More...
wxDateSpan & | operator- ()
| Changes the sign of this date span. More...
wxDateSpan & | operator*= (int factor)
| Multiplies this date span by the specified factor. More...
bool | operator!= (const wxDateSpan &other) const
| Returns true if this date span is different from the other one. More...
bool | operator== (const wxDateSpan &other) const
| Returns true if this date span is equal to the other one. More...

## Static Public Member Functions

static wxDateSpan | Day ()
| Returns a date span object corresponding to one day. More...
static wxDateSpan | Days (int days)
| Returns a date span object corresponding to the given number of days. More...
static wxDateSpan | Month ()
| Returns a date span object corresponding to one month. More...
static wxDateSpan | Months (int mon)
| Returns a date span object corresponding to the given number of months. More...
static wxDateSpan | Week ()
| Returns a date span object corresponding to one week. More...
static wxDateSpan | Weeks (int weeks)
| Returns a date span object corresponding to the given number of weeks. More...
static wxDateSpan | Year ()
| Returns a date span object corresponding to one year. More...
static wxDateSpan | Years (int years)
| Returns a date span object corresponding to the given number of years. More...

## Constructor & Destructor Documentation

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.

## Member Function Documentation

wxDateSpan wxDateSpan::Add | ( | const wxDateSpan & | other | ) | const

Returns the sum of two date spans.

Returns
  A new wxDateSpan object with the result.

wxDateSpan& wxDateSpan::Add | ( | const wxDateSpan & | other | ) |

Adds the given wxDateSpan to this wxDateSpan and returns a reference to itself.

static wxDateSpan wxDateSpan::Day | ( |  | ) |

static

Returns a date span object corresponding to one day.

See also
  Days()

static wxDateSpan wxDateSpan::Days | ( | int | days | ) |

static

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

See also
  Day()

int wxDateSpan::GetDays | ( |  | ) | const

Returns the number of days (not counting the weeks component) in this date span.

See also
  GetTotalDays()

int wxDateSpan::GetMonths | ( |  | ) | const

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

int wxDateSpan::GetTotalDays | ( |  | ) | const

Returns the combined number of days in this date span, counting both weeks and days.

This doesn't take months or years into account.

See also
  GetWeeks(), GetDays()

int wxDateSpan::GetTotalMonths | ( |  | ) | const

Returns the combined number of months in this date span, counting both years and months.

See also
  GetYears(), GetMonths()

Since
  2.9.5

int wxDateSpan::GetWeeks | ( |  | ) | const

Returns the number of weeks in this date span.

See also
  GetTotalDays()

int wxDateSpan::GetYears | ( |  | ) | const

Returns the number of years in this date span.

static wxDateSpan wxDateSpan::Month | ( |  | ) |

static

Returns a date span object corresponding to one month.

See also
  Months()

static wxDateSpan wxDateSpan::Months | ( | int | mon | ) |

static

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

See also
  Month()

wxDateSpan wxDateSpan::Multiply | ( | int | factor | ) | const

Returns the product of the date span by the specified factor.

The product is computed by multiplying each of the components by the factor.

Returns
  A new wxDateSpan object with the result.

wxDateSpan& wxDateSpan::Multiply | ( | int | factor | ) |

Multiplies this date span by the specified factor.

The product is computed by multiplying each of the components by the factor.

Returns
  A reference to this wxDateSpan object modified in place.

wxDateSpan& wxDateSpan::Neg | ( |  | ) |

Changes the sign of this date span.

See also
  Negate()

wxDateSpan wxDateSpan::Negate | ( |  | ) | const

Returns a date span with the opposite sign.

See also
  Neg()

bool wxDateSpan::operator!= | ( | const wxDateSpan & | other | ) | const

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

wxDateSpan& wxDateSpan::operator*= | ( | int | factor | ) |

Multiplies this date span by the specified factor.

The product is computed by multiplying each of the components by the factor.

Returns
  A reference to this wxDateSpan object modified in place.

wxDateSpan& wxDateSpan::operator+= | ( | const wxDateSpan & | other | ) |

Adds the given wxDateSpan to this wxDateSpan and returns the result.

wxDateSpan& wxDateSpan::operator- | ( |  | ) |

Changes the sign of this date span.

See also
  Negate()

wxDateSpan& wxDateSpan::operator-= | ( | const wxDateSpan & | other | ) |

Subtracts the given wxDateSpan to this wxDateSpan and returns the result.

bool wxDateSpan::operator== | ( | const 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& wxDateSpan::SetDays | ( | int | n | ) |

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

wxDateSpan& wxDateSpan::SetMonths | ( | int | n | ) |

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

wxDateSpan& wxDateSpan::SetWeeks | ( | int | n | ) |

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

wxDateSpan& wxDateSpan::SetYears | ( | int | n | ) |

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

wxDateSpan wxDateSpan::Subtract | ( | const wxDateSpan & | other | ) | const

Returns the difference of two date spans.

Returns
  A new wxDateSpan object with the result.

wxDateSpan& wxDateSpan::Subtract | ( | const wxDateSpan & | other | ) |

Subtracts the given wxDateSpan to this wxDateSpan and returns a reference to itself.

static wxDateSpan wxDateSpan::Week | ( |  | ) |

static

Returns a date span object corresponding to one week.

See also
  Weeks()

static wxDateSpan wxDateSpan::Weeks | ( | int | weeks | ) |

static

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

See also
  Week()

static wxDateSpan wxDateSpan::Year | ( |  | ) |

static

Returns a date span object corresponding to one year.

See also
  Years()

static wxDateSpan wxDateSpan::Years | ( | int | years | ) |

static

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

See also
  Year()