File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -22,4 +22,22 @@ def is_after(t1, t2):
22
22
t2_time = datetime .strptime (t2 .print_time (), time_format ).time ()
23
23
return t1_time > t2_time
24
24
25
+ @staticmethod
26
+ def time_to_int (time ):
27
+ minutes = time .hours * 60 + time .minutes
28
+ seconds = minutes * 60 + time .seconds
29
+ return seconds
30
+
31
+ @staticmethod
32
+ def int_to_time (seconds ):
33
+ time = Time ()
34
+ minutes , time .seconds = divmod (seconds , 60 )
35
+ time .hours , time .minutes = divmod (minutes , 60 )
36
+ return time
37
+
38
+ @staticmethod
39
+ def add_time (t1 , t2 ):
40
+ seconds = Time .time_to_int (t1 ) + Time .time_to_int (t2 )
41
+ return Time .int_to_time (seconds )
42
+
25
43
Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ def test_is_after(self):
23
23
self .assertTrue (Time .is_after (t3 , t2 ))
24
24
self .assertFalse (Time .is_after (t2 , t3 ))
25
25
26
+ def test_time_to_int_to_time (self ):
27
+ t = Time (8 , 54 , 16 )
28
+ self .assertEqual (Time .time_to_int (t ), 32056 )
29
+ self .assertEqual (Time .time_to_int (Time .int_to_time (32056 )), 32056 )
30
+
26
31
27
32
if __name__ == '__main__' :
28
33
unittest .main ()
You can’t perform that action at this time.
0 commit comments