yera.ui.utils

Utility functions for the local UI server.

Symbols

def fmt_relative — Formats a timestamp as a compact relative label for session rows.

fmt_relative

fmt_relative(
    t: datetime,
    now: datetime | None = None,
) → str

Formats a timestamp as a compact relative label for session rows.

Buckets match the sidebar design: minutes within the last hour, hours within the last day, a lowercase weekday within the last week, then an abbreviated mon d date. Names come from fixed English tables so output is stable regardless of the server's locale.

Parameters

t
type: datetime

Timestamp to format. Coerced to UTC if naive (see below).

now
type: datetime | None = None

Reference time, for testing. Defaults to datetime.now(UTC).

Returns

type: str

A lowercase relative-time string such as "5m ago", "2h ago", "tue", or "jun 30".