def format_timedelta(td):
    """Format td in seconds to HHH:MM:SS."""
    td = int(td)
    hours, remainder = divmod(td, 3600)
    minutes, seconds = divmod(remainder, 60)
    return '{:03}:{:02}:{:02}'.format(hours, minutes, seconds)