esptest.common.timestamp module

esptest.common.timestamp.timestamp_str(fmt='', dt=None)[source]

Generates a timestamp string from datetime

Parameters:
  • fmt (str, optional) – time stamp format. Defaults to ‘%Y-%m-%dT%H:%M:%S.%f’, follow ISO 8601 Formats.

  • dt (datetime, optional) – convert specific datetime to string. Defaults to datatime.now().

Returns:

time stamp string

Return type:

str

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:

str

esptest.common.timestamp.parse_timestamp(text, fmt='')[source]

Parses a timestamp string into a datetime.

Inverse of timestamp_str. When fmt is omitted, a set of common formats is tried automatically, covering both T and space separators, with or without microseconds, and with or without a timezone offset (+0800, +08:00 or Z). Timezone-aware candidates are tried first, so the offset is preserved whenever the input carries one.

Parameters:
  • text (str) – the timestamp string to parse.

  • fmt (str, optional) – explicit strptime format. When given, only this format is used. Defaults to auto-detection.

Returns:

the parsed datetime object.

Return type:

datetime

Raises:

ValueError – if the string does not match any known format.

esptest.common.timestamp.timestamp_slug(fmt='', dt=None)[source]

Similar to timestamp_str but only include [0-9a-zA-Z_-].

Returns:

time stamp string

Return type:

str

Parameters: