2021-10-20 11:45:37 +00:00
|
|
|
from common.utils.timezone import local_now
|
2021-10-20 09:56:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def contains_time_period(time_periods):
|
|
|
|
"""
|
|
|
|
time_periods: [{"id": 1, "value": "00:00~07:30、10:00~13:00"}, {"id": 2, "value": "00:00~00:00"}]
|
|
|
|
"""
|
|
|
|
if not time_periods:
|
|
|
|
return False
|
|
|
|
|
2021-10-20 11:45:37 +00:00
|
|
|
current_time = local_now().strftime('%H:%M')
|
|
|
|
today_time_period = next(filter(lambda x: str(x['id']) == local_now().strftime("%w"), time_periods))
|
2021-10-22 08:09:22 +00:00
|
|
|
today_time_period = today_time_period['value']
|
|
|
|
if not today_time_period:
|
|
|
|
return False
|
|
|
|
|
2021-10-25 06:24:43 +00:00
|
|
|
for time in today_time_period.split('、'):
|
2021-10-20 09:56:59 +00:00
|
|
|
start, end = time.split('~')
|
|
|
|
end = "24:00" if end == "00:00" else end
|
|
|
|
if start <= current_time <= end:
|
|
|
|
return True
|
|
|
|
return False
|