mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 10:23:57 -05:00
Added functions to reset and get time from duration
This commit is contained in:
33
Stopwatch.py
33
Stopwatch.py
@@ -1,10 +1,10 @@
|
||||
#Python/pyClasses/Stopwatch.py
|
||||
#Matthew Ellison
|
||||
# Created: 01-27-19
|
||||
#Modified: 08-02-19
|
||||
#Modified: 07-19-20
|
||||
#This is a class that is used to time program run times
|
||||
"""
|
||||
Copyright (C) 2019 Matthew Ellison
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -107,8 +107,26 @@ class Stopwatch:
|
||||
#Returns a string with the result of getTime() at the appropriate resolution
|
||||
def getString(self):
|
||||
#Get the time
|
||||
time = self.getTime()
|
||||
return Stopwatch.getStr(self.getTime())
|
||||
|
||||
#Reset the timer so it can be used again
|
||||
def reset(self):
|
||||
self.timeStarted = 0.0
|
||||
self.timeStopped = 0.0
|
||||
self.started = False
|
||||
self.finished = False
|
||||
|
||||
def __str__(self):
|
||||
return self.getString()
|
||||
|
||||
def __add__(self, other):
|
||||
return self.getString() + other
|
||||
|
||||
def __radd__(self, other):
|
||||
return other + self.getString()
|
||||
|
||||
@staticmethod
|
||||
def getStr(time: float) -> str:
|
||||
#Divide by 1000 until you reach an appropriate resolution or run out of types of seconds
|
||||
resCnt = 0
|
||||
while((time >= 1000) and (resCnt < 3)):
|
||||
@@ -155,12 +173,3 @@ class Stopwatch:
|
||||
|
||||
#Return the string
|
||||
return timeString
|
||||
|
||||
def __str__(self):
|
||||
return self.getString()
|
||||
|
||||
def __add__(self, other):
|
||||
return self.getString() + other
|
||||
|
||||
def __radd__(self, other):
|
||||
return other + self.getString()
|
||||
|
||||
Reference in New Issue
Block a user