def F_Get_WorkDay_First_Last(*args):
#参数解释: BeginDate -> 起始日, EndDate -> 结束日, day_type -> 取值类型
#返回: 从员工对应的日历中,根据起始日和结束日统计指定期段中指定类型的天数
if len(args) == 0 or len(args) == 1:
return 0
elif len(args) == 2:
BeginDate = args[0]
EndDate = args[1]
day_type = 1
elif len(args) == 3:
BeginDate = args[0]
EndDate = args[1]
day_type = args[2]
else:
return 0
workday_data = global_dict['F_Workday'] or []
holiday_data = global_dict['F_Holiday'] or []
legal_holiday_data = global_dict['F_LegalHoliday'] or []
employee_id = individual_dict['ref_employee_id']
employee_days = global_dict['F_get_day_type_form_item'][employee_id]
lower_date = datetime.datetime.strptime(BeginDate, '%Y-%m-%d')
upper_date = datetime.datetime.strptime(EndDate, '%Y-%m-%d')
if not (upper_date and lower_date) or lower_date > upper_date:
return 0
if day_type == 1:
count_legal_holiday = 0
count_workday = 0
count_daytype_workday = 0
count_daytype_workoff = 0
while True:
str_lower_date = lower_date.strftime('%Y-%m-%d')
if str_lower_date in legal_holiday_data:
count_legal_holiday += 1
count_workday += 1
elif str_lower_date in workday_data or lower_date.weekday() not in [5,6] and str_lower_date not in holiday_data:
count_workday += 1
if day_type in [4, 5]:
day_type_value = employee_days[str_lower_date]
if day_type == 4 and day_type_value and day_type_value == 'schedule_workday':
count_daytype_workday += 1
elif day_type == 5 and day_type_value and day_type_value == 'schedule_day_off':
count_daytype_workoff += 1
#2020.11.09,Elvis.Yu,增加day_type==91 and count_workday-count_legal_holiday>0,找到第一个工作日(不含法定假日)退出
if day_type==1 and count_workday-count_legal_holiday>0:
break
elif lower_date >= upper_date:
lower_date=None
break
lower_date = lower_date + timedelta(days=1)
if lower_date:
lower_date =lower_date.strftime('%Y-%m-%d')
return lower_date
if day_type == 2:
count_legal_holiday = 0
count_workday = 0
count_daytype_workday = 0
count_daytype_workoff = 0
while True:
str_upper_date = upper_date.strftime('%Y-%m-%d')
if str_upper_date in legal_holiday_data:
count_legal_holiday += 1
count_workday += 1
elif str_upper_date in workday_data or upper_date.weekday() not in [5,6] and str_upper_date not in holiday_data:
count_workday += 1
if day_type in [4, 5]:
day_type_value = employee_days[str_lower_date]
if day_type == 4 and day_type_value and day_type_value == 'schedule_workday':
count_daytype_workday += 1
elif day_type == 5 and day_type_value and day_type_value == 'schedule_day_off':
count_daytype_workoff += 1
#2020.11.09,Elvis.Yu,增加day_type==91 and count_workday-count_legal_holiday>0,找到第一个工作日(不含法定假日)退出
if day_type==2 and count_workday-count_legal_holiday>0:
break
elif upper_date <= lower_date:
upper_date=None
break
upper_date = upper_date - timedelta(days=1)
if upper_date:
upper_date =upper_date.strftime('%Y-%m-%d')
return upper_date