Improve a few functions in common and item

This commit is contained in:
Veronica K. B. Olsen
2020-10-24 17:54:02 +02:00
parent c0ad631039
commit 8d31428a9d
4 changed files with 39 additions and 28 deletions
+7 -6
View File
@@ -152,13 +152,13 @@ def formatInt(theInt):
theVal /= 1000.0
if theVal < 1000.0:
if theVal < 10.0:
return "%4.2f%s%s" % (theVal, nwUnicode.U_THNSP, pF)
return f"{theVal:4.2f}{nwUnicode.U_THNSP}{pF}"
elif theVal < 100.0:
return "%4.1f%s%s" % (theVal, nwUnicode.U_THNSP, pF)
return f"{theVal:4.1f}{nwUnicode.U_THNSP}{pF}"
else:
return "%3.0f%s%s" % (theVal, nwUnicode.U_THNSP, pF)
return f"{theVal:3.0f}{nwUnicode.U_THNSP}{pF}"
return "%d" % theInt
return str(theInt)
def formatTimeStamp(theTime, fileSafe=False):
"""Take a number (on the format returned by time.time()) and convert
@@ -170,11 +170,12 @@ def formatTimeStamp(theTime, fileSafe=False):
return datetime.fromtimestamp(theTime).strftime(nwConst.tStampFmt)
def formatTime(tS):
"""Format the time spent in 00:00:00 format.
"""Format a time in seconds in HH:MM:SS format or d-HH:MM:SS format
if a full day or longer.
"""
if isinstance(tS, int):
if tS >= 86400:
return f"{tS//86400:d}-{tS//3600%24:02d}:{tS%3600//60:02d}:{tS%60:02d}"
return f"{tS//86400:d}-{tS%86400//3600:02d}:{tS%3600//60:02d}:{tS%60:02d}"
else:
return f"{tS//3600:02d}:{tS%3600//60:02d}:{tS%60:02d}"
return "ERROR"