File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -174,19 +174,22 @@ def is_time_greater_than_now(time_str: str) -> bool:
174
174
175
175
def is_current_time_within_range (time_range_str : str ):
176
176
"""
177
- Determine whether the current time is within the time range
177
+ 判断当前时间是否在时间范围内,支持跨越午夜的时间范围
178
178
179
- :param time_range_str: such as "18:30:00~20:30:00"
180
- :return: Return whether it is within the time range
179
+ :param time_range_str: 如 "18:30:00~20:30:00" 或跨越午夜的 "20:00:00~02:00 :00"
180
+ :return: 是否在时间范围内
181
181
"""
182
182
start_str , end_str = time_range_str .split ("~" )
183
183
time_format = "%H:%M:%S"
184
184
185
185
start_time = datetime .strptime (start_str .strip (), time_format ).time ()
186
186
end_time = datetime .strptime (end_str .strip (), time_format ).time ()
187
-
188
187
now = datetime .now ().time ()
189
- return start_time <= now <= end_time
188
+
189
+ if end_time < start_time :
190
+ return now >= start_time or now <= end_time
191
+ else :
192
+ return start_time <= now <= end_time
190
193
191
194
192
195
def is_time_interval_exceeded (last_check_time , interval_seconds = 60 ):
You can’t perform that action at this time.
0 commit comments