feat:校验时间是否满足开市时间
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验当前时间是否满足工作日的9:30-11:30 13:00-15:00
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user