Skip to content

Commit

Permalink
[GUI] Fix possible division-by-zero bug in superblock time left
Browse files Browse the repository at this point in the history
Re-work the function that converts seconds to days, hours, minutes to avoid a division-by-zero situation when the time left until the next superblock is less than 1 day.

Also, no longer show seconds in the text as they are always zero.
  • Loading branch information
Fuzzbawls committed May 28, 2024
1 parent bb2db92 commit 83aac5a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,14 @@ def saveCacheSettings(cache):
settings.setValue('cache_isTestnetRPC', cache.get('isTestnetRPC'))


def sec_to_time(seconds):
days = seconds // 86400
seconds %= days * 86400
hrs = seconds // 3600
seconds %= hrs * 3600
mins = seconds // 60
seconds %= mins * 60
return f"{days} days, {hrs} hrs, {mins} mins, {seconds} secs"
def sec_to_time(secs):
days = secs // 86400
hours = (secs - days * 86400) // 3600
minutes = (secs - days * 86400 - hours * 3600) // 60
result = ("{0} day{1}, ".format(days, "s" if days != 1 else "")) + \
("{0} hour{1}, ".format(hours, "s" if hours != 1 else "")) + \
("{0} minute{1} ".format(minutes, "s" if minutes != 1 else ""))
return result


def splitString(text, n):
Expand Down

0 comments on commit 83aac5a

Please sign in to comment.