Browse Source

add formatElapsedSeconds

David Rose 23 years ago
parent
commit
b747b3133e
1 changed files with 19 additions and 0 deletions
  1. 19 0
      direct/src/showbase/PythonUtil.py

+ 19 - 0
direct/src/showbase/PythonUtil.py

@@ -528,3 +528,22 @@ def lineupPos(i, num, spacing):
     assert i >= 0 and i < num
     assert i >= 0 and i < num
     pos = float(i) * spacing
     pos = float(i) * spacing
     return pos - ((float(spacing) * (num-1))/2.)
     return pos - ((float(spacing) * (num-1))/2.)
+
+def formatElapsedSeconds(seconds):
+    """
+    Returns a string of the form "mm:ss" or "hh:mm:ss" or "n days",
+    representing the indicated elapsed time in seconds.
+    """
+    seconds = (int)(seconds)
+    hours = (int)(seconds / (60 * 60))
+    if hours > 36:
+        days = (int)((hours + 12) / 24)
+        return "%d days" % (days)
+    
+    seconds -= hours * (60 * 60)
+    minutes = (int)(seconds / 60)
+    seconds -= minutes * 60
+    if hours != 0:
+        return "%d:%02d:%02d" % (hours, minutes, seconds)
+    else:
+        return "%d:%02d" % (minutes, seconds)