Эх сурвалжийг харах

for adding minutes to time

sandriek 9 жил өмнө
parent
commit
9e9c4b4242
1 өөрчлөгдсөн 24 нэмэгдсэн , 1 устгасан
  1. 24 1
      gotosleep.c

+ 24 - 1
gotosleep.c

@@ -23,12 +23,35 @@ void setSleep(void)
 {
 	X12RtcGetClock(&count);
 	fallSleep.sleepTime = count;
-	fallSleep.sleepTime.tm_hour += 1;
+	AddMinutes(60);
+	
 	changeChanel();
 	x = fallSleep.sleepTime.tm_min;
 	
 	return 1;
 }
+void AddMinutes(int minutes){
+	if (fallSleep.sleepTime.tm_min + minutes >= 60){ //Checks if minutes is >= 60 else minute
+		fallSleep.sleepTime.tm_hour += 1;
+		fallSleep.sleepTime.tm_min = ((snooze[idx].snoozeTime.tm_min + minutes) % 60);
+		if (fallSleep.sleepTime.tm_hour >= 24){ //Checks if hours is >= 24
+			fallSleep.sleepTime.tm_hour = 0;
+			if ((fallSleep.sleepTime.tm_mday + 1) <= daysInMonth((fallSleep.sleepTime..tm_mon+1), (fallSleep.sleepTime.tm_year+1900))){ //Checks if day+1 smaller or even is to the amount of days in the month
+				fallSleep.sleepTime.tm_mday += 1;
+			} else { //If the days+1 is bigger than the amount of days in the month, day = 1 & month is + 1
+				fallSleep.sleepTime.tm_mday = 1;
+				if (fallSleep.sleepTime.tm_mon + 1 > 11){//If month+1 is bigger than 11 (month is 0-11) then month = 0 & year + 1
+					fallSleep.sleepTime.tm_mon = 0;
+					fallSleep.sleepTime.tm_year += 1;
+				} else {
+					fallSleep.sleepTime.tm_mon += 1;
+				}
+			}
+		}
+	} else {
+		fallSleep.sleepTime.tm_min += minutes;
+	}
+}
 void checkSleep(void)
 {
 	X12RtcGetClock(&count);