-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init: Define TimerClass object (iss #16)
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |