import time


class Timer(object):

    def __init__(self):
        self.reset()

    def reset(self):
        self.t_start = 0.
        self.t_elapsed = {'hrs': 0., 'min': 0., 'sec': 0.}

    def start(self):
        self.reset()
        self.t_start = time.time()

    def stop(self):
        if not self.t_start:
            return
        t_elapsed = time.time() - self.t_start
        t_min, t_sec = divmod(t_elapsed, 60)
        t_hrs, t_min = divmod(t_min, 60)
        self.t_elapsed = {'hrs': t_hrs, 'min': t_min, 'sec': t_sec}

    def elapsed(self):
        return self.t_elapsed

    def __str__(self):
        t_hrs = int(self.t_elapsed['hrs'])
        t_min = int(self.t_elapsed['min'])
        t_sec = self.t_elapsed['sec']
        return '{0} hrs {1} min {2:.2f} sec'.format(t_hrs, t_min, t_sec)
