Skip to content

Commit 30db0ef

Browse files
committed
chore: handle over-night ranges
1 parent 6f9101d commit 30db0ef

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

src/utils/schedule.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,21 @@ export const isWithinSchedule = (schedule, date) => {
129129
const weekly = schedule?.weekly;
130130
if (!Array.isArray(weekly) || weekly.length === 0) return true;
131131

132-
const day = date.getDay();
133-
const minutes = date.getHours() * 60 + date.getMinutes();
132+
const WEEK = 7 * 1440;
133+
const nowInWeek = date.getDay() * 1440 + date.getHours() * 60 + date.getMinutes();
134134

135135
for (const slot of weekly) {
136136
const slotDay = parseDay(slot.day);
137137
if (slotDay === null) continue;
138138

139-
if (slotDay !== day) continue;
140-
141139
const startMin = parseTime(slot.start);
142140
if (startMin === null || typeof slot.duration !== 'number' || slot.duration <= 0) continue;
143-
const endMin = startMin + slot.duration * 60;
144141

145-
if (startMin <= endMin) {
146-
if (minutes >= startMin && minutes < endMin) return true;
147-
} else {
148-
if (minutes >= startMin || minutes < endMin) return true;
149-
}
142+
const slotStart = slotDay * 1440 + startMin;
143+
const durationMin = slot.duration * 60;
144+
const elapsed = (nowInWeek - slotStart + WEEK) % WEEK;
145+
146+
if (elapsed < durationMin) return true;
150147
}
151148

152149
return false;

0 commit comments

Comments
 (0)