import re
import click
import time


def increment_time(time_str, offset):
    """increment hhmmss by offset seconds"""
    m = re.match(r'^(\d{2})(\d{2})(\d{2})$', time_str)
    if not m:
        click.echo("can't extract h:m:s from time str: {}".format(time_str))
        return
    h, m, s = m.group(1), m.group(2), m.group(3)
    sec = int(h) * 3600 + int(m) * 60 + int(s)  # convert to total seconds
    sec += offset
    if sec < 0:
        # sanity check to make sure sec is not negative
        # if negative we need to tweak the date, ignore for now
        click.echo("negative time is not yet supported")
        return

    return time.strftime('%H%M%S', time.gmtime(sec))