| | |
| | | * 以年为单位相差为:6年 |
| | | * 以月为单位相差为:73个月 |
| | | * 以日为单位相差为:2220天 |
| | | * @param fromDate |
| | | * @param toDateOrigin |
| | | * @return |
| | | */ |
| | | public static DateCompare dayCompare(Date fromDate,Date toDateOrigin,Date freeStart,Date freeEnd){ |
| | | public static DateCompare dayCompare(Date fromDateOrigin,Date toDateOrigin,Date freeStart,Date freeEnd){ |
| | | //开始时间往后延伸,除去有效时期 |
| | | fromDate = DateUtil.addDaysToDate(fromDate,getIntersectingDays(fromDate,DateUtil.addDaysToDate(toDateOrigin,1),freeStart,DateUtil.addDaysToDate(freeEnd,1))); |
| | | Date fromDate = DateUtil.addDaysToDate(fromDateOrigin,getIntersectingDays(fromDateOrigin,DateUtil.addDaysToDate(toDateOrigin,1), |
| | | freeStart, |
| | | Objects.isNull(freeEnd)?null:DateUtil.addDaysToDate(freeEnd,1)) |
| | | ); |
| | | if(toDateOrigin.getTime()< fromDate.getTime()){ |
| | | return DateCompare.builder().day(0).month(0).year(0).yearFloat(new BigDecimal(0)).monthFloat(new BigDecimal(0)).build(); |
| | | } |
| | |
| | | } |
| | | yearFloat = yearFloat.add(new BigDecimal(1.0*yearDays).divide(new BigDecimal(365.0), 15,RoundingMode.HALF_UP)); |
| | | } |
| | | int monthDays = day - (DateUtil.daysBetweenDates(DateUtil.addMonthToDate(fromDate,month),fromDate)+1) ; |
| | | int monthDays = day - (DateUtil.daysBetweenDates(DateUtil.addMonthToDate(fromDate,month),fromDate)) ; |
| | | if(monthDays!=0){ |
| | | if(monthDays <0){ |
| | | month = month-1; |
| | |
| | | } |
| | | |
| | | public static int getIntersectingDays(Date start1, Date end1, Date start2, Date end2) { |
| | | if(Objects.isNull(start2)||Objects.isNull(end2)){ |
| | | return 0; |
| | | } |
| | | Date earlierStart = DateUtil.daysBetweenDates(start1,start2)>0? start1 : start2; |
| | | Date laterEnd = DateUtil.daysBetweenDates(end2,end1)>0 ? end1 : end2; |
| | | |