Duration#

class Duration(seconds, nanoseconds=0)#

Bases: object

A nonnegative duration with nanosecond precision.

Construct a duration from seconds and an additional nanosecond count.

Parameters:
  • seconds (int)

    Whole nonnegative seconds.

  • nanoseconds (int)

    Additional nonnegative nanoseconds. Defaults to zero.

Returns:

Duration – Their sum, within the native duration range.

Examples

>>> Duration(1, 500_000_000).as_millis()
1500

Methods

as_millis

Return total whole milliseconds, truncating any smaller unit.

as_nanos

Return total whole nanoseconds, truncating any smaller unit.

as_secs

Return total whole seconds, truncating any smaller unit.

from_millis

Construct a duration from a nonnegative integer count of milliseconds.

from_nanos

Construct a duration from a nonnegative integer count of nanoseconds.

from_secs

Construct a duration from a nonnegative integer count of seconds.

as_millis()#

Return total whole milliseconds, truncating any smaller unit.

as_nanos()#

Return total whole nanoseconds, truncating any smaller unit.

as_secs()#

Return total whole seconds, truncating any smaller unit.

static from_millis(milliseconds)#

Construct a duration from a nonnegative integer count of milliseconds.

static from_nanos(nanoseconds)#

Construct a duration from a nonnegative integer count of nanoseconds.

static from_secs(seconds)#

Construct a duration from a nonnegative integer count of seconds.