MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / relative_time

Function relative_time

openkb/agent/chat_session.py:255–271  ·  view source on GitHub ↗

Render an ISO-8601 timestamp as a short relative string.

(iso_str: str)

Source from the content-addressed store, hash-verified

253
254
255def relative_time(iso_str: str) -> str:
256 """Render an ISO-8601 timestamp as a short relative string."""
257 try:
258 t = datetime.strptime(iso_str, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
259 except (ValueError, TypeError):
260 return iso_str or ""
261 now = datetime.now(timezone.utc)
262 seconds = int((now - t).total_seconds())
263 if seconds < 60:
264 return "just now"
265 if seconds < 3600:
266 return f"{seconds // 60}m ago"
267 if seconds < 86400:
268 return f"{seconds // 3600}h ago"
269 if seconds < 86400 * 7:
270 return f"{seconds // 86400}d ago"
271 return t.strftime("%Y-%m-%d")

Callers 1

chatFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected