Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

roboto.time

Module Contents

MAX_32BIT_EPOCH_SECONDS

roboto.time.MAX_32BIT_EPOCH_SECONDS = 2147483647#View Source

NSEC_PER_MS

roboto.time.NSEC_PER_MS = 1000000#View Source

NSEC_PER_SEC

roboto.time.NSEC_PER_SEC = 1000000000#View Source

NSEC_PER_US

roboto.time.NSEC_PER_US = 1000#View Source

Time

type roboto.time.Time = typing.Union[int, float, decimal.Decimal, str, datetime.datetime]#View Source

TimeUnit

class roboto.time.TimeUnit#View Source

Bases: roboto.compat.StrEnum

Well-known time units supported for timestamps in recording data.

Attributes

TimeUnit.Microseconds

Microseconds = 'us' #

TimeUnit.Milliseconds

Milliseconds = 'ms' #

TimeUnit.Nanoseconds

Nanoseconds = 'ns' #

TimeUnit.Seconds

Seconds = 's' #

TimeUnit.nano_multiplier()

nano_multiplier()#View Source

Return type

int

log

roboto.time.log#View Source

to_epoch_nanoseconds()

roboto.time.to_epoch_nanoseconds(value, unit=None)#View Source

Convert a time value to nanoseconds since Unix epoch (1970-01-01 00:00:00 UTC). Accepts various input formats (int, float, Decimal, str, datetime) and time units (seconds, milliseconds, microseconds, nanoseconds).

Notes

  • int formatted value:

    • If not provided, unit defaults to Nanoseconds.
    • Any integer type is accepted, such as a numpy.int64 read out of a pandas or numpy column.
    • A bool is refused: it is an int in Python, and True would otherwise read as 1.
  • float formatted value:

    • Not recommended due to potential for precision loss. If possible, pass value as str or decimal.Decimal instead.
    • If not provided, unit defaults to Seconds.
  • decimal.Decimal formatted value:

    • If not provided, unit defaults to Seconds.
    • E.g., a ROS formatted timestamp in the form of decimal.Decimal(“<sec>.<nsec>”)).
  • str formatted value:

    • If not provided, unit defaults to Seconds.
    • E.g., a ROS formatted timestamp in the form of “<sec>.<nsec>”).
    • ISO8601 timestamp strings (e.g. "2024-05-16T10:25:47Z") are also accepted; they are parsed via datetime.datetime.fromisoformat() and treated as the datetime branch below. The unit argument is ignored for ISO8601 input.
  • datetime.datetime formatted value:

    • unit, if provided, is ignored. Datetimes are always converted from seconds to nanoseconds.
    • A datetime before 1970 converts to a negative number of nanoseconds.

Parameters

value Time
unit Optional[TimeUnit]

Raises

TypeError

value is not one of the types above.

ValueError

value is a boolean, a negative int, float, Decimal, or numeric string, or a string that is neither a number of seconds nor an ISO 8601 timestamp.

OverflowError

value is an infinite float, Decimal, or string, such as "inf".

utcnow()

roboto.time.utcnow()#View Source

Return timezone aware datetime.datetime object, now in UTC.

Return type

datetime.datetime

Was this page helpful?