scenario.datetimeutils module

Date/time conversions from timestamp to ISO8601.

Note

This modules intends to centralize date/time conversions from timestamp to ISO8601, which remains a pain in Python. Indeed, full support of timezones with their ‘Zoulou’ or ‘+/-00:00’ forms is not provided by default.

DURATION_REGEX

Regular expression matching a duration as displayed by scenario (i.e. last part of ISO8601).

ISO8601_REGEX

Regular expression matching ISO8601 date/times.

toiso8601(timestamp, timezone=None)

Formats a timestamp to a ISO8601 string.

Parameters:
  • timestamp – Input timestamp.

  • timezone – Optional timezone specification. None stands for the local timezone.

Returns:

ISO8601 string.

Raises:

ValueError – When the operation could not be completed.

fromiso8601(iso8601)

Parses a ISO8601 string in a timestamp.

Parameters:

iso8601 – Input ISO8601 string.

Returns:

Timestamp.

Raises:

ValueError – When the operation could not be completed.

f2strtime(timestamp)

Computes a string representation for the given timestamp.

Parameters:

timestamp – Timestamp to convert.

Returns:

String representation of the timestamp.

f2strduration(duration)

Computes a string representation for a time duration.

Parameters:

duration – Time duration to convert.

Returns:

String representation of the duration.

str2fduration(duration)

Parses a time duration from its string representation as computed by f2strduration().

Parameters:

duration – String representation of the time duration as computed by f2strduration().

Returns:

Time duration.