Skip to content

Commit

Permalink
init: Define TimerClass object (iss #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochun committed Mar 17, 2020
1 parent b3a6cd5 commit 5f0353b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions DataRepository_patrons/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
__version__ = "0.6.0"


class TimerClass(object):
"""
Purpose:
Define timer object that records elapsed time
Initiate:
timer = TimerClass()
timer._start()
Stop
timer._stop()
Get information:
timer.format
Attributes
----------
start : datetime object
Starting value for timer
stop : datetime object
Stopping value for timer
delta : datetime object
Time difference
"""

from datetime import datetime as dt

def __init__(self):
self.start = 0
self.stop = 0
self.delta = 0
self.format = ""

def _start(self):
self.start = self.dt.now()

def _stop(self):
self.stop = self.dt.now()
self.delta = self.stop - self.start
sec = self.delta.seconds + self.delta.microseconds / 1e6
HH = int(sec // 3600)
MM = int((sec // 60) - (HH * 60))
SS = sec - (HH * 3600) - (MM * 60)
self.format = "Total time: {0: 02d} hours {1: 02d} minutes {2: .2f} seconds".format(HH, MM, SS)

0 comments on commit 5f0353b

Please sign in to comment.