11from cloudbot .util .timeformat import format_time , timesince , timeuntil
22
3+ from datetime import datetime , timezone
4+
35
46def test_format_time ():
57 # basic
@@ -8,4 +10,29 @@ def test_format_time():
810 # count
911 assert format_time (1200003 , count = 4 ) == "13 days, 21 hours, 20 minutes and 3 seconds"
1012 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"
13+ assert format_time (1200000 , count = 2 ) == "13 days and 21 hours"
14+
15+
16+ def test_timesince ():
17+ then = datetime (2010 , 4 , 12 , 12 , 30 , 0 )
18+ then_timestamp = 1271075400.0
19+ then_future = datetime (2012 , 4 , 12 , 12 , 30 , 0 )
20+ now = datetime (2010 , 5 , 15 , 1 , 50 , 0 )
21+ now_timestamp = 1273888200.0
22+ # timestamp
23+ assert timesince (then_timestamp , now_timestamp ) == "1 month and 2 days"
24+ # basic
25+ assert timesince (then , now ) == "1 month and 2 days"
26+ # count
27+ assert timesince (then , now , count = 3 ) == "1 month, 2 days and 13 hours"
28+ # future
29+ assert timesince (then_future , now ) == "0 minutes"
30+
31+
32+ def test_timeuntil ():
33+ now = datetime (2010 , 4 , 12 , 12 , 30 , 0 )
34+ future = datetime (2010 , 5 , 15 , 1 , 50 , 0 )
35+ # basic
36+ assert timeuntil (future , now ) == "1 month and 2 days"
37+ # count
38+ assert timeuntil (future , now , count = 3 ) == "1 month, 2 days and 13 hours"
0 commit comments