import time


def timestamp(at=None, d=True, t=True, tz=True, utc=False, winsafe=False,
              t_sep='T'):
    """Simple utility to print out a time, date, or time & date stamp,
    with some reconfigurability for commonly-used options.

    Default is in ISO8601 format in local time. Use winsafe mode to remove
    colons separating hours, min, and sec to avoid file naming issues.

    Parameters
    ----------
    at : None or int
        Time in seconds for which to get the timestamp. If None, current time
        is used.
    d
        print date (default: True)
    t
        print time (default: True)
    tz
        print timezone offset from UTC (default: True)
    utc
        print time/date in UTC (default: False)
    winsafe
        omit colons between hours/minutes (default: False)
    t_sep
        Separator between date and time (default: "T")

    """
    if at is None:
        at = time.time()

    if utc:
        timeTuple = time.gmtime(at)
    else:
        timeTuple = time.localtime(at)

    dts = ""
    if d:
        dts += time.strftime("%Y-%m-%d", timeTuple)
        if t:
            dts += t_sep
    if t:
        if winsafe:
            dts += time.strftime("%H%M%S", timeTuple)
        else:
            dts += time.strftime("%H:%M:%S", timeTuple)

        if tz:
            if utc:
                if winsafe:
                    dts += time.strftime("+0000")
                else:
                    dts += time.strftime("+00:00")
            else:
                offset = time.strftime("%z")
                if not winsafe:
                    offset = offset[:-2] + ":" + offset[-2:]
                dts += offset
    return dts