Skip to content

Commit

Permalink
Handle negative time in time formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Jan 14, 2025
1 parent c6576d6 commit 80dc567
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions RNS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ def prettydistance(m, suffix="m"):
return "%.2f %s%s" % (num, last_unit, suffix)

def prettytime(time, verbose=False, compact=False):
neg = False
if time < 0:
time = abs(time)
neg = True

days = int(time // (24 * 3600))
time = time % (24 * 3600)
hours = int(time // 3600)
Expand Down Expand Up @@ -291,10 +296,17 @@ def prettytime(time, verbose=False, compact=False):
if tstr == "":
return "0s"
else:
return tstr
if not neg:
return tstr
else:
return f"-{tstr}"

def prettyshorttime(time, verbose=False, compact=False):
neg = False
time = time*1e6
if time < 0:
time = abs(time)
neg = True

seconds = int(time // 1e6); time %= 1e6
milliseconds = int(time // 1e3); time %= 1e3
Expand Down Expand Up @@ -338,7 +350,10 @@ def prettyshorttime(time, verbose=False, compact=False):
if tstr == "":
return "0us"
else:
return tstr
if not neg:
return tstr
else:
return f"-{tstr}"

def phyparams():
print("Required Physical Layer MTU : "+str(Reticulum.MTU)+" bytes")
Expand Down

0 comments on commit 80dc567

Please sign in to comment.