#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: ./nb/timer.ipynb
import sys
if __name__ == '__main__': sys.path.append('..')
import xs_lib.common as common

from datetime import datetime
import time
import sys
def now():return datetime.now()
def now_s():
    s = datetime.now().isoformat()
    return s[:s.index('.')]

def timer(slient_mode = False):
    """
    Usage:
    time = iter(timer())
    next(time) # print
    # do something
    next(time) # print
    printing as spliter
    generator, returns (current_timestamp as datetime.datetime, current_timestamp - last_timestamp as datetime.timedelta)
    datetime.datetime, datetime.timedelta can be by str()
    datetime.timedelta can be add by
    """
    pf = print
    def empty_func(*args):
        pass
    pf = empty_func if slient_mode else print

    def split_by_time(*args):
        pf("-"*60 , now_s(), *args)

    split_by_time()
    t1 = now()
    yield t1, t1 - t1

    while True:
        t2 = now()
        split_by_time( "total " + (t2 - t1).__str__() + " spent")
        yield t2, t2 - t1
        t1 = t2

from time import sleep