def _format_duration(duration):
    """Formats a duration."""
    duration = int(1000 * duration)
    duration, ms = divmod(duration, 1000)
    duration, s = divmod(duration, 60)
    h, m = divmod(duration, 60)
    return "{:d}:{:02d}:{:02d}.{:03d}".format(h, m, s, ms)