ISO 8601 encoding for Python timedelta object.
(td: datetime.timedelta)
| 104 | |
| 105 | |
| 106 | def timedelta_isoformat(td: datetime.timedelta) -> str: |
| 107 | """ |
| 108 | ISO 8601 encoding for Python timedelta object. |
| 109 | """ |
| 110 | minutes, seconds = divmod(td.seconds, 60) |
| 111 | hours, minutes = divmod(minutes, 60) |
| 112 | return f'{"-" if td.days < 0 else ""}P{abs(td.days)}DT{hours:d}H{minutes:d}M{seconds:d}.{td.microseconds:06d}S' |
no outgoing calls