代码示例:
# 定义企业工作时间
business_working_hour = {
'weekdays': {'start': '09:00', 'end': '17:00'},
'saturday': {'start': '10:00', 'end': '14:00'},
'sunday': None
}
def filter_appointments_by_working_hour(appointments):
"""
通过企业工作时间筛选预约记录
"""
filtered_appointments = []
for appointment in appointments:
# 如果预约时间是周末且企业周末不工作,则跳过
if is_weekend(appointment['date']) and business_working_hour['sunday'] is None:
continue
# 如果预约时间不在企业工作时间内,则跳过
if not is_within_working_hour(appointment['time'], business_working_hour):
continue
filtered_appointments.append(appointment)
return filtered_appointments
def is_weekend(date):
"""
判断给定日期是不是周末
"""
# 省略代码实现
def is_within_working_hour(time, working_hour):
"""
判断给定时间是不是在企业工作时间内
"""
# 省略代码实现
以上代码中,filter_appointments_by_working_hour
函数接受一个预约记录列表,并返回一个在企业工作时间内的预约记录子列表。
is_weekend
函数判断给定日期是不是周末,可根据需求进行实现。is_within_working_hour
函数判断给定时间是不是在企业工作时间内,需要通过解析时间字符串和工作时间字典来实现。
利用以上两个函数,我们就可以通过企业工作时间筛选预约记录了。