-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions
35 lines (28 loc) · 997 Bytes
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Timer():
'''A timer used to record how long a process takes.
After instaniating, a .start() and .stop() can be used
before and after a process in respective order.'''## def init
def __init__(self,format_="%m/%d/%y - %I:%M %p"):
import tzlocal
self.tz = tzlocal.get_localzone()
self.fmt = format_
self.created_at = self.get_time()# get time
## def get time method
def get_time(self):
import datetime as dt
return dt.datetime.now(self.tz)
## def start
def start(self):
time = self.get_time()
self.start = time
print(f"[i] Timer started at{self.start.strftime(self.fmt)}")
## def stop
def stop(self):
time = self.get_time()
self.end = time
print(f"[i] Timer ended at {self.end.strftime(self.fmt)}")
print(f"- Total time = {self.end-self.start}")
timer = Timer()
print(timer.created_at)
timer.start()
timer.stop()