Skip to content

Commit 2b0d5e2

Browse files
CopilotBeckettFrey
andauthored
fix: readable_from_unique_id handles prefixed IDs from generate_unique_id (#101)
* Initial plan * fix: handle prefixed IDs in readable_from_unique_id Agent-Logs-Url: https://github.com/BrainBehaviorAnalyticsLab/voxkit-desktop/sessions/f6936450-f9a2-4df8-b75a-b403d98db565 Co-authored-by: BeckettFrey <83560790+BeckettFrey@users.noreply.github.com> * fix: raise descriptive ValueError when no timestamp found in readable_from_unique_id Agent-Logs-Url: https://github.com/BrainBehaviorAnalyticsLab/voxkit-desktop/sessions/f6936450-f9a2-4df8-b75a-b403d98db565 Co-authored-by: BeckettFrey <83560790+BeckettFrey@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: BeckettFrey <83560790+BeckettFrey@users.noreply.github.com>
1 parent 58a41f4 commit 2b0d5e2

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/voxkit/storage/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,22 @@ def generate_unique_id(prefix: str | None = None) -> str:
6363
def readable_from_unique_id(date_str: str) -> str:
6464
"""Convert a unique ID timestamp to a human-readable format.
6565
66+
Accepts both plain timestamps (YYYYMMDD_HHMMSS_ffffff) and prefixed IDs
67+
produced by generate_unique_id (e.g. prefix_YYYYMMDD_HHMMSS_ffffff).
68+
6669
Args:
67-
date_str: Timestamp string in format YYYYMMDD_HHMMSS_ffffff
70+
date_str: Unique ID string, optionally prefixed as [prefix_]YYYYMMDD_HHMMSS_ffffff
6871
6972
Returns:
7073
Human-readable date string (e.g., "January 01, 2024 at 12:00:00 PM")
7174
"""
75+
parts = date_str.split("_")
76+
for i, part in enumerate(parts):
77+
if len(part) == 8 and part.isdigit():
78+
date_str = "_".join(parts[i:])
79+
break
80+
else:
81+
raise ValueError(f"No valid timestamp found in unique ID: {date_str!r}")
7282
dt = datetime.strptime(date_str, "%Y%m%d_%H%M%S_%f")
7383
return dt.strftime("%B %d, %Y at %I:%M:%S %p")
7484

tests/storage/test_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,23 @@ def test_readable_from_unique_id_format(self):
185185
assert " at " in readable
186186
# Should contain AM/PM
187187
assert "AM" in readable or "PM" in readable
188+
189+
def test_readable_from_unique_id_with_prefix(self):
190+
"""Test that readable_from_unique_id handles prefixed IDs from generate_unique_id."""
191+
prefixed_id = generate_unique_id(prefix="test")
192+
readable = readable_from_unique_id(prefixed_id)
193+
194+
assert " at " in readable
195+
assert "AM" in readable or "PM" in readable
196+
197+
def test_readable_from_unique_id_roundtrip_with_prefix(self):
198+
"""Test round-trip: a prefixed ID produces the same readable output as unprefixed."""
199+
base_id = "20240115_143022_123456"
200+
prefixed_id = f"myprefix_{base_id}"
201+
202+
assert readable_from_unique_id(base_id) == readable_from_unique_id(prefixed_id)
203+
204+
def test_readable_from_unique_id_invalid_raises(self):
205+
"""Test that an ID with no valid timestamp raises ValueError."""
206+
with pytest.raises(ValueError, match="No valid timestamp found"):
207+
readable_from_unique_id("not_a_timestamp")

0 commit comments

Comments
 (0)