예제 #1
0
def pretty_time(delta: dt.timedelta) -> str:
    """
    Args:
        delta: a delta between two dt.datetime objects

    Returns:
        a pretty string of the time delta
    """
    delta = str(delta)

    if delta.startswith("0:00:00."):
        delta_us = int(delta.split(".")[1])
        delta_ms = int(delta_us / 1000)

        if delta_ms >= 500:
            return f"\033[91m{delta_ms}ms\033[0m"
        else:
            return f"{delta_ms}ms"

    elif delta.startswith("0:00:01."):
        delta_us = int(delta.split(".")[1])
        delta_ms = 1000 + int(delta_us / 1000)
        return f"\033[91m{delta_ms}ms\033[0m"

    else:
        return f"\033[91m{delta_ms}\033[0m"
예제 #2
0
        def str_timedelta(td: timedelta) -> str:
            td = str(td)

            # Remove ms
            # 0:01:40.123000 -> 0:01:40
            if '.' in td:
                td = td[:td.rindex('.')]

            # 0:01:40 -> 00:01:40
            if td.startswith('0:'):
                td = '00:' + td[2:]

            return td