Day26: After holiday

假期应该是结束了,可自己却还没进入状态。

天一回来了,小满和女朋友过夜去了,我在算一道抽牌的问题。

若干人抽若干张牌,每次抽1到3张,谁抽到最后一张便算输,这个游戏有什么规律吗?

我很感兴趣,心血来潮的算了算,发现3人抽牌是公平的。

10.4 Tuesday

/** * 判断输入时间是否在免打扰区间内 * 如果是,返回下一个可执行时间 * 否则返回原时间 */ public static Date checkNext(Date inputDate, PlatformSlaEnum.SlaDoNotDisturbType rule, String startTime, String endTime) { DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); LocalDateTime inputDateTime = DateUtil.dateToLocalDateTime(inputDate); LocalTime inputTime = inputDateTime.toLocalTime(); LocalTime startQuiet = LocalTime.parse(startTime, timeFormatter); LocalTime endQuiet = LocalTime.parse(endTime, timeFormatter); boolean isApplicable = false; // 根据免打扰规则判断是否应用免打扰时间段 switch (rule) { case HOLIDAY: isApplicable = isHoliday(inputDate); break; case WORK_DAY: isApplicable = isWorkDay(inputDate); break; case WEEKEND: isApplicable = DateUtil.isWeekend(inputDate); break; case NATURAL_DAY: isApplicable = true; break; default: break; } if (!isApplicable) { // 不适用当前规则,直接返回原时间 return inputDate; } // 判断是否在免打扰时间段内 boolean isWithinQuietPeriod; if (startQuiet.isBefore(endQuiet)) { // 非跨天时间段(例如 08:00 - 22:00) isWithinQuietPeriod = !inputTime.isBefore(startQuiet) && inputTime.isBefore(endQuiet); } else { // 跨天时间段(例如 22:00 - 08:00) isWithinQuietPeriod = inputTime.isAfter(startQuiet) || inputTime.isBefore(endQuiet); } LocalDateTime result; if (isWithinQuietPeriod) { LocalDateTime nextExecutionTime; // 判断当天是否还有“非免打扰”时间 if (hasNonQuietTimeToday(inputDateTime, startQuiet, endQuiet)) { // 当天还有非免打扰时间,计算当天的下一个可执行时间 if (startQuiet.isBefore(endQuiet)) { // 非跨天,返回当天免打扰结束时间 + 1 分钟 nextExecutionTime = inputDateTime.with(LocalTime.of(endQuiet.getHour(), endQuiet.getMinute())); } else { // 跨天,但当前时间还没过当天免打扰开始时间,仍可在当天执行 nextExecutionTime = inputDateTime.with(LocalTime.of(endQuiet.getHour(), endQuiet.getMinute())); } result = nextExecutionTime.plusMinutes(1); } else { // 当天已无可用时间,跳转到次日 if (startQuiet.isBefore(endQuiet)) { nextExecutionTime = inputDateTime.with(LocalTime.of(endQuiet.getHour(), endQuiet.getMinute())); } else { nextExecutionTime = inputDateTime.plusDays(1) .with(LocalTime.of(endQuiet.getHour(), endQuiet.getMinute())); } nextExecutionTime = nextExecutionTime.plusMinutes(1); // 再次判断新增后的时间是否仍属于免打扰规则 boolean isNextDayApplicable = isRuleApplicable(nextExecutionTime.toLocalDate(), rule); if (!isNextDayApplicable) { // 次日不适用免打扰规则,使用次日 00:00 + 1分钟 nextExecutionTime = nextExecutionTime.with(LocalTime.MIDNIGHT).plusMinutes(1); } result = nextExecutionTime; } // 检查新增后的时间是否仍然适用免打扰规则(仅用于跨天场景) if (startQuiet.isAfter(endQuiet)) { boolean isNextDayApplicable = isRuleApplicable(nextExecutionTime.toLocalDate(), rule); if (!isNextDayApplicable) { // 如果新增后的时间已经不在免打扰规则范围内,则返回该天00:00 + 1分钟 result = nextExecutionTime.with(LocalTime.MIDNIGHT).plusMinutes(1); } } } else { // 当前时间不在免打扰区间,直接返回原时间 result = inputDateTime; } return DateUtil.localDateTimeToDate(result); }目前接口实现是这样的,上述情况怎么改造
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值