mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -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
|
#Python/pyClasses/Stopwatch.py
|
||||||
#Matthew Ellison
|
#Matthew Ellison
|
||||||
# Created: 01-27-19
|
# Created: 01-27-19
|
||||||
#Modified: 08-02-19
|
#Modified: 07-19-20
|
||||||
#This is a class that is used to time program run times
|
#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
|
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
|
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
|
#Returns a string with the result of getTime() at the appropriate resolution
|
||||||
def getString(self):
|
def getString(self):
|
||||||
#Get the time
|
#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
|
#Divide by 1000 until you reach an appropriate resolution or run out of types of seconds
|
||||||
resCnt = 0
|
resCnt = 0
|
||||||
while((time >= 1000) and (resCnt < 3)):
|
while((time >= 1000) and (resCnt < 3)):
|
||||||
@@ -155,12 +173,3 @@ class Stopwatch:
|
|||||||
|
|
||||||
#Return the string
|
#Return the string
|
||||||
return timeString
|
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