feat:校验时间是否满足开市时间

This commit is contained in:
xiang
2025-09-20 00:51:11 +08:00
parent 14d190e2db
commit 8f92daf7c8

View File

@@ -1,13 +1,19 @@
package com.xiang.xservice.basic.utils;
import lombok.extern.slf4j.Slf4j;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
/**
* 时间工具类
* @author xiang
*/
@Slf4j
public class DateUtils {
private final static String defaultDateFormatter = "yyyy-MM-dd";
@@ -58,4 +64,24 @@ public class DateUtils {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return LocalDateTime.parse(dateTimeStr, formatter);
}
/**
* 校验当前时间是否满足工作日的930-1130 1300-1500
* @return
*/
public static Boolean validWeekTime() {
if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) ||
Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) {
log.info("当前时间为:{}", LocalDateTime.now());
return false;
}
LocalTime now = LocalTime.now();
boolean inMorning = now.isAfter(LocalTime.of(9, 29)) && now.isBefore(LocalTime.of(11, 31));
boolean inAfternoon = now.isAfter(LocalTime.of(12, 59)) && now.isBefore(LocalTime.of(15, 1));
if (!inAfternoon && !inMorning) {
return false;
}
return true;
}
}