Merge pull request #3 from ekimekim/pull-format

Fixed negative times in format_bustime
pull/10/head
Christopher Usher 6 years ago committed by GitHub
commit 15fe6256a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -50,10 +50,14 @@ 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 Negative times are formatted as time-until-start, preceeded by a minus
is negative, the number of minutes/seconds is simply time past the hour. sign.
eg. the bustime "-01:20:00" indicates the run begins in 40 minutes, not 80 minutes. eg. "-1:20:00" indicates the run begins in 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 +72,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