Skip to content

Commit db0e0ab

Browse files
mrveissclaude
andauthored
docs(shared): document UTC-format selection rule in autobot_shared.time_utils (#5169 part A) (#5176)
Adds a module docstring with a clear selection rule for picking between utc_timestamp() (default for new code, +00:00 with microseconds) and utc_timestamp_z() (legacy compatibility only, Z-suffix, second precision). Each function docstring now cross-references the module rule. Body changes: none — docstrings only. Both helpers retain byte-identical output. Verified via: python3 -c "from autobot_shared.time_utils import utc_timestamp, utc_timestamp_z; print(utc_timestamp(), '|', utc_timestamp_z())" -> 2026-04-18T20:36:03.523477+00:00 | 2026-04-18T20:36:03Z Part A of #5169. Parts B (parser audit) and C (canonicalization ADR) deferred to follow-up — issue stays OPEN. Refs #5169 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3eb0fca commit db0e0ab

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

autobot_shared/time_utils.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
1-
"""Shared time utility helpers."""
1+
"""Shared UTC timestamp helpers.
2+
3+
This module exposes two helpers for producing the current UTC time as an
4+
ISO-8601 string. They differ in *output format*; the choice between them
5+
is dictated by what consumers can parse, not by author preference.
6+
7+
Selection rule (#5106, #5152, #5169)
8+
------------------------------------
9+
10+
``utc_timestamp()`` — **default for new code.**
11+
Returns ``+00:00`` ISO-8601 with microseconds
12+
(e.g. ``2026-04-18T19:34:50.123456+00:00``). Use this unless you are
13+
reading or writing a stored format that explicitly expects ``Z``.
14+
15+
``utc_timestamp_z()`` — **legacy compatibility only.**
16+
Returns ``Z``-suffix ISO-8601 with second precision and no
17+
microseconds (e.g. ``2026-04-18T19:34:50Z``). Use ONLY when reading
18+
or writing existing on-disk records that already use this format
19+
(currently: workflow-version records via
20+
``services/workflow_versioning.py``). **Do not use for new
21+
producers** — pick ``utc_timestamp()`` instead so the codebase
22+
converges on one canonical format.
23+
24+
Long-term canonicalization (#5169 parts B + C) is deferred pending a
25+
parser audit; until then both formats coexist and the rule above tells
26+
new code which to pick.
27+
"""
228
import time
329
from datetime import datetime, timezone
430

531

632
def utc_timestamp() -> str:
7-
"""Return the current time as an ISO-8601 UTC timestamp string."""
33+
"""Return current UTC time as ISO-8601 with ``+00:00`` offset.
34+
35+
Format: ``YYYY-MM-DDTHH:MM:SS.ffffff+00:00`` (microsecond precision).
36+
Default helper for new code — see module docstring for selection rule.
37+
"""
838
return datetime.now(timezone.utc).isoformat()
939

1040

1141
def utc_timestamp_z() -> str:
12-
"""Return current UTC time as an ISO-8601 string with Z suffix.
42+
"""Return current UTC time as ISO-8601 with ``Z`` suffix.
43+
44+
Format: ``YYYY-MM-DDTHH:MM:SSZ`` (exactly 20 chars, second precision,
45+
no microseconds, no ``+00:00`` offset). Matches the on-disk format
46+
used by workflow_versioning records.
1347
14-
Produces exactly 20 characters in the form ``YYYY-MM-DDTHH:MM:SSZ``
15-
with no microseconds and no ``+00:00`` offset — matching the on-disk
16-
format used by workflow_versioning records (#5152).
48+
Use ONLY for legacy compatibility — see module docstring for
49+
selection rule. Picking this for new producers perpetuates format
50+
drift (#5106, #5152, #5169).
1751
"""
1852
t = time.gmtime()
1953
return (

0 commit comments

Comments
 (0)