6
6
HOUR_MIN_SEPARATOR = ":"
7
7
8
8
9
+ DAY_MAPPING = {
10
+ 1 : TimeValues .MONDAY .value ,
11
+ 2 : TimeValues .TUESDAY .value ,
12
+ 3 : TimeValues .WEDNESDAY .value ,
13
+ 4 : TimeValues .THURSDAY .value ,
14
+ 5 : TimeValues .FRIDAY .value ,
15
+ 6 : TimeValues .SATURDAY .value ,
16
+ 7 : TimeValues .SUNDAY .value ,
17
+ }
18
+
19
+
9
20
def time_range_compare (action : str , values : Dict ) -> bool :
10
21
if action == TimeKeys .CURRENT_TIME_UTC .value :
11
22
return _time_range_compare_current_time_utc (values )
12
23
elif action == TimeKeys .CURRENT_HOUR_UTC .value :
13
- return _time_range_compare_current_time_utc (values )
24
+ return _time_range_compare_current_hour_utc (values )
14
25
# we assume it passed validation right? so no need to raise an error
15
26
return False
16
27
@@ -22,20 +33,24 @@ def time_selected_days_compare(action: str, values: List[str]) -> bool:
22
33
return False
23
34
24
35
36
+ def _get_utc_time_now () -> datetime :
37
+ return datetime .now (timezone .utc )
38
+
39
+
25
40
def _time_selected_days_current_days_compare (values : List [str ]) -> bool :
26
- current_day : datetime = datetime . now ( timezone . utc ). strftime ( '%A' ). lower ()
27
- return current_day in values
41
+ current_day_number = _get_utc_time_now (). isoweekday ()
42
+ return DAY_MAPPING . get ( current_day_number , "" ) in values
28
43
29
44
30
45
def _time_range_compare_current_time_utc (values : Dict ) -> bool :
31
- current_time_utc : datetime = datetime . now ( timezone . utc )
46
+ current_time_utc : datetime = _get_utc_time_now ( )
32
47
start_date = datetime .strptime (values .get (TimeValues .START_TIME , "" ), "%Y-%m-%dT%H:%M:%S%z" )
33
48
end_date = datetime .strptime (values .get (TimeValues .END_TIME , "" ), "%Y-%m-%dT%H:%M:%S%z" )
34
49
return current_time_utc >= start_date and current_time_utc <= end_date
35
50
36
51
37
52
def _time_range_compare_current_hour_utc (values : Dict ) -> bool :
38
- current_time_utc : datetime = datetime . now ( timezone . utc )
53
+ current_time_utc : datetime = _get_utc_time_now ( )
39
54
start_hour , start_min = values .get (TimeValues .START_TIME , HOUR_MIN_SEPARATOR ).split (HOUR_MIN_SEPARATOR )
40
55
end_hour , end_min = values .get (TimeValues .END_TIME , HOUR_MIN_SEPARATOR ).split (HOUR_MIN_SEPARATOR )
41
56
return (
0 commit comments