import time


def format_time(parts, compact=False):
    """
    Format a split-up message ID to a timestamp string

    If compact is true, an alternate slightly shorter representation
    without whitespace is emitted. Both compact and "long" forms have
    a fixed width, and are recognized by parse_time().
    """
    sec, ms, seq = parts
    if compact:
        return '%s.%03d#%04d' % (time.strftime('%Y-%m-%d_%H:%M:%S',
            time.gmtime(sec)), ms, seq)
    else:
        return '%s.%03d Z, #%04d' % (time.strftime('%Y-%m-%d %H:%M:%S',
            time.gmtime(sec)), ms, seq)