测试工程师之【python】按工龄开始日期和司龄开始日期计算当年公司福利年假

1.脚本需求:
公司内部休假系统,计算规则比较复杂比较恶心,前期准备工作看看文档什么的,想着自己写一个一摸一样类似的规则方便到时候给出工龄和司龄日期自动计算结果,省的到时候用计算器手工算了,另一方面是熟悉业务方便后期功能测试写用例场景能想的全覆盖的多一点
2.代码实现及思路
需求文档上有一部分示例场景了解的,概括来说就是未满1年-已满1年-等等等一直到第6年每满一年都有对应的福利年假天数,在根据工龄什么时候时开始工作共多少天了当年有没有跨档,根据跨档节点进行计算,猜测应该有bug,因为判断条年写死了,有误差

import datetime

def welfare_annual_leave(working_years_Starttime,Secretary_Ling_Starttime):
    Small_10,Small_20 = 0,0
    Secretary_Ling_one,Secretary_Ling_two,Secretary_Ling_three,Secretary_Ling_four,Secretary_Ling_five,Secretary_Ling_six = 0,0,0,0,0,0
    working_years_Starttime = datetime.date(int(working_years_Starttime.split('-')[0]),int(working_years_Starttime.split('-')[1]),int(working_years_Starttime.split('-')[2]))
    Secretary_Ling_Starttime = datetime.date(int(Secretary_Ling_Starttime.split('-')[0]),int(Secretary_Ling_Starttime.split('-')[1]),int(Secretary_Ling_Starttime.split('-')[2]))
    if datetime.date(datetime.date.today().year,1,1).__sub__(Secretary_Ling_Starttime).days >= 0:
        That_year_1month1 = datetime.date(datetime.date.today().year,1,1)
        differ_day = That_year_1month1.__sub__(working_years_Starttime).days
        while 1:
            if str(That_year_1month1) == str(That_year_1month1.year) + '-12-31':
                break
            That_year_1month1 += datetime.timedelta(days=1)
            differ_day += 1
            if differ_day == 3650:
                Small_10 = That_year_1month1
            elif differ_day == 7300:
                Small_20 = That_year_1month1
        That_year_1month1 = datetime.date(datetime.date.today().year,1,1)
        Straddle_day = That_year_1month1.__sub__(Secretary_Ling_Starttime).days
        while 1:
            if str(That_year_1month1) == str(That_year_1month1.year) + '-12-31':
                break
            That_year_1month1 += datetime.timedelta(days=1)
            Straddle_day += 1
            if Straddle_day == 365:
                Secretary_Ling_one = That_year_1month1
            elif Straddle_day == 730:
                Secretary_Ling_two = That_year_1month1
            elif Straddle_day == 1095:
                Secretary_Ling_three = That_year_1month1
            elif Straddle_day == 1460:
                Secretary_Ling_four = That_year_1month1
            elif Straddle_day == 1825:
                Secretary_Ling_five = That_year_1month1
            elif Straddle_day == 2190:
                Secretary_Ling_six = That_year_1month1
        if Small_10:
            if Secretary_Ling_one:
                if Small_10.__sub__(Secretary_Ling_one).days == 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 1)
                elif Small_10.__sub__(Secretary_Ling_one).days > 0:
                    return ((Secretary_Ling_one.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((Small_10.__sub__(Secretary_Ling_one).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 1)
                elif Small_10.__sub__(Secretary_Ling_one).days < 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((Secretary_Ling_one.__sub__(Small_10).days / 365) * 0) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_one).days / 365) * 1)
            elif Secretary_Ling_two:
                if Small_10.__sub__(Secretary_Ling_two).days == 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 2)
                elif Small_10.__sub__(Secretary_Ling_two).days > 0:
                    return ((Secretary_Ling_two.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((Small_10.__sub__(Secretary_Ling_two).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 2)
                elif Small_10.__sub__(Secretary_Ling_two).days < 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((Secretary_Ling_two.__sub__(Small_10).days / 365) * 1) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_two).days / 365) * 2)
            elif Secretary_Ling_three:
                if Small_10.__sub__(Secretary_Ling_three).days == 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 3)
                elif Small_10.__sub__(Secretary_Ling_three).days > 0:
                    return ((Secretary_Ling_three.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((Small_10.__sub__(Secretary_Ling_three).days / 365) * 6) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 3)
                elif Small_10.__sub__(Secretary_Ling_three).days < 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((Secretary_Ling_three.__sub__(Small_10).days / 365) * 2) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_three).days / 365) * 3)
            elif Secretary_Ling_four:
                if Small_10.__sub__(Secretary_Ling_four).days == 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 6) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 4)
                elif Small_10.__sub__(Secretary_Ling_four).days > 0:
                    return ((Secretary_Ling_four.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 6) + ((Small_10.__sub__(Secretary_Ling_four).days / 365) * 7) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 4)
                elif Small_10.__sub__(Secretary_Ling_four).days < 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 6) + ((Secretary_Ling_four.__sub__(Small_10).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_four).days / 365) * 4)
            elif Secretary_Ling_five:
                if Small_10.__sub__(Secretary_Ling_five).days == 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 7) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 5)
                elif Small_10.__sub__(Secretary_Ling_five).days > 0:
                    return ((Secretary_Ling_five.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 7) + ((Small_10.__sub__(Secretary_Ling_five).days / 365) * 8) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 5)
                elif Small_10.__sub__(Secretary_Ling_five).days < 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 7) + ((Secretary_Ling_five.__sub__(Small_10).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_five).days / 365) * 5)
            elif Secretary_Ling_six:
                if Small_10.__sub__(Secretary_Ling_six).days == 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 8) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 6)
                elif Small_10.__sub__(Secretary_Ling_six).days > 0:
                    return ((Secretary_Ling_six.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 8) + ((Small_10.__sub__(Secretary_Ling_six).days / 365) * 9) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 6)
                elif Small_10.__sub__(Secretary_Ling_six).days < 0:
                    return ((Small_10.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 8) + ((Secretary_Ling_six.__sub__(Small_10).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_six).days / 365) * 6)
        elif Small_20:
            if Secretary_Ling_one:
                if Small_20.__sub__(Secretary_Ling_one).days == 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 0) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 1)
                elif Small_20.__sub__(Secretary_Ling_one).days > 0:
                    return ((Secretary_Ling_one.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 0) + ((Small_20.__sub__(Secretary_Ling_one).days / 365) * 1) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 1)
                elif Small_20.__sub__(Secretary_Ling_one).days < 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 0) + ((Secretary_Ling_one.__sub__(Small_20).days / 365) * 0) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_one).days / 365) * 1)
            elif Secretary_Ling_two:
                if Small_20.__sub__(Secretary_Ling_two).days == 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 1) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 2)
                elif Small_20.__sub__(Secretary_Ling_two).days > 0:
                    return ((Secretary_Ling_two.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 1) + ((Small_20.__sub__(Secretary_Ling_two).days / 365) * 2) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 2)
                elif Small_20.__sub__(Secretary_Ling_two).days < 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 1) + ((Secretary_Ling_two.__sub__(Small_20).days / 365) * 1) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_two).days / 365) * 2)
            elif Secretary_Ling_three:
                if Small_20.__sub__(Secretary_Ling_three).days == 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 2) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 3)
                elif Small_20.__sub__(Secretary_Ling_three).days > 0:
                    return ((Secretary_Ling_three.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 2) + ((Small_20.__sub__(Secretary_Ling_three).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 3)
                elif Small_20.__sub__(Secretary_Ling_three).days < 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 2) + ((Secretary_Ling_three.__sub__(Small_20).days / 365) * 2) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_three).days / 365) * 3)
            elif Secretary_Ling_four:
                if Small_20.__sub__(Secretary_Ling_four).days == 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 4)
                elif Small_20.__sub__(Secretary_Ling_four).days > 0:
                    return ((Secretary_Ling_four.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((Small_20.__sub__(Secretary_Ling_four).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 4)
                elif Small_20.__sub__(Secretary_Ling_four).days < 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((Secretary_Ling_four.__sub__(Small_20).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_four).days / 365) * 4)
            elif Secretary_Ling_five:
                if Small_20.__sub__(Secretary_Ling_five).days == 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 5)
                elif Small_20.__sub__(Secretary_Ling_five).days > 0:
                    return ((Secretary_Ling_five.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((Small_20.__sub__(Secretary_Ling_five).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 5)
                elif Small_20.__sub__(Secretary_Ling_five).days < 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((Secretary_Ling_five.__sub__(Small_20).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_five).days / 365) * 5)
            elif Secretary_Ling_six:
                if Small_20.__sub__(Secretary_Ling_six).days == 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 6)
                elif Small_20.__sub__(Secretary_Ling_six).days > 0:
                    return ((Secretary_Ling_six.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((Small_20.__sub__(Secretary_Ling_six).days / 365) * 6) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 5)
                elif Small_20.__sub__(Secretary_Ling_six).days < 0:
                    return ((Small_20.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((Secretary_Ling_six.__sub__(Small_20).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_six).days / 365) * 5)
        elif differ_day < 3650:
            if Secretary_Ling_one:
                return ((Secretary_Ling_one.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_one).days / 365) * 4)
            elif Secretary_Ling_two:
                return ((Secretary_Ling_two.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_two).days / 365) * 5)
            elif Secretary_Ling_three:
                 return ((Secretary_Ling_three.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_three).days / 365) * 6)
            elif Secretary_Ling_four:
                return ((Secretary_Ling_four.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 6) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_four).days / 365) * 7)
            elif Secretary_Ling_five:
                return ((Secretary_Ling_five.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 7) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_five).days / 365) * 8)
            elif Secretary_Ling_six:
                return ((Secretary_Ling_six.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 8) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_six).days / 365) * 9)
        elif 3650 < differ_day < 7300:
            if Secretary_Ling_one:
                return ((Secretary_Ling_one.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 0) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_one).days / 365) * 1)
            elif Secretary_Ling_two:
                return ((Secretary_Ling_two.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 1) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_two).days / 365) * 2)
            elif Secretary_Ling_three:
                 return ((Secretary_Ling_three.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 2) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_three).days / 365) * 3)
            elif Secretary_Ling_four:
                return ((Secretary_Ling_four.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_four).days / 365) * 4)
            elif Secretary_Ling_five:
                return ((Secretary_Ling_five.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_five).days / 365) * 5)
            elif Secretary_Ling_six:
                return ((Secretary_Ling_six.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_six).days / 365) * 6)
        elif differ_day > 7300:
            if Secretary_Ling_one:
                return ((Secretary_Ling_one.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 0) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_one).days / 365) * 1)
            elif Secretary_Ling_two:
                return ((Secretary_Ling_two.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 1) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_two).days / 365) * 2)
            elif Secretary_Ling_three:
                 return ((Secretary_Ling_three.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 2) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_three).days / 365) * 3)
            elif Secretary_Ling_four:
                return ((Secretary_Ling_four.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_four).days / 365) * 4)
            elif Secretary_Ling_five:
                return ((Secretary_Ling_five.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 4) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_five).days / 365) * 5)
            elif Secretary_Ling_six:
                return ((Secretary_Ling_six.__sub__(datetime.date(datetime.date.today().year,1,1)).days / 365) * 5) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_six).days / 365) * 5)
    else:
        Secretary_Ling_Starttime_1 = Secretary_Ling_Starttime
        differ_day = Secretary_Ling_Starttime.__sub__(working_years_Starttime).days + 1
        while 1:
            if str(Secretary_Ling_Starttime) == str(Secretary_Ling_Starttime.year) + '-12-31':
                break
            Secretary_Ling_Starttime += datetime.timedelta(days=1)
            differ_day += 1
            if differ_day == 3650:
                Small_10 = Secretary_Ling_Starttime
            elif differ_day == 7300:
                Small_20 = Secretary_Ling_Starttime
        if Small_10:
            if Small_10.__sub__(Secretary_Ling_Starttime_1).days == 0:
                return (datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_Starttime_1).days / 365) * 0
            elif Small_10.__sub__(Secretary_Ling_Starttime_1).days > 0:
                return ((Small_10.__sub__(Secretary_Ling_Starttime_1).days / 365) * 3) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_10).days / 365) * 0)
            elif Small_10.__sub__(Secretary_Ling_Starttime_1).days < 0:
                return (datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_Starttime_1).days / 365) * 0
        elif Small_20:
            if Small_20.__sub__(Secretary_Ling_Starttime_1).days == 0:
                return (datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_Starttime_1).days / 365) * 0
            elif Small_20.__sub__(Secretary_Ling_Starttime_1).days > 0:
                return ((Small_20.__sub__(Secretary_Ling_Starttime_1).days / 365) * 0) + ((datetime.date(datetime.date.today().year + 1,1,1).__sub__(Small_20).days / 365) * 0)
            elif Small_20.__sub__(Secretary_Ling_Starttime_1).days < 0:
                return (datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_Starttime_1).days / 365) * 0
        elif differ_day < 3650:
            return (datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_Starttime_1).days / 365) * 3
        elif 3650 < differ_day < 7300:
            return (datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_Starttime_1).days / 365) * 0
        elif differ_day > 7300:
            return (datetime.date(datetime.date.today().year + 1,1,1).__sub__(Secretary_Ling_Starttime_1).days / 365) * 0
            
if __name__ == "__main__":
	print(welfare_annual_leave('2011-02-01','2019-12-01'))
上一篇:深入理解vuex


下一篇:vue+zrender实现医院体温单