Skip to content

Duration

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.

days #

days: int = 0

The number of days in the duration.

hours #

hours: int = 0

The number of hours in the duration.

in_days #

in_days: int

Returns total duration in days.

in_hours #

in_hours: int

Returns total duration in hours.

in_microseconds #

in_microseconds: int

Returns total duration in microseconds.

in_milliseconds #

in_milliseconds: int

Returns total duration in milliseconds.

in_minutes #

in_minutes: int

Returns total duration in minutes.

in_seconds #

in_seconds: int

Returns total duration in seconds.

is_negative #

is_negative: bool

Returns True if duration is negative.

microseconds #

microseconds: int = 0

The number of microseconds in the duration.

milliseconds #

milliseconds: int = 0

The number of milliseconds in the duration.

minutes #

minutes: int = 0

The number of minutes in the duration.

seconds #

seconds: int = 0

The number of seconds in the duration.

abs #

abs() -> Duration

Returns absolute (non-negative) Duration.

copy_with #

copy_with(
    *,
    microseconds: int | None = None,
    milliseconds: int | None = None,
    seconds: int | None = None,
    minutes: int | None = None,
    hours: int | None = None,
    days: int | None = None,
) -> Duration

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

from_unit #

from_unit(
    *,
    days: int = 0,
    hours: int = 0,
    minutes: int = 0,
    seconds: int = 0,
    milliseconds: int = 0,
    microseconds: int = 0,
) -> Duration

Creates a Duration from individual time units.