roboto.time#
Module Contents#
- roboto.time.MAX_32BIT_EPOCH_SECONDS = 2147483647#
- roboto.time.NSEC_PER_MS = 1000000#
- roboto.time.NSEC_PER_SEC = 1000000000#
- roboto.time.NSEC_PER_US = 1000#
- type roboto.time.Time = Union[int, float, decimal.Decimal, str, datetime.datetime]#
- class roboto.time.TimeUnit#
Bases:
str
,enum.Enum
Well-known time units supported for timestamps in recording data.
- Microseconds = 'us'#
- Milliseconds = 'ms'#
- Nanoseconds = 'ns'#
- Seconds = 's'#
- nano_multiplier()#
- Return type:
int
- roboto.time.log#
- roboto.time.to_epoch_nanoseconds(value, unit=None)#
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
formattedvalue
:If not provided,
unit
defaults toNanoseconds
.
float
formattedvalue
:Not recommended due to potential for precision loss. If possible, pass
value
asstr
ordecimal.Decimal
instead.If not provided,
unit
defaults toSeconds
.
decimal.Decimal
formattedvalue
:If not provided,
unit
defaults toSeconds
.E.g., a ROS formatted timestamp in the form of decimal.Decimal(“<sec>.<nsec>”)).
str
formattedvalue
:If not provided,
unit
defaults toSeconds
.E.g., a ROS formatted timestamp in the form of “<sec>.<nsec>”).
datetime.datetime
formattedvalue
:unit
, if provided, is ignored. Datetimes are always converted from seconds to nanoseconds.
- Parameters:
value (Time)
unit (Optional[TimeUnit])
- roboto.time.utcnow()#
Return timezone aware datetime.datetime object, now in UTC.
- Return type:
datetime.datetime