.. include:: headings.inc .. _TimeSpan: ========================================================================================================================================== |phoenix_title| **TimeSpan** ========================================================================================================================================== :ref:`TimeSpan` class represents a time interval. .. seealso:: :ref:`Date and Time `, :ref:`DateTime` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **TimeSpan** .. raw:: html

Inheritance diagram of TimeSpan

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~TimeSpan.__init__` Default constructor, constructs a zero timespan. :meth:`~TimeSpan.Abs` Returns the absolute value of the timespan: does not modify the object. :meth:`~TimeSpan.Add` Adds the given :ref:`TimeSpan` to this :ref:`TimeSpan` and returns a reference to itself. :meth:`~TimeSpan.Day` Returns the timespan for one day. :meth:`~TimeSpan.Days` Returns the timespan for the given number of days. :meth:`~TimeSpan.Format` Returns the string containing the formatted representation of the time span. :meth:`~TimeSpan.GetDays` Returns the difference in number of days. :meth:`~TimeSpan.GetHours` Returns the difference in number of hours. :meth:`~TimeSpan.GetMilliseconds` Returns the difference in number of milliseconds. :meth:`~TimeSpan.GetMinutes` Returns the difference in number of minutes. :meth:`~TimeSpan.GetSeconds` Returns the difference in number of seconds. :meth:`~TimeSpan.GetValue` Returns the internal representation of timespan. :meth:`~TimeSpan.GetWeeks` Returns the difference in number of weeks. :meth:`~TimeSpan.Hour` Returns the timespan for one hour. :meth:`~TimeSpan.Hours` Returns the timespan for the given number of hours. :meth:`~TimeSpan.IsEqualTo` Returns ``True`` if two timespans are equal. :meth:`~TimeSpan.IsLongerThan` Compares two timespans: works with the absolute values, i.e. :meth:`~TimeSpan.IsNegative` Returns ``True`` if the timespan is negative. :meth:`~TimeSpan.IsNull` Returns ``True`` if the timespan is empty. :meth:`~TimeSpan.IsPositive` Returns ``True`` if the timespan is positive. :meth:`~TimeSpan.IsShorterThan` Compares two timespans: works with the absolute values, i.e. :meth:`~TimeSpan.Millisecond` Returns the timespan for one millisecond. :meth:`~TimeSpan.Milliseconds` Returns the timespan for the given number of milliseconds. :meth:`~TimeSpan.Minute` Returns the timespan for one minute. :meth:`~TimeSpan.Minutes` Returns the timespan for the given number of minutes. :meth:`~TimeSpan.Multiply` Multiplies this time span by `n`. :meth:`~TimeSpan.Neg` Negate the value of the timespan. :meth:`~TimeSpan.Negate` Returns timespan with inverted sign. :meth:`~TimeSpan.Second` Returns the timespan for one second. :meth:`~TimeSpan.Seconds` Returns the timespan for the given number of seconds. :meth:`~TimeSpan.Subtract` Subtracts the given :ref:`TimeSpan` to this :ref:`TimeSpan` and returns a reference to itself. :meth:`~TimeSpan.Week` Returns the timespan for one week. :meth:`~TimeSpan.Weeks` Returns the timespan for the given number of weeks. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: TimeSpan(object) TimeSpan class represents a time interval. **Possible constructors**:: TimeSpan() TimeSpan(hours, min=0, sec=0, msec=0) .. method:: __init__(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **__init__** `(self)` Default constructor, constructs a zero timespan. **~~~** **__init__** `(self, hours, min=0, sec=0, msec=0)` Constructs timespan from separate values for each component, with the date set to 0. Hours are not restricted to ``0-24`` range, neither are minutes, seconds or milliseconds. :param `hours`: :type `hours`: long :param `min`: :type `min`: long :param `sec`: :type `sec`: long :param `msec`: :type `msec`: long **~~~** .. method:: Abs(self) Returns the absolute value of the timespan: does not modify the object. :rtype: :ref:`TimeSpan` .. method:: Add(self, *args, **kw) Adds the given :ref:`TimeSpan` to this :ref:`TimeSpan` and returns a reference to itself. .. staticmethod:: Day() Returns the timespan for one day. :rtype: :ref:`TimeSpan` .. staticmethod:: Days(days) Returns the timespan for the given number of days. :param `days`: :type `days`: long :rtype: :ref:`TimeSpan` .. method:: Format(self, format=DefaultTimeSpanFormat) Returns the string containing the formatted representation of the time span. The following format specifiers are allowed after %: - ``H`` - Number of Hours - ``M`` - Number of Minutes - ``S`` - Number of Seconds - ``l`` - Number of Milliseconds - ``D`` - Number of Days - ``E`` - Number of Weeks - ``%`` - The percent character Note that, for example, the number of hours in the description above is not well defined: it can be either the total number of hours (for example, for a time span of 50 hours this would be 50) or just the hour part of the time span, which would be 2 in this case as 50 hours is equal to 2 days and 2 hours. :ref:`TimeSpan` resolves this ambiguity in the following way: if there had been, indeed, the ``D`` format specified preceding the ``H`` , then it is interpreted as 2. Otherwise, it is 50. The same applies to all other format specifiers: if they follow a specifier of larger unit, only the rest part is taken, otherwise the full value is used. :param `format`: :type `format`: string :rtype: `string` .. method:: GetDays(self) Returns the difference in number of days. :rtype: `int` .. method:: GetHours(self) Returns the difference in number of hours. :rtype: `int` .. method:: GetMilliseconds(self) Returns the difference in number of milliseconds. :rtype: `long` .. method:: GetMinutes(self) Returns the difference in number of minutes. :rtype: `int` .. method:: GetSeconds(self) Returns the difference in number of seconds. :rtype: `long` .. method:: GetValue(self) Returns the internal representation of timespan. :rtype: `long` .. method:: GetWeeks(self) Returns the difference in number of weeks. :rtype: `int` .. staticmethod:: Hour() Returns the timespan for one hour. :rtype: :ref:`TimeSpan` .. staticmethod:: Hours(hours) Returns the timespan for the given number of hours. :param `hours`: :type `hours`: long :rtype: :ref:`TimeSpan` .. method:: IsEqualTo(self, ts) Returns ``True`` if two timespans are equal. :param `ts`: :type `ts`: TimeSpan :rtype: `bool` .. method:: IsLongerThan(self, ts) Compares two timespans: works with the absolute values, i.e. -2 hours is longer than 1 hour. Also, it will return ``False`` if the timespans are equal in absolute value. :param `ts`: :type `ts`: TimeSpan :rtype: `bool` .. method:: IsNegative(self) Returns ``True`` if the timespan is negative. :rtype: `bool` .. method:: IsNull(self) Returns ``True`` if the timespan is empty. :rtype: `bool` .. method:: IsPositive(self) Returns ``True`` if the timespan is positive. :rtype: `bool` .. method:: IsShorterThan(self, ts) Compares two timespans: works with the absolute values, i.e. 1 hour is shorter than -2 hours. Also, it will return ``False`` if the timespans are equal in absolute value. :param `ts`: :type `ts`: TimeSpan :rtype: `bool` .. staticmethod:: Millisecond() Returns the timespan for one millisecond. :rtype: :ref:`TimeSpan` .. staticmethod:: Milliseconds(ms) Returns the timespan for the given number of milliseconds. :param `ms`: :type `ms`: long :rtype: :ref:`TimeSpan` .. staticmethod:: Minute() Returns the timespan for one minute. :rtype: :ref:`TimeSpan` .. staticmethod:: Minutes(min) Returns the timespan for the given number of minutes. :param `min`: :type `min`: long :rtype: :ref:`TimeSpan` .. method:: Multiply(self, *args, **kw) Multiplies this time span by `n`. :returns: A reference to this :ref:`TimeSpan` object modified in place. .. method:: Neg(self) Negate the value of the timespan. :rtype: :ref:`TimeSpan` .. seealso:: :meth:`Negate` .. method:: Negate(self) Returns timespan with inverted sign. :rtype: :ref:`TimeSpan` .. seealso:: :meth:`Neg` .. staticmethod:: Second() Returns the timespan for one second. :rtype: :ref:`TimeSpan` .. staticmethod:: Seconds(sec) Returns the timespan for the given number of seconds. :param `sec`: :type `sec`: long :rtype: :ref:`TimeSpan` .. method:: Subtract(self, *args, **kw) Subtracts the given :ref:`TimeSpan` to this :ref:`TimeSpan` and returns a reference to itself. .. staticmethod:: Week() Returns the timespan for one week. :rtype: :ref:`TimeSpan` .. staticmethod:: Weeks(weeks) Returns the timespan for the given number of weeks. :param `weeks`: :type `weeks`: long :rtype: :ref:`TimeSpan`