Skip to main content

Duration

A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds.

A Duration represents a difference from one point in time to another. The duration may be "negative" if the difference is from a later time to an earlier.

Properties

  • days - The number of days in the duration.
  • hours - The number of hours in the duration.
  • in_days - Returns total duration in days.
  • in_hours - Returns total duration in hours.
  • in_microseconds - Returns total duration in microseconds.
  • in_milliseconds - Returns total duration in milliseconds.
  • in_minutes - Returns total duration in minutes.
  • in_seconds - Returns total duration in seconds.
  • is_negative - Returns True if duration is negative.
  • microseconds - The number of microseconds in the duration.
  • milliseconds - The number of milliseconds in the duration.
  • minutes - The number of minutes in the duration.
  • seconds - The number of seconds in the duration.

Methods

  • abs - Returns absolute (non-negative) Duration.
  • copy - Returns a copy of this Duration instance with the given fields replaced with the new values.
  • from_unit - Creates a Duration from individual time units.

Properties

daysclass-attributeinstance-attribute

days: int = 0

The number of days in the duration.

hoursclass-attributeinstance-attribute

hours: int = 0

The number of hours in the duration.

in_daysproperty

in_days: int

Returns total duration in days.

in_hoursproperty

in_hours: int

Returns total duration in hours.

in_microsecondsproperty

in_microseconds: int

Returns total duration in microseconds.

in_millisecondsproperty

in_milliseconds: int

Returns total duration in milliseconds.

in_minutesproperty

in_minutes: int

Returns total duration in minutes.

in_secondsproperty

in_seconds: int

Returns total duration in seconds.

is_negativeproperty

is_negative: bool

Returns True if duration is negative.

microsecondsclass-attributeinstance-attribute

microseconds: int = 0

The number of microseconds in the duration.

millisecondsclass-attributeinstance-attribute

milliseconds: int = 0

The number of milliseconds in the duration.

minutesclass-attributeinstance-attribute

minutes: int = 0

The number of minutes in the duration.

secondsclass-attributeinstance-attribute

seconds: int = 0

The number of seconds in the duration.

Methods

abs

abs()

Returns absolute (non-negative) Duration.

copy

copy(microseconds: Optional[int] = None, milliseconds: Optional[int] = None, seconds: Optional[int] = None, minutes: Optional[int] = None, hours: Optional[int] = None, days: Optional[int] = None)

Returns a copy of this Duration instance with the given fields replaced with the new values.

from_unitclassmethod

from_unit(cls, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0, milliseconds: int = 0, microseconds: int = 0)

Creates a Duration from individual time units.