first commit

This commit is contained in:
wen
2025-09-30 13:01:24 +08:00
parent d8d17c8076
commit ec83999cef
40 changed files with 13830 additions and 136 deletions

View File

@@ -54,6 +54,52 @@
* EXTERNAL FUNCTIONS
*/
int isLeapYear(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int daysInMonth(int year, int month)
{
if (month == 2)
{
return isLeapYear(year) ? 29 : 28;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
return 30;
}
else
{
return 31;
}
}
long dateToEpoch(int year, int month, int day, int hour, int minute, int second)
{
int days = 0;
for (int y = 1970; y < year; y++)
{
days += isLeapYear(y) ? 366 : 365;
}
for (int m = 1; m < month; m++)
{
days += daysInMonth(year, m);
}
days += day - 1;
long seconds = days * 86400 + hour * 3600 + minute * 60 + second;
return seconds;
}
/*********************************************************************
* LOCAL VARIABLES
*/

View File

@@ -132,7 +132,7 @@ typedef struct
* tm - pointer to UTC time struct
*/
extern UTCTime esp32_ConvertUTCSecs( UTCTimeStruct *tm );
extern long dateToEpoch(int year, int month, int day, int hour, int minute, int second);
/*
* Update/Adjust the esp32 clock and timers
* Msec - elapsed time in milli seconds