Skip to main content

duration_iso_string

Converts a timedelta object into an ISO 8601 formatted duration string, handling both positive and negative durations.

def duration_iso_string(
duration: datetime.timedelta
) - > string

Converts a timedelta object into an ISO 8601 formatted duration string, handling both positive and negative time offsets.

Parameters

NameTypeDescription
durationdatetime.timedeltaThe timedelta object representing the time span to be formatted.

Returns

TypeDescription
stringThe ISO 8601 duration representation (e.g., 'P1DT02H30M00S') including a leading sign for negative durations.