From 8f92daf7c811082424aa8a3a94110e8464dd2e87 Mon Sep 17 00:00:00 2001 From: xiang Date: Sat, 20 Sep 2025 00:51:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=A0=A1=E9=AA=8C=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=BB=A1=E8=B6=B3=E5=BC=80=E5=B8=82=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiang/xservice/basic/utils/DateUtils.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/xservice-common/src/main/java/com/xiang/xservice/basic/utils/DateUtils.java b/xservice-common/src/main/java/com/xiang/xservice/basic/utils/DateUtils.java index 2b6d907..971de0a 100644 --- a/xservice-common/src/main/java/com/xiang/xservice/basic/utils/DateUtils.java +++ b/xservice-common/src/main/java/com/xiang/xservice/basic/utils/DateUtils.java @@ -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; + } }