xecs.Duration#

class xecs.Duration#

Bases: object

Represents a span of time.

Methods

as_micros

Return the total number of whole microseconds in this duration.

as_millis

Return the total number of whole milliseconds in this duration.

as_nanos

Return the total number of whole nanoseconds in this duration.

as_secs

Return the total number of whole seconds in the duration.

checked_add

Add a duration inplace.

checked_div

Divide a duration inplace.

checked_mul

Multiply a duration inplace.

checked_sub

Subtract a duration inplace.

from_micros

Create a new duration from a specified number of microseconds.

from_millis

Create a new duration from a specified number of milliseconds.

from_nanos

Create a new duration from a specified number of nanoseconds.

is_zero

Return True if the duration spans no time.

new

Create a new duration.

saturating_sub

Subtract a duration.

subsec_micros

Return the fractional part of this duration, in whole microseconds.

subsec_nanos

Return the fractional part of this duration, in whole nanoseconds.

as_micros()#

Return the total number of whole microseconds in this duration.

Returns:

The number of whole microseconds.

Return type:

int

as_millis()#

Return the total number of whole milliseconds in this duration.

Returns:

The number of whole milliseconds.

Return type:

int

as_nanos()#

Return the total number of whole nanoseconds in this duration.

Returns:

The number of whole nanoseconds.

Return type:

int

as_secs()#

Return the total number of whole seconds in the duration.

Returns:

The total number of whole seconds.

Return type:

int

checked_add(rhs)#

Add a duration inplace.

Parameters:

rhs (Duration) – The other duration.

checked_div(rhs)#

Divide a duration inplace.

Parameters:

rhs (Duration) – The other duration.

checked_mul(rhs)#

Multiply a duration inplace.

Parameters:

rhs (Duration) – The other duration.

checked_sub(rhs)#

Subtract a duration inplace.

Parameters:

rhs (Duration) – The other duration.

static from_micros(micros)#

Create a new duration from a specified number of microseconds.

Parameters:

micros (int) – The number of microseconds.

Returns:

The duration.

Return type:

Duration

static from_millis(millis)#

Create a new duration from a specified number of milliseconds.

Parameters:

millis (int) – The number of milliseconds.

Returns:

The duration.

Return type:

Duration

static from_nanos(nanos)#

Create a new duration from a specified number of nanoseconds.

Parameters:

nanos (int) – The number of nanoseconds.

Returns:

The duration.

Return type:

Duration

is_zero()#

Return True if the duration spans no time.

Returns:

Whether the duration spans any time or not.

Return type:

bool

static new(secs, nanos)#

Create a new duration.

Parameters:
  • secs (int) – The number of whole seconds.

  • nanos (int) – The number of additional nanoseconds.

Returns:

The duration.

Return type:

Duration

saturating_sub(rhs)#

Subtract a duration.

Parameters:

rhs (Duration) – The other duration.

Returns:

The new duration. Zero if the result would have been negative

Return type:

Duration

subsec_micros()#

Return the fractional part of this duration, in whole microseconds.

This method does not return the lenght of the duration when represented by microseconds. The returned number always represents a fractional portion of a second.

Returns:

The subsecond microseconds in the duration.

Return type:

int

subsec_nanos()#

Return the fractional part of this duration, in whole nanoseconds.

This method does not return the lenght of the duration when represented by nanoseconds. The returned number always represents a fractional portion of a second.

Returns:

The subsecond nanoseconds in the duration.

Return type:

int