def hhmmss(seconds, rounded=False):
    """formats a time in seconds as hh:mm:ss"""
    if rounded:
        seconds = int(seconds + 0.5)
    sign = ''
    if seconds < 0:
        seconds, sign = -seconds, '-'
    m = int(seconds // 60)
    return '{3}{0:02d}:{1:02d}:{2:02d}'.format(int(m // 60), m % 60, int(
        seconds - 60 * m), sign)
