From adf0a78ab6d8c41373d0514d8d4c3474e39171e4 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Sun, 19 Jul 2020 15:32:32 -0400 Subject: [PATCH] Added functions to reset and get time from duration --- Stopwatch.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/Stopwatch.py b/Stopwatch.py index a9b7b49..80fb849 100644 --- a/Stopwatch.py +++ b/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()