2025年1月1日起最新退休年龄算法Java实现最优方案

全国人民代表大会常务委员会关于实施渐进式延迟法定退休年龄的决定icon-default.png?t=O83Ahttps://www.gov.cn/yaowen/liebiao/202409/content_6974294.htm

1、业务代码

 /**
     * 计算退休日期
     * @author:csdn百思不得奇解
     * @param birthDate             出生日期
     * @param originalRetirementAge 原退休年龄
     * @return {@link LocalDate }
     */
    public static RetirementInfo calculateRetirementDate(LocalDate birthDate, int originalRetirementAge) {
        RetirementInfo retirementInfo = new RetirementInfo();
        // 政策起始日期
        LocalDate policyStartDate = LocalDate.of(2025, 1, 1);

        // 计算原退休日期
        LocalDate originalRetirementDate = birthDate.plusYears(originalRetirementAge);

        // 计算政策开始日期到原退休日期的月数差异
        long monthsBetween = ChronoUnit.MONTHS.between(policyStartDate, originalRetirementDate) + 1L;
        // 计算政策开始日期到原退休日期的天数差异
        long daysBetween = ChronoUnit.DAYS.between(policyStartDate, originalRetirementDate);

        // 如果月数差异为0或负值,直接返回原退休日期
        if (daysBetween < 0) {
            retirementInfo.setRetirementDateNew(originalRetirementDate);
            return retirementInfo;
        }

        // 计算调整后月份
        int monthsToAdd = 0;

        switch (originalRetirementAge) {
            case 60:
            case 55:
                // 原法定退休年龄为55岁的女职工:每4个月延迟1个月,逐步延迟至58岁
                // 原法定退休年龄为60岁的男职工:每4个月延迟1个月,逐步延迟至63岁
                monthsToAdd = (int) Math.ceil((double) monthsBetween / 4);
                if (monthsToAdd > 36) {
                    monthsToAdd = 36;
                }
                break;
            case 50:
                // 原法定退休年龄为50岁的女职工:每2个月延迟1个月,逐步延迟至55岁
                monthsToAdd = (int) Math.ceil((double) monthsBetween / 2);
                if (monthsToAdd > 60) {
                    monthsToAdd = 60;
                }
                break;
            default:
                break;
        }
        // 计算最终的退休年龄
        int totalMonths = originalRetirementAge * 12 + monthsToAdd;
        int newAgeInYears = totalMonths / 12;
        int newAgeInMonths = totalMonths % 12;


        // 计算最终的退休日期
        retirementInfo.setRetirementDateNew(originalRetirementDate.plusMonths(monthsToAdd));
        retirementInfo.setRetirementDateOld(originalRetirementDate);
        retirementInfo.setDelayMonth(monthsToAdd);
        retirementInfo.setRetirementAgeNew(String.format("%s岁%s个月", newAgeInYears, newAgeInMonths));
        retirementInfo.setRetirementAgeOld(String.format("%s岁%s个月", originalRetirementAge, 0));
        return retirementInfo;
    }

    @Data
    static
    class RetirementInfo {

        private Integer delayMonth;//延迟月份
        private String retirementAgeOld;//原退休年龄
        private String retirementAgeNew;//最新退休年龄
        private LocalDate retirementDateOld;//原退休日期
        private LocalDate retirementDateNew;//最新退休日期
    }

2、代码实现

public static void main(String[] args) {
        // 测试用例
        LocalDate birthDate = LocalDate.of(1972, 7, 31); // 出生日期
        //LocalDate birthDate = LocalDate.of(1972, 8, 31); // 出生日期
        //LocalDate birthDate = LocalDate.of(1965, 5, 27); // 出生日期
        int originalRetirementAge = 60; // 原法定退休年龄
        RetirementInfo retirementDate = calculateRetirementDate(birthDate, originalRetirementAge);
        System.out.println("新政策实施日期: " + "【" + "2025-01-01" + "】");
        System.out.println("预设人员的生日: " + "【" + birthDate + "】");
        System.out.println("原来的退休日期: " + "【" + retirementDate.getRetirementDateOld() + "】");
        System.out.println("新政策退休日期: " + "【" + retirementDate.getRetirementDateNew() + "】");
        System.out.println("原来的退休年龄: " + retirementDate.getRetirementAgeOld());
        System.out.println("新政策退休年龄: " + retirementDate.getRetirementAgeNew());
        System.out.println("*新政策延迟退休的月数: " + retirementDate.getDelayMonth() + "个月");
    }

3、效果图

大家可以自己多测试几个日期,因为我看有些博主的代码看似实现了,但是一些特殊的日期还是不准确的。特殊的日期比如1966-10-31,1965-1-31

1966-10-31和2027-04-30相差的年月为60岁5个月,是因为在这两个日期之间没有跨越10月31日这一天。而1966-10-30和2027-04-30相差的年月为60岁6个月,是因为在这两个日期之间跨越了10月31日这一天,所以多出了一个月。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@百思不得奇解

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值