roboto.time
Module Contents
MAX_32BIT_EPOCH_SECONDS
NSEC_PER_MS
NSEC_PER_SEC
NSEC_PER_US
Time
TimeUnit
Bases: roboto.compat.StrEnum
Well-known time units supported for timestamps in recording data.
TimeUnit.nano_multiplier()
Return type
log
to_epoch_nanoseconds()
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
-
intformattedvalue:- If not provided,
unitdefaults toNanoseconds. - Any integer type is accepted, such as a
numpy.int64read out of a pandas or numpy column. - A
boolis refused: it is anintin Python, andTruewould otherwise read as 1.
- If not provided,
-
floatformattedvalue:- Not recommended due to potential for precision loss. If possible, pass
valueasstrordecimal.Decimalinstead. - If not provided,
unitdefaults toSeconds.
- Not recommended due to potential for precision loss. If possible, pass
-
decimal.Decimalformattedvalue:- If not provided,
unitdefaults toSeconds. - E.g., a ROS formatted timestamp in the form of decimal.Decimal(“<sec>.<nsec>”)).
- If not provided,
-
strformattedvalue:- If not provided,
unitdefaults toSeconds. - 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 viadatetime.datetime.fromisoformat()and treated as thedatetimebranch below. Theunitargument is ignored for ISO8601 input.
- If not provided,
-
datetime.datetimeformattedvalue:unit, if provided, is ignored. Datetimes are always converted from seconds to nanoseconds.- A datetime before 1970 converts to a negative number of nanoseconds.
Raises
TypeErrorvalue is not one of the types above.
ValueErrorvalue 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.
OverflowErrorvalue is an infinite float, Decimal, or string, such as "inf".
utcnow()
Return timezone aware datetime.datetime object, now in UTC.
Return type