From e36752d9a4c7702f1661ef662198c9de488325e6 Mon Sep 17 00:00:00 2001 From: hello8693 <1320998105@qq.com> Date: Sun, 4 Aug 2024 21:04:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8B=E4=B8=80=E4=B8=AA=E8=80=83=E8=AF=95=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=A7=BD=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/utils/subjectUtils.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/utils/subjectUtils.ts b/src/renderer/src/utils/subjectUtils.ts index 4e7f25b..7d7bb67 100644 --- a/src/renderer/src/utils/subjectUtils.ts +++ b/src/renderer/src/utils/subjectUtils.ts @@ -1,4 +1,4 @@ -import { parseISO, isBefore } from 'date-fns'; +import { parseISO, isBefore, isAfter } from 'date-fns'; import { TimeSlot } from '@renderer/interfaces/timeTable'; /** @@ -28,3 +28,25 @@ export function getCurrentTimeSlot(timeSlots: TimeSlot[]): TimeSlot | null { // 如果没有找到包含当前时间的时间段,返回null return null; } + +export function getNextExamTimeSlot(timeSlots: TimeSlot[]): TimeSlot | null { + // 获取当前日期和时间 + const now = new Date(); + + // 按照开始时间排序时间段 + timeSlots.sort((a, b) => parseISO(a.start).getTime() - parseISO(b.start).getTime()); + + // 遍历排序后的时间段数组 + for (const slot of timeSlots) { + // 解析时间段的开始时间 + const startTime = parseISO(slot.start); + // 判断开始时间是否在当前时间之后 + if (isAfter(startTime, now)) { + // 如果是,返回当前时间段 + return slot; + } + } + + // 如果没有找到开始时间在当前时间之后的时间段,返回null + return null; +}