File tree 2 files changed +24
-6
lines changed
2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,14 @@ def get_minutes_from_str(time_str: str) -> int:
42
42
try :
43
43
struct_time = time .strptime (time_str , "%H:%M:%S" )
44
44
tm = struct_time .tm_hour * 60 + struct_time .tm_min
45
+ return tm
45
46
except ValueError :
47
+ pass
48
+
49
+ try :
46
50
struct_time = time .strptime (time_str , "%M:%S" )
47
51
tm = struct_time .tm_min
48
- except Exception as e :
49
- main_logger .warning (f"Unhandled error while parsing time happened. ({ e } )" )
50
- tm = 0
51
-
52
- return tm
52
+ return tm
53
+ except ValueError as e :
54
+ main_logger .warning (f"Invalid time format. ({ e } )" )
55
+ return 0
Original file line number Diff line number Diff line change 1
- from modules .utils .time import get_date
1
+ from modules .utils .time import get_date , get_minutes_from_str
2
2
3
3
4
4
def test_epoch_time ():
@@ -8,3 +8,18 @@ def test_epoch_time():
8
8
assert get_date (1497448943 , 1685541046 ) == "5 years 11 months 21 days"
9
9
assert get_date (1331474543 , 1685541046 ) == "11 years 2 months 21 days"
10
10
assert get_date (1685541046 , 1685541046 ) == "0 years 0 months 0 days"
11
+
12
+
13
+ def test_get_minutes_from_str ():
14
+ # Minutes
15
+ assert get_minutes_from_str ("12:20" ) == 12
16
+ assert get_minutes_from_str ("12:60" ) == 12
17
+
18
+ # Hours
19
+ assert get_minutes_from_str ("1:00:00" ) == 60
20
+ assert get_minutes_from_str ("1:25:00" ) == 85
21
+
22
+ # Fails
23
+ assert get_minutes_from_str ("TEST" ) == 0
24
+ assert get_minutes_from_str ("2:" ) == 0
25
+ assert get_minutes_from_str ("12:62" ) == 0
You can’t perform that action at this time.
0 commit comments