timeutils.timespan module

TimeSpan

class timeutils.timespan.TimeSpan[source]

Bases: datetime.timedelta

Represents a time span.

All arguments are optional and default to 0. Arguments may be integers or floats, and may be positive or negative.

As in the base datetime.timedelta class, only days, seconds and microseconds are stored internally. Arguments are converted to those units:

  • A millisecond is converted to 1000 microseconds.
  • A minute is converted to 60 seconds.
  • An hour is converted to 3600 seconds.

and days, seconds and microseconds are then normalized so that the representation is unique.

If any argument is a float and there are fractional microseconds, the fractional microseconds left over from all arguments are combined and their sum is rounded to the nearest microsecond using round-half-to-even tiebreaker.

Parameters:
  • seconds (float,optional) – number of seconds in the time span.
  • microseconds (float,optional) – number of microseconds in the time span.
  • milliseconds (float,optional) – number of milliseconds in the time span.
  • minutes (float,optional) – number of minutes in the time span.
  • hours (float,optional) – number of hours in the time span.
  • days (float,optional) – number of days in the time span.
__str__
days

Number of days.

human_str(trim_zeros=True)[source]

Returns a human-readable TimeSpan object, represented as time units such as days, hours, minutes, and seconds.

Parameters:trim_zeros (bool,optional) – indicates whether the leading zeros in the result should be skipped
Returns:human-readable time span
Return type:str
microseconds

Number of microseconds (>= 0 and less than 1 second).

seconds

Number of seconds (>= 0 and less than 1 day).

total_hours()[source]

Total hours in the duration.

total_milliseconds()[source]

Total milliseconds in the duration.

total_minutes()[source]

Total minutes in the duration.

total_seconds()

Total seconds in the duration.