Hi I need some help to understand why this is happening. I have a method to track \'time remaining\' in an event program:
def get_program_time_budget(self):
Why?
Possibly as a unintended side effect of the way //
and %
are defined.
Possibly because it makes it easier to implement the datetime
class. Five minutes before the epoch is 23:55, not 0:-5.
It doesn't really matter. Just know that it's how days
, seconds
, and microseconds
get normalized. And that it can easily be worked around.
def format_timedelta(td):
if td < timedelta(0):
return '-' + format_timedelta(-td)
else:
# Change this to format positive timedeltas the way you want
return str(td)
>>> format_timedelta(timedelta(minutes=-5))
'-0:05:00'