|
@@ -55,11 +55,16 @@ int getFirstDayDayOfWeek() {
|
|
|
}
|
|
|
|
|
|
//Get the number of days of a month
|
|
|
-int getNumberOfDayByMonth(int monthId) {
|
|
|
+int getNumberOfDayByMonth(int monthId, int currentYear) {
|
|
|
if (monthId < 0 || monthId > 11) {
|
|
|
return -1; // Invalid monthId
|
|
|
}
|
|
|
int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
|
+
|
|
|
+ if (monthId == 1 && isLeapYear(currentYear)){
|
|
|
+ //Feb in leap year
|
|
|
+ return 29;
|
|
|
+ }
|
|
|
return daysInMonth[monthId];
|
|
|
}
|
|
|
|
|
@@ -71,6 +76,19 @@ bool isNight() {
|
|
|
return (currentHour >= 19 || currentHour < 7);
|
|
|
}
|
|
|
|
|
|
+//Check if given year is leap year
|
|
|
+bool isLeapYear(int year) {
|
|
|
+ // Check if the year is divisible by 4
|
|
|
+ if (year % 4 == 0) {
|
|
|
+ // If it's divisible by 100, it should also be divisible by 400 to be a leap year
|
|
|
+ if (year % 100 == 0) {
|
|
|
+ return year % 400 == 0;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
//Grab a random NTP server
|
|
|
const char* getRandomNtpServer(const char* ntpServers[]) {
|
|
|
int randomIndex = ESP8266TrueRandom.random(ntpServerCounts - 1);
|