Skip to content

Commit de4f757

Browse files
committed
Add some unit tests for timeformat.py
1 parent 6218be2 commit de4f757

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from cloudbot.util.timeformat import format_time, timesince, timeuntil
2+
3+
4+
def test_format_time():
5+
# basic
6+
assert format_time(120000) == "1 day, 9 hours and 20 minutes"
7+
assert format_time(120000, simple=True) == "1d 9h 20m"
8+
# count
9+
assert format_time(1200003, count=4) == "13 days, 21 hours, 20 minutes and 3 seconds"
10+
assert format_time(1200000, count=4) == "13 days, 21 hours and 20 minutes"
11+
assert format_time(1200000, count=2) == "13 days and 21 hours"

cloudbot/util/timeformat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def timeuntil(d, now=None, count=2, accuracy=6, simple=False):
5858
"""
5959
if not now:
6060
now = datetime.datetime.now()
61-
return timesince(now, d, count=3, accuracy=6, simple=False)
61+
return timesince(now, d, count, accuracy, simple)
6262

6363

6464
def format_time(seconds, count=3, accuracy=6, simple=False):
@@ -107,6 +107,7 @@ def format_time(seconds, count=3, accuracy=6, simple=False):
107107
strings = []
108108
i = 0
109109
for period_name, period_seconds in periods:
110+
print(i, period_name)
110111
if i < count:
111112
if seconds > period_seconds:
112113
period_value, seconds = divmod(seconds, period_seconds)

0 commit comments

Comments
 (0)