Fix calculation of totals longer than a day

datetime.timedelta stores days, seconds and microseconds. Therefore the
seconds attribute only stores timedeltas of less than 24 hours. Use
total_seconds() instead which properly accounts for the days part.
This commit is contained in:
Michael Eischer 2019-10-12 18:57:00 +02:00 committed by lauft
parent cd0d5d175e
commit 8053ccf68e
2 changed files with 39 additions and 4 deletions

View file

@ -133,13 +133,15 @@ def calculate_totals(input_stream):
# Compose table rows.
grand_total = 0
for tag in sorted(totals):
formatted = format_seconds(totals[tag].seconds)
grand_total += totals[tag].seconds
seconds = int(totals[tag].total_seconds())
formatted = format_seconds(seconds)
grand_total += seconds
output.append("{:{width}} {:10}".format(tag, formatted, width=max_width))
if untagged is not None:
formatted = format_seconds(untagged.seconds)
grand_total += untagged.seconds
seconds = int(untagged.total_seconds())
formatted = format_seconds(seconds)
grand_total += seconds
output.append("{:{width}} {:10}".format("", formatted, width=max_width))
# Compose total.