计算逾期天数和小时数
This commit is contained in:
@ -62,7 +62,7 @@ public class OrderUtil {
|
||||
public static Integer getOrderOverdueHours(LocalDateTime endRentTime) {
|
||||
if(endRentTime!=null){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
log.info("计算时租逾期小时数,预计还车时间:{}, 当前时间 : {}", endRentTime, now);
|
||||
log.info("计算间隔小时数,预计还车时间:{}, 当前时间 : {}", endRentTime, now);
|
||||
if(now.isAfter(endRentTime)){
|
||||
int hours = (int) ChronoUnit.HOURS.between(endRentTime, now);
|
||||
return hours +1;
|
||||
@ -79,8 +79,14 @@ public class OrderUtil {
|
||||
public static Integer getOrderOverdueDays(LocalDateTime endRentTime) {
|
||||
if(endRentTime!=null){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
log.info("计算间隔天数,预计还车时间:{}, 当前时间 : {}", endRentTime, now);
|
||||
if(now.isAfter(endRentTime)){
|
||||
return (int) ChronoUnit.DAYS.between(endRentTime, now);
|
||||
long days = ChronoUnit.DAYS.between(endRentTime, now);
|
||||
// 检查是否有不足一天的余数
|
||||
if (!now.truncatedTo(ChronoUnit.DAYS).equals(endRentTime.plusDays(days).truncatedTo(ChronoUnit.DAYS))) {
|
||||
return (int) days + 1;
|
||||
}
|
||||
return (int) days;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -113,9 +119,14 @@ public class OrderUtil {
|
||||
if(startTime!=null&&endTime!=null){
|
||||
if(startTime.isBefore(endTime)){
|
||||
if(StringUtils.equalsIgnoreCase(rentalType, RentCarTypeEnum.HOUR_RENTAL.getCode())){
|
||||
return (int) ChronoUnit.HOURS.between(startTime, endTime);
|
||||
return (int) ChronoUnit.HOURS.between(startTime, endTime) +1;
|
||||
} else {
|
||||
return (int) ChronoUnit.DAYS.between(startTime, endTime);
|
||||
long days = ChronoUnit.DAYS.between(startTime, endTime) +1;
|
||||
// 检查是否有不足一天的余数
|
||||
if (!endTime.truncatedTo(ChronoUnit.DAYS).equals(endTime.plusDays(days).truncatedTo(ChronoUnit.DAYS))) {
|
||||
return (int) days + 1;
|
||||
}
|
||||
return (int) days;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user