MCPcopy
hub / github.com/pydantic/pydantic / timedelta_isoformat

Function timedelta_isoformat

pydantic/v1/json.py:106–112  ·  view source on GitHub ↗

ISO 8601 encoding for Python timedelta object.

(td: datetime.timedelta)

Source from the content-addressed store, hash-verified

104
105
106def 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'

Callers 2

test_deprecated_moduleFunction · 0.90
test_iso_timedeltaFunction · 0.90

Calls

no outgoing calls

Tested by 2

test_deprecated_moduleFunction · 0.72
test_iso_timedeltaFunction · 0.72