Commits

Anonymous committed a873e56

Downgrade properties to allow older python to work.

  • Participants
  • Parent commits d0b1e09

Comments (0)

Files changed (1)

stopwatch/stopwatch/__init__.py

 
 import time
 
-"""Simple timer.  Great for finding out how long code takes to execute.
+"""stopwatch is a very simple python module for measuring time.
+Great for finding out how long code takes to execute.
 
 >>> import stopwatch
 >>> t = stopwatch.Timer()
 >>> print t
 """
 
-__version__ = '0.2.0'
+__version__ = '0.3.0'
+__author__ = 'John Paulett <http://blog.7oars.com>'
 
 class Timer(object):
     def __init__(self):
         self.__stopped = None
-        self.__start = time.time()
+        self.__start = self.__time()
   
     def stop(self):
-        self.__stopped = self.__time()
+        """Stops the clock permanently for the instance of the Timer.
+        Returns the time at which the instance was stopped.
+        """
+        self.__stopped = self.__last_time()
         return self.elapsed
 
-    @property
     def elapsed(self):
-        return self.__time() - self.__start
-        
-    def __time(self):
+        """The number of seconds since the current time that the Timer
+        object was created.  If stop() was called, it is the number
+        of seconds from the instance creation until stop() was called.
+        """
+        return self.__last_time() - self.__start
+    elapsed = property(elapsed)
+    
+    def start_time(self):
+        """The time at which the Timer instance was created.
+        """
+        return self.__start
+    start_time = property(start_time)
+    
+    def stop_time(self):
+        """The time at which stop() was called, or None if stop was 
+        never called.
+        """
+        return self.__stopped 
+    stop_time = property(stop_time)        
+    
+    def __last_time(self):
+        """Return the current time or the time at which stop() was call,
+        if called at all.
+        """
         if self.__stopped is not None:
             return self.__stopped
+        return self.__time()
+    
+    def __time(self):
+        """Wrapper for time.time() to allow unit testing.
+        """
         return time.time()
     
     def __str__(self):
+        """Nicely format the elapsed time
+        """
         return str(self.elapsed) + ' sec'