将 mall 使用到 Date 的部分,迁移到 LocalDateTime 中

This commit is contained in:
YunaiV
2022-11-13 21:23:38 +08:00
parent 12d045ea58
commit 38f67d4130
21 changed files with 123 additions and 115 deletions

View File

@ -1,13 +1,8 @@
package cn.iocoder.yudao.framework.common.util.date;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.*;
import java.util.Calendar;
import java.util.Date;
@ -58,6 +53,7 @@ public class DateUtils {
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
}
@Deprecated
public static Date addTime(Duration duration) {
return new Date(System.currentTimeMillis() + duration.toMillis());
}
@ -87,6 +83,7 @@ public class DateUtils {
return buildTime(year, mouth, day, 0, 0, 0);
}
@Deprecated
public static LocalDateTime buildLocalDateTime(int year, int mouth, int day) {
return LocalDateTime.of(year, mouth, day, 0, 0, 0);
}
@ -135,14 +132,7 @@ public class DateUtils {
return a.isAfter(b) ? a : b;
}
public static boolean beforeNow(Date date) {
return date.getTime() < System.currentTimeMillis();
}
public static boolean afterNow(Date date) {
return date.getTime() >= System.currentTimeMillis();
}
@Deprecated
public static boolean afterNow(LocalDateTime localDateTime) {
return localDateTime.isAfter(LocalDateTime.now());
}
@ -178,19 +168,6 @@ public class DateUtils {
return c.getTime();
}
/**
* 是否今天
*
* @param date 日期
* @return 是否
*/
public static boolean isToday(Date date) {
if (date == null) {
return false;
}
return DateUtil.isSameDay(date, new Date());
}
/**
* 是否今天
*
@ -201,19 +178,4 @@ public class DateUtils {
return LocalDateTimeUtil.isSameDay(date, LocalDateTime.now());
}
/**
* 判断当前时间是否在该时间范围内
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 是否
*/
public static boolean isBetween(Date startTime, Date endTime) {
if (startTime == null || endTime == null) {
return false;
}
return startTime.getTime() <= System.currentTimeMillis()
&& endTime.getTime() >= System.currentTimeMillis();
}
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.framework.common.util.date;
import cn.hutool.core.date.LocalDateTimeUtil;
import java.time.Duration;
import java.time.LocalDateTime;
@ -14,4 +16,38 @@ public class LocalDateTimeUtils {
return LocalDateTime.now().plus(duration);
}
public static boolean beforeNow(LocalDateTime date) {
return date.isBefore(LocalDateTime.now());
}
public static boolean afterNow(LocalDateTime date) {
return date.isAfter(LocalDateTime.now());
}
/**
* 创建指定时间
*
* @param year 年
* @param mouth 月
* @param day 日
* @return 指定时间
*/
public static LocalDateTime buildTime(int year, int mouth, int day) {
return LocalDateTime.of(year, mouth, day, 0, 0, 0);
}
/**
* 判断当前时间是否在该时间范围内
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 是否
*/
public static boolean isBetween(LocalDateTime startTime, LocalDateTime endTime) {
if (startTime == null || endTime == null) {
return false;
}
return LocalDateTimeUtil.isIn(LocalDateTime.now(), startTime, endTime);
}
}