Browse Source

added formatTimeCompact

Darren Ranalli 17 years ago
parent
commit
ad5749c61e
1 changed files with 21 additions and 1 deletions
  1. 21 1
      direct/src/showbase/PythonUtil.py

+ 21 - 1
direct/src/showbase/PythonUtil.py

@@ -29,7 +29,7 @@ __all__ = ['enumerate', 'unique', 'indent', 'nonRepeatingRandomList',
 'GoldenRectangle', 'pivotScalar', 'rad90', 'rad180', 'rad270', 'rad360',
 'GoldenRectangle', 'pivotScalar', 'rad90', 'rad180', 'rad270', 'rad360',
 'nullGen', 'loopGen', 'makeFlywheelGen', 'flywheel', 'choice',
 'nullGen', 'loopGen', 'makeFlywheelGen', 'flywheel', 'choice',
 'printStack', 'printReverseStack', 'listToIndex2item', 'listToItem2index',
 'printStack', 'printReverseStack', 'listToIndex2item', 'listToItem2index',
-'pandaBreak','pandaTrace']
+'pandaBreak','pandaTrace','formatTimeCompact']
 
 
 import types
 import types
 import string
 import string
@@ -3315,6 +3315,26 @@ def recordFunctorCreationStacks():
             Functor._functorCreationStacksRecorded = True
             Functor._functorCreationStacksRecorded = True
             Functor.__call__ = Functor._exceptionLoggedCreationStack__call__
             Functor.__call__ = Functor._exceptionLoggedCreationStack__call__
 
 
+def formatTimeCompact(seconds):
+    # returns string in format '1d3h22m43s'
+    result = ''
+    a = int(seconds)
+    seconds = a % 60
+    a /= 60
+    if a > 0:
+        minutes = a % 60
+        a /= 60
+        if a > 0:
+            hours = a % 24
+            a /= 24
+            if a > 0:
+                days = a
+                result += '%sd' % days
+            result += '%sh' % hours
+        result += '%sm' % minutes
+    result += '%ss' % seconds
+    return result
+
 globalPdb = None
 globalPdb = None
 
 
 traceCalled = False
 traceCalled = False