Fixed negative times in format_bustime

pull/3/head
Christopher Usher 6 years ago
parent afb96cbfc4
commit 4c22edf2e6

@ -50,10 +50,11 @@ def format_bustime(bustime, round="millisecond"):
110:50 110:50
159:59:59.999 159:59:59.999
-10:30:01.100 -10:30:01.100
Note that a negative value only indicates the number of hours after the start
is negative, the number of minutes/seconds is simply time past the hour.
eg. the bustime "-01:20:00" indicates the run begins in 40 minutes, not 80 minutes.
""" """
sign = ''
if bustime < 0:
sign = '-'
bustime = -bustime
total_mins, secs = divmod(bustime, 60) total_mins, secs = divmod(bustime, 60)
hours, mins = divmod(total_mins, 60) hours, mins = divmod(total_mins, 60)
parts = [ parts = [
@ -68,4 +69,4 @@ def format_bustime(bustime, round="millisecond"):
parts.append("{:06.3f}".format(secs)) parts.append("{:06.3f}".format(secs))
else: else:
raise ValueError("Bad rounding value: {!r}".format(round)) raise ValueError("Bad rounding value: {!r}".format(round))
return ":".join(parts) return sign + ":".join(parts)

Loading…
Cancel
Save