jiaweir
init
21c4e64
raw
history blame
637 Bytes
import time
class Timer:
def __init__(self):
self.start_time = None
self.elapsed = 0
self.paused = False
def start(self):
if self.start_time is None:
self.start_time = time.time()
elif self.paused:
self.start_time = time.time() - self.elapsed
self.paused = False
def pause(self):
if not self.paused:
self.elapsed = time.time() - self.start_time
self.paused = True
def get_elapsed_time(self):
if self.paused:
return self.elapsed
else:
return time.time() - self.start_time