def format_duration(seconds):
    """Format a duration as ``[hours:]minutes:seconds``.

    Parameters
    ----------
    seconds : int
        Duration in seconds.

    Returns
    -------
    str
    """
    minutes, seconds = divmod(seconds, 60)
    hours, minutes = divmod(minutes, 60)

    if hours > 0:
        return "{}:{:02d}:{:02d}".format(hours, minutes, seconds)
    else:
        return "{}:{:02d}".format(minutes, seconds)