@@ -70,8 +70,10 @@ class Schedule : public ISchedule
7070 // Note: localTime->tm_wday: Sunday == 0, Monday == 1, etc.
7171 if (daysOfWeek) {
7272 uint8_t todayBit = 1 << localTime->tm_wday ;
73- if (!(*daysOfWeek & todayBit))
73+ if (!(*daysOfWeek & todayBit)) {
74+ logger->debug (" Schedule inactive: day bit {} not in mask {}" , todayBit, *daysOfWeek);
7475 return false ;
76+ }
7577 }
7678
7779 // Format current date and time as strings in "YYYY-MM-DD" and "HH:MM:SS" formats.
@@ -82,18 +84,36 @@ class Schedule : public ISchedule
8284 string currentTime = timeStream.str ();
8385
8486 // Check start and stop dates if set.
85- if (startDate && currentDate < *startDate)
87+ if (startDate && currentDate < *startDate) {
8688 return false ;
89+ }
8790
88- if (stopDate && currentDate > *stopDate)
91+ if (stopDate && currentDate > *stopDate) {
8992 return false ;
93+ }
9094
9195 // Check start and stop times if set.
92- if (startTime && currentTime < *startTime)
93- return false ;
94-
95- if (stopTime && currentTime > *stopTime)
96- return false ;
96+ if (startTime && stopTime) {
97+ if (*startTime <= *stopTime) {
98+ // Normal range (e.g., 08:00:00 to 17:00:00)
99+ if (currentTime < *startTime || currentTime > *stopTime) {
100+ return false ;
101+ }
102+ } else {
103+ // Overnight range (e.g., 22:00:00 to 06:00:00)
104+ if (currentTime < *startTime && currentTime > *stopTime) {
105+ return false ;
106+ }
107+ }
108+ } else if (startTime) {
109+ if (currentTime < *startTime) {
110+ return false ;
111+ }
112+ } else if (stopTime) {
113+ if (currentTime > *stopTime) {
114+ return false ;
115+ }
116+ }
97117
98118 return true ;
99119 }
0 commit comments