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 60x60x24x31 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 wx.DateSpan will not, in general, give back the original date: Feb 28 - 1 month will be Jan 28, not Jan 31!
wx.DateSpan 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 wx.DateTime or wx.TimeSpan, but the type of result is different for each case.
Equality operators are defined for DateSpans. Two DateSpans are equal if and only if they both give the same target date when added to every source date. Thus DateSpan.Months(1) is not equal to DateSpan.Days(30), because they don’t give the same date when added to Feb 1st. But DateSpan.Days(14) is equal to DateSpan.Weeks(2).
Finally, notice that for adding hours, minutes and so on you don’t need this class at all: wx.TimeSpan will do the job because there are no subtleties associated with those (we don’t support leap seconds).
Warning
If you specify both weeks and days, the total number of days added will be 7weeks + days! See also GetTotalDays
.
See also
Constructs the date span object for the given number of years, months, weeks and days. |
|
Adds the given wx.DateSpan to this wx.DateSpan and returns a reference to itself. |
|
Returns a date span object corresponding to one day. |
|
Returns a date span object corresponding to the given number of days. |
|
Returns the number of days (not counting the weeks component) in this date span. |
|
Returns the number of the months (not counting the years) in this date span. |
|
Returns the combined number of days in this date span, counting both weeks and days. |
|
Returns the combined number of months in this date span, counting both years and months. |
|
Returns the number of weeks in this date span. |
|
Returns the number of years in this date span. |
|
Returns a date span object corresponding to one month. |
|
Returns a date span object corresponding to the given number of months. |
|
Multiplies this date span by the specified factor. |
|
Changes the sign of this date span. |
|
Returns a date span with the opposite sign. |
|
Sets the number of days (without modifying any other components) in this date span. |
|
Sets the number of months (without modifying any other components) in this date span. |
|
Sets the number of weeks (without modifying any other components) in this date span. |
|
Sets the number of years (without modifying any other components) in this date span. |
|
Subtracts the given wx.DateSpan to this wx.DateSpan and returns a reference to itself. |
|
Returns a date span object corresponding to one week. |
|
Returns a date span object corresponding to the given number of weeks. |
|
Returns a date span object corresponding to one year. |
|
Returns a date span object corresponding to the given number of years. |
wx.
DateSpan
(object)¶Possible constructors:
DateSpan(years=0, months=0, weeks=0, days=0)
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 60x60x24x31 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).
__init__
(self, years=0, months=0, weeks=0, 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.
years (int) –
months (int) –
weeks (int) –
days (int) –
Add
(self, other)¶Adds the given wx.DateSpan to this wx.DateSpan and returns a reference to itself.
other (wx.DateSpan) –
Day
()¶Returns a date span object corresponding to one day.
See also
Days
(days)¶Returns a date span object corresponding to the given number of days.
days (int) –
See also
GetDays
(self)¶Returns the number of days (not counting the weeks component) in this date span.
int
See also
GetMonths
(self)¶Returns the number of the months (not counting the years) in this date span.
int
GetTotalDays
(self)¶Returns the combined number of days in this date span, counting both weeks and days.
This doesn’t take months or years into account.
int
GetTotalMonths
(self)¶Returns the combined number of months in this date span, counting both years and months.
int
New in version 2.9.5.
GetWeeks
(self)¶Returns the number of weeks in this date span.
int
See also
GetYears
(self)¶Returns the number of years in this date span.
int
Month
()¶Returns a date span object corresponding to one month.
See also
Months
(mon)¶Returns a date span object corresponding to the given number of months.
mon (int) –
See also
Multiply
(self, factor)¶Multiplies this date span by the specified factor.
The product is computed by multiplying each of the components by the factor.
factor (int) –
A reference to this wx.DateSpan object modified in place.
Neg
(self)¶Changes the sign of this date span.
See also
Negate
(self)¶Returns a date span with the opposite sign.
See also
SetDays
(self, n)¶Sets the number of days (without modifying any other components) in this date span.
n (int) –
SetMonths
(self, n)¶Sets the number of months (without modifying any other components) in this date span.
n (int) –
SetWeeks
(self, n)¶Sets the number of weeks (without modifying any other components) in this date span.
n (int) –
SetYears
(self, n)¶Sets the number of years (without modifying any other components) in this date span.
n (int) –
Subtract
(self, other)¶Subtracts the given wx.DateSpan to this wx.DateSpan and returns a reference to itself.
other (wx.DateSpan) –
Week
()¶Returns a date span object corresponding to one week.
See also
Weeks
(weeks)¶Returns a date span object corresponding to the given number of weeks.
weeks (int) –
See also
Year
()¶Returns a date span object corresponding to one year.
See also
Years
(years)¶Returns a date span object corresponding to the given number of years.
years (int) –
See also