esptest.common.timestamp module
- esptest.common.timestamp.timestamp_str(fmt='', dt=None)[source]
Generates a timestamp string from datetime
- esptest.common.timestamp.timestamp_iso(dt=None)[source]
Generates a timezone-aware ISO 8601 timestamp string.
Unlike timestamp_str, the result always includes a timezone offset, e.g. ‘2026-07-08T12:32:00.123456+0800’.
- Parameters:
dt (datetime, optional) – datetime to convert. Naive datetimes are assumed to be in the local timezone. Defaults to datetime.now().
- Returns:
ISO 8601 timestamp string with microseconds and timezone offset
- Return type:
- esptest.common.timestamp.parse_timestamp(text, fmt='')[source]
Parses a timestamp string into a datetime.
Inverse of timestamp_str. When
fmtis omitted, a set of common formats is tried automatically, covering bothTand space separators, with or without microseconds, and with or without a timezone offset (+0800,+08:00orZ). Timezone-aware candidates are tried first, so the offset is preserved whenever the input carries one.- Parameters:
- Returns:
the parsed datetime object.
- Return type:
datetime
- Raises:
ValueError – if the string does not match any known format.