.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. _wx.DateSpan: ========================================================================================================================================== |phoenix_title| **wx.DateSpan** ========================================================================================================================================== 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 :ref:`wx.DateSpan` will **not**, in general, give back the original date: Feb 28 - 1 month will be Jan 28, not Jan 31! :ref:`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 :ref:`wx.DateTime` or :ref:`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: :ref:`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 :meth:`GetTotalDays` . .. seealso:: :ref:`Date and Time `, :ref:`wx.DateTime` | |class_hierarchy| Class Hierarchy ================================= .. raw:: html
Inheritance diagram for class DateSpan:
| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.DateSpan.__init__` Constructs the date span object for the given number of years, months, weeks and days. :meth:`~wx.DateSpan.Add` Adds the given :ref:`wx.DateSpan` to this :ref:`wx.DateSpan` and returns a reference to itself. :meth:`~wx.DateSpan.Day` Returns a date span object corresponding to one day. :meth:`~wx.DateSpan.Days` Returns a date span object corresponding to the given number of days. :meth:`~wx.DateSpan.GetDays` Returns the number of days (not counting the weeks component) in this date span. :meth:`~wx.DateSpan.GetMonths` Returns the number of the months (not counting the years) in this date span. :meth:`~wx.DateSpan.GetTotalDays` Returns the combined number of days in this date span, counting both weeks and days. :meth:`~wx.DateSpan.GetTotalMonths` Returns the combined number of months in this date span, counting both years and months. :meth:`~wx.DateSpan.GetWeeks` Returns the number of weeks in this date span. :meth:`~wx.DateSpan.GetYears` Returns the number of years in this date span. :meth:`~wx.DateSpan.Month` Returns a date span object corresponding to one month. :meth:`~wx.DateSpan.Months` Returns a date span object corresponding to the given number of months. :meth:`~wx.DateSpan.Multiply` Multiplies this date span by the specified `factor`. :meth:`~wx.DateSpan.Neg` Changes the sign of this date span. :meth:`~wx.DateSpan.Negate` Returns a date span with the opposite sign. :meth:`~wx.DateSpan.SetDays` Sets the number of days (without modifying any other components) in this date span. :meth:`~wx.DateSpan.SetMonths` Sets the number of months (without modifying any other components) in this date span. :meth:`~wx.DateSpan.SetWeeks` Sets the number of weeks (without modifying any other components) in this date span. :meth:`~wx.DateSpan.SetYears` Sets the number of years (without modifying any other components) in this date span. :meth:`~wx.DateSpan.Subtract` Subtracts the given :ref:`wx.DateSpan` to this :ref:`wx.DateSpan` and returns a reference to itself. :meth:`~wx.DateSpan.Week` Returns a date span object corresponding to one week. :meth:`~wx.DateSpan.Weeks` Returns a date span object corresponding to the given number of weeks. :meth:`~wx.DateSpan.Year` Returns a date span object corresponding to one year. :meth:`~wx.DateSpan.Years` Returns a date span object corresponding to the given number of years. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: 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). .. method:: __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. :param `years`: :type `years`: int :param `months`: :type `months`: int :param `weeks`: :type `weeks`: int :param `days`: :type `days`: int .. method:: Add(self, other) Adds the given :ref:`wx.DateSpan` to this :ref:`wx.DateSpan` and returns a reference to itself. :param `other`: :type `other`: wx.DateSpan :rtype: :ref:`wx.DateSpan` .. staticmethod:: Day() Returns a date span object corresponding to one day. :rtype: :ref:`wx.DateSpan` .. seealso:: :meth:`Days` .. staticmethod:: Days(days) Returns a date span object corresponding to the given number of days. :param `days`: :type `days`: int :rtype: :ref:`wx.DateSpan` .. seealso:: :meth:`Day` .. method:: GetDays(self) Returns the number of days (not counting the weeks component) in this date span. :rtype: `int` .. seealso:: :meth:`GetTotalDays` .. method:: GetMonths(self) Returns the number of the months (not counting the years) in this date span. :rtype: `int` .. method:: 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. :rtype: `int` .. seealso:: :meth:`GetWeeks` , :meth:`GetDays` .. method:: GetTotalMonths(self) Returns the combined number of months in this date span, counting both years and months. :rtype: `int` .. versionadded:: 2.9.5 .. seealso:: :meth:`GetYears` , :meth:`GetMonths` .. method:: GetWeeks(self) Returns the number of weeks in this date span. :rtype: `int` .. seealso:: :meth:`GetTotalDays` .. method:: GetYears(self) Returns the number of years in this date span. :rtype: `int` .. staticmethod:: Month() Returns a date span object corresponding to one month. :rtype: :ref:`wx.DateSpan` .. seealso:: :meth:`Months` .. staticmethod:: Months(mon) Returns a date span object corresponding to the given number of months. :param `mon`: :type `mon`: int :rtype: :ref:`wx.DateSpan` .. seealso:: :ref:`wx.DateTime.Month` .. method:: Multiply(self, factor) Multiplies this date span by the specified `factor`. The product is computed by multiplying each of the components by the `factor`. :param `factor`: :type `factor`: int :rtype: :ref:`wx.DateSpan` :returns: A reference to this :ref:`wx.DateSpan` object modified in place. .. method:: Neg(self) Changes the sign of this date span. :rtype: :ref:`wx.DateSpan` .. seealso:: :meth:`Negate` .. method:: Negate(self) Returns a date span with the opposite sign. :rtype: :ref:`wx.DateSpan` .. seealso:: :meth:`Neg` .. method:: SetDays(self, n) Sets the number of days (without modifying any other components) in this date span. :param `n`: :type `n`: int :rtype: :ref:`wx.DateSpan` .. method:: SetMonths(self, n) Sets the number of months (without modifying any other components) in this date span. :param `n`: :type `n`: int :rtype: :ref:`wx.DateSpan` .. method:: SetWeeks(self, n) Sets the number of weeks (without modifying any other components) in this date span. :param `n`: :type `n`: int :rtype: :ref:`wx.DateSpan` .. method:: SetYears(self, n) Sets the number of years (without modifying any other components) in this date span. :param `n`: :type `n`: int :rtype: :ref:`wx.DateSpan` .. method:: Subtract(self, other) Subtracts the given :ref:`wx.DateSpan` to this :ref:`wx.DateSpan` and returns a reference to itself. :param `other`: :type `other`: wx.DateSpan :rtype: :ref:`wx.DateSpan` .. staticmethod:: Week() Returns a date span object corresponding to one week. :rtype: :ref:`wx.DateSpan` .. seealso:: :meth:`Weeks` .. staticmethod:: Weeks(weeks) Returns a date span object corresponding to the given number of weeks. :param `weeks`: :type `weeks`: int :rtype: :ref:`wx.DateSpan` .. seealso:: :meth:`Week` .. staticmethod:: Year() Returns a date span object corresponding to one year. :rtype: :ref:`wx.DateSpan` .. seealso:: :meth:`Years` .. staticmethod:: Years(years) Returns a date span object corresponding to the given number of years. :param `years`: :type `years`: int :rtype: :ref:`wx.DateSpan` .. seealso:: :ref:`wx.DateTime.Year`