def format_relative_datetime(amount: float, unit_key: str) -> str:
    """Generate a human-readable relative time string."""
    # Only show relevant decimal places https://stackoverflow.com/a/51227501
    amount_str = f"{amount:f}".rstrip("0").rstrip(".")
    # Only show the plural s if needed
    unit_str = unit_key if amount != 1.0 else unit_key[:-1]
    return f"{amount_str} {unit_str} ago"