1. Victor Stinner
  2. hachoir

Commits

haypo  committed 82b97bd

humanDuration(): raise exceptions if value is not a positive number

  • Participants
  • Parent commits 4e480d1
  • Branches default

Comments (0)

Files changed (1)

File hachoir-core/hachoir_core/tools.py

View file
  • Ignore whitespace
     >>> humanDuration(6402309)
     u'1 hour(s) 46 min 42 sec'
     """
+    if millisec < 0:
+        raise ValueError("Invalid duration value (%s)" % millisec)
+    if isinstance(millisec, float):
+        millisec = int(millisec)
+    if not isinstance(millisec, (int, long)):
+        raise ValueError("humanDuration() argument must be a positive integer")
 
     # Milliseconds
     if millisec < 1000: